使用pyspark:
from pyspark.sql import SparkSession
spark = SparkSession\
.builder\
.appName("spark play")\
.getOrCreate()
df = spark.read\
.format("jdbc")\
.option("url", "jdbc:mysql://localhost:port")\
.option("dbtable", "schema.tablename")\
.option("user", "username")\
.option("password", "password")\
.load()
我不想获取" schema.tablename",而是希望获取查询的结果集。
答案 0 :(得分:10)
Same as in 1.x您可以将有效子查询作为dbtable
参数传递,例如:
...
.option("dbtable", "(SELECT foo, bar FROM schema.tablename) AS tmp")
...