You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "beliefer (via GitHub)" <gi...@apache.org> on 2025/02/24 08:11:56 UTC
[PR] [WIP][SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
beliefer opened a new pull request, #50059:
URL: https://github.com/apache/spark/pull/50059
### What changes were proposed in this pull request?
This PR proposes to unify the calling to the DataFrameReader API in Spark Connect where supports the jdbc API.
### Why are the changes needed?
### Does this PR introduce _any_ user-facing change?
'No'.
### How was this patch tested?
GA.
### Was this patch authored or co-authored using generative AI tooling?
'No'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50059:
URL: https://github.com/apache/spark/pull/50059#issuecomment-2678117446
ping @HyukjinKwon @zhengruifeng @LuciferYang
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang commented on code in PR #50059:
URL: https://github.com/apache/spark/pull/50059#discussion_r1969870783
##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -1383,28 +1383,25 @@ class SparkConnectPlanner(
isStreaming = rel.getIsStreaming)
case proto.Read.ReadTypeCase.DATA_SOURCE if !rel.getIsStreaming =>
- val localMap = CaseInsensitiveMap[String](rel.getDataSource.getOptionsMap.asScala.toMap)
val reader = session.read
- if (rel.getDataSource.hasFormat) {
- reader.format(rel.getDataSource.getFormat)
- }
- localMap.foreach { case (key, value) => reader.option(key, value) }
if (rel.getDataSource.getFormat == "jdbc" && rel.getDataSource.getPredicatesCount > 0) {
- if (!localMap.contains(JDBCOptions.JDBC_URL) ||
- !localMap.contains(JDBCOptions.JDBC_TABLE_NAME)) {
+ if (!rel.getDataSource.getOptionsMap.containsKey(JDBCOptions.JDBC_URL) ||
+ !rel.getDataSource.getOptionsMap.containsKey(JDBCOptions.JDBC_TABLE_NAME)) {
throw InvalidPlanInput(s"Invalid jdbc params, please specify jdbc url and table.")
}
val url = rel.getDataSource.getOptionsMap.get(JDBCOptions.JDBC_URL)
val table = rel.getDataSource.getOptionsMap.get(JDBCOptions.JDBC_TABLE_NAME)
- val options = new JDBCOptions(url, table, localMap)
val predicates = rel.getDataSource.getPredicatesList.asScala.toArray
- val parts: Array[Partition] = predicates.zipWithIndex.map { case (part, i) =>
- JDBCPartition(part, i): Partition
- }
- val relation = JDBCRelation(parts, options)(session)
- LogicalRelation(relation)
+ val properties = new Properties()
+ properties.putAll(rel.getDataSource.getOptionsMap)
+ reader.jdbc(url, table, predicates, properties).queryExecution.analyzed
Review Comment:
When `rel.getDataSource.getFormat == "jdbc" && rel.getDataSource.getPredicatesCount == 0` is true, isn't it unnecessary to use `reader.jdbc(url, table, predicates, properties).queryExecution.analyzed`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50059:
URL: https://github.com/apache/spark/pull/50059#discussion_r2122565510
##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -1383,28 +1383,25 @@ class SparkConnectPlanner(
isStreaming = rel.getIsStreaming)
case proto.Read.ReadTypeCase.DATA_SOURCE if !rel.getIsStreaming =>
- val localMap = CaseInsensitiveMap[String](rel.getDataSource.getOptionsMap.asScala.toMap)
val reader = session.read
- if (rel.getDataSource.hasFormat) {
- reader.format(rel.getDataSource.getFormat)
- }
- localMap.foreach { case (key, value) => reader.option(key, value) }
if (rel.getDataSource.getFormat == "jdbc" && rel.getDataSource.getPredicatesCount > 0) {
- if (!localMap.contains(JDBCOptions.JDBC_URL) ||
- !localMap.contains(JDBCOptions.JDBC_TABLE_NAME)) {
+ if (!rel.getDataSource.getOptionsMap.containsKey(JDBCOptions.JDBC_URL) ||
Review Comment:
Good Catch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #50059:
URL: https://github.com/apache/spark/pull/50059#discussion_r1970897081
##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -1383,28 +1383,25 @@ class SparkConnectPlanner(
isStreaming = rel.getIsStreaming)
case proto.Read.ReadTypeCase.DATA_SOURCE if !rel.getIsStreaming =>
- val localMap = CaseInsensitiveMap[String](rel.getDataSource.getOptionsMap.asScala.toMap)
val reader = session.read
- if (rel.getDataSource.hasFormat) {
- reader.format(rel.getDataSource.getFormat)
- }
- localMap.foreach { case (key, value) => reader.option(key, value) }
if (rel.getDataSource.getFormat == "jdbc" && rel.getDataSource.getPredicatesCount > 0) {
- if (!localMap.contains(JDBCOptions.JDBC_URL) ||
- !localMap.contains(JDBCOptions.JDBC_TABLE_NAME)) {
+ if (!rel.getDataSource.getOptionsMap.containsKey(JDBCOptions.JDBC_URL) ||
+ !rel.getDataSource.getOptionsMap.containsKey(JDBCOptions.JDBC_TABLE_NAME)) {
throw InvalidPlanInput(s"Invalid jdbc params, please specify jdbc url and table.")
}
val url = rel.getDataSource.getOptionsMap.get(JDBCOptions.JDBC_URL)
val table = rel.getDataSource.getOptionsMap.get(JDBCOptions.JDBC_TABLE_NAME)
- val options = new JDBCOptions(url, table, localMap)
val predicates = rel.getDataSource.getPredicatesList.asScala.toArray
- val parts: Array[Partition] = predicates.zipWithIndex.map { case (part, i) =>
- JDBCPartition(part, i): Partition
- }
- val relation = JDBCRelation(parts, options)(session)
- LogicalRelation(relation)
+ val properties = new Properties()
+ properties.putAll(rel.getDataSource.getOptionsMap)
+ reader.jdbc(url, table, predicates, properties).queryExecution.analyzed
Review Comment:
Yes. `reader.load()` could support that way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #50059:
URL: https://github.com/apache/spark/pull/50059#discussion_r2111071577
##########
sql/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -1383,28 +1383,25 @@ class SparkConnectPlanner(
isStreaming = rel.getIsStreaming)
case proto.Read.ReadTypeCase.DATA_SOURCE if !rel.getIsStreaming =>
- val localMap = CaseInsensitiveMap[String](rel.getDataSource.getOptionsMap.asScala.toMap)
val reader = session.read
- if (rel.getDataSource.hasFormat) {
- reader.format(rel.getDataSource.getFormat)
- }
- localMap.foreach { case (key, value) => reader.option(key, value) }
if (rel.getDataSource.getFormat == "jdbc" && rel.getDataSource.getPredicatesCount > 0) {
- if (!localMap.contains(JDBCOptions.JDBC_URL) ||
- !localMap.contains(JDBCOptions.JDBC_TABLE_NAME)) {
+ if (!rel.getDataSource.getOptionsMap.containsKey(JDBCOptions.JDBC_URL) ||
Review Comment:
it was case insensitive before, is it a bug?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50059:
URL: https://github.com/apache/spark/pull/50059#issuecomment-2680328835
> Do you think you can add some test cases, @beliefer , to be clear what was the problem and to prevent a future regression?
Spark Connect already have the test cases. This improvement is just to unify the code path and improve the maintenance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on PR #50059:
URL: https://github.com/apache/spark/pull/50059#issuecomment-2687136845
Merged into branch-4.0/master.
@LuciferYang @dongjoon-hyun Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer closed pull request #50059: [SPARK-51302][CONNECT] Spark Connect supports JDBC should use the DataFrameReader API
URL: https://github.com/apache/spark/pull/50059
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org