Home > Back-end >  Optimizing Spark JDBC connection read time by adding query parameter
Optimizing Spark JDBC connection read time by adding query parameter

Time:08-31

Connecting sql server to spark using the following package https://docs.microsoft.com/en-us/sql/connect/spark/connector?view=sql-server-ver16. At the moment am reading the entire table however this is bad for performance. To optimize performance I want to pass a query to the following spark.read config. for example select * from my table where record time > timestamp. is this possible? how would I do this?

DF = spark.read \
        .format("com.microsoft.sqlserver.jdbc.spark") \
        .option("url", jdbcUrl) \
        .option("dbtable", table_name) \
        .option("user", username) \
        .option("password", password).load()

CodePudding user response:

You can just filter the data frame that you are creating. Spark supports predicate pushdown, which means that the filtering will most likely run on top of the database directly. You can make sure that that works by looking at the SparkUI / Explain Plan

  • Related