Skip to content

Instantly share code, notes, and snippets.

@jesusjavierdediego
Last active December 19, 2018 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusjavierdediego/f26845d244269ba854808e1b2d72d61e to your computer and use it in GitHub Desktop.
Save jesusjavierdediego/f26845d244269ba854808e1b2d72d61e to your computer and use it in GitHub Desktop.
@throws(classOf[ReadDBFeaturesException])
def getRequirementFeaturesFromDBByProject(project: String): Option[DataFrame] ={
var result: Option[DataFrame] = None
try{
val storedRFsDF = spark
.sqlContext
.read
.format("com.microsoft.azure.cosmosdb.spark")
.cosmosDB(featuresStorageMap)
.toDF()
result = Some(storedRFsDF.filter($"project" === project))
}catch{
case(e: Exception) => {
logger.error(s"Error reading from database. reason: ${e}")
throw new ReadDBFeaturesException(s"Error reading from database. reason: ${e}")
}
}
result
}
@throws(classOf[ReadDBFeaturesException])
def getRequirementFeatureFromDBByID(feature_id: String): RequirementFeaturePersistence = {
try{
val fId: Int = feature_id.toInt
val rfp: RequirementFeaturePersistence = this.datastore
.createQuery(classOf[RequirementFeaturePersistence])
.filter("feature_id =" , feature_id)
.get()
rfp
}catch{
case e: Exception => throw new ReadDBFeaturesException(s"Error getting RFP from DB. Reason: ${e}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment