PBL PBL - 1 year ago 90
MySQL Question

In Apache Spark 2.0.0, is it possible to fetch a query from an external database (rather than grab the whole table)?

Using pyspark:

from pyspark.sql import SparkSession

spark = SparkSession\
.appName("spark play")\

df = spark.read\
.option("url", "jdbc:mysql://localhost:port")\
.option("dbtable", "schema.tablename")\
.option("user", "username")\
.option("password", "password")\

Rather than fetch "schema.tablename", I would prefer to grab the result set of a query.

Answer Source

Same as in 1.x you can pass valid subquery as dbtable argument for example:

.option("dbtable", "(SELECT foo, bar FROM schema.tablename) AS tmp")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download