Reputation: 303
I would like to read data from MySQL through Spark. The API which I saw is able to read data from specific table. something like,
val prop = new java.util.Properties
prop.setProperty("user", "<username>")
prop.setProperty("password", "<password>")
sparkSession.read.jdbc("jdbc:mysql://????:3306/???", "some-table", prop)
Now, I would like to perform a query for join tables. Does anyone know how to do it (on the database side, not with Spark SQL) ?
Thanks,
Eran
Upvotes: 2
Views: 2681
Reputation:
You'll need to use the "table " argument as a query:
val table = "(SELECT foo JOIN bar ON foo.id = bar.id) as t"
spark.read.jdbc("jdbc:mysql://????:3306/???", table, prop)
You should note that giving an alias to your query is important or this won't work.
Upvotes: 5