Skip to content

Instantly share code, notes, and snippets.

@niroj-office
Last active November 6, 2020 20:46
Show Gist options
  • Save niroj-office/3188ab1f3309730983fc2c279f90ed52 to your computer and use it in GitHub Desktop.
Save niroj-office/3188ab1f3309730983fc2c279f90ed52 to your computer and use it in GitHub Desktop.
class ExecuteDbQuery( spark: Option[SparkSession],
dbConfigFilePath: String, query: String, var commitNbr: Long = 1000,
var loadReadyDbDF: DataFrame = null, mode: SaveMode = SaveMode.Append,
var dbOperation: DbOperations.Value = DbOperation.INSERT,
var joinKeys: Seq[String] = Seq(),
var updateCols: Seq[String] = Seq(), surrogateKey: String = null,
generateSurrogateKey: Boolean = true, chkPrintFlg: Boolean = false,
sequenceName: String = nulll, readByPartitionColumn: Boolean = false,
rejectionHDFSPath: String = null)
extends EnvProperties with java.io.Serializable
{
... /** Hidden Code **/
...
def execute(): Either[Option[ResultSet], DataFrame] = {
if(spark.isDefined)
Right(executeDbQuery(spark.get, query))
else
Left(executeDbQuery(query))
}
private[this] def executeDbQuery(internalQuery: String): Option[ResultSet] = {
... /** Hidden Code **/
}
private[this] def executeDbQuery(spark: SparkSession, internalQuery: String): DataFrame = {
... /** Hidden Code **/
}
}
object ExecuteDbQuery extends EnvProperties { self =>
... /** Hidden Code **/
def apply(configFilePath: String, query: String): Any = Option(execute(new ExecuteDbQuery(configFilePath,query) )).getOrElse("")
def apply(spark: Option[SparkSession], configFilePath: String, query: String) = execute(new ExecuteDbQuery(spark,configFilePath,query)).asInstanceOfDataFrame
....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment