-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-39627][SQL] JDBC V2 pushdown should unify the compile API #37047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5dbf628
[SPARK-39627][SQL] Unify compileAggregate and compileExpression
beliefer b4b81d3
Update code
beliefer 6ee4450
Update code
beliefer 4c6cd35
Update code
beliefer 6d1c591
Update code
beliefer 97d68c8
Update code
beliefer c159841
Update code
beliefer afe2137
Update code
beliefer 00f6899
Update code
beliefer 88c180e
Update code
beliefer df23ae0
Update code
beliefer 3cb1a7e
Update code
beliefer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ import org.apache.spark.sql.connector.catalog.TableChange._ | |
| import org.apache.spark.sql.connector.catalog.functions.UnboundFunction | ||
| import org.apache.spark.sql.connector.catalog.index.TableIndex | ||
| import org.apache.spark.sql.connector.expressions.{Expression, Literal, NamedReference} | ||
| import org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc, Avg, Count, CountStar, Max, Min, Sum} | ||
| import org.apache.spark.sql.connector.expressions.aggregate.AggregateFunc | ||
| import org.apache.spark.sql.connector.util.V2ExpressionSQLBuilder | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.execution.datasources.jdbc.{DriverRegistry, JDBCOptions, JdbcUtils} | ||
|
|
@@ -244,7 +244,7 @@ abstract class JdbcDialect extends Serializable with Logging { | |
|
|
||
| override def visitSQLFunction(funcName: String, inputs: Array[String]): String = { | ||
| if (isSupportedFunction(funcName)) { | ||
| s"""$funcName(${inputs.mkString(", ")})""" | ||
| s"""${dialectFunctionName(funcName)}(${inputs.mkString(", ")})""" | ||
| } else { | ||
| // The framework will catch the error and give up the push-down. | ||
| // Please see `JdbcDialect.compileExpression(expr: Expression)` for more details. | ||
|
|
@@ -253,6 +253,18 @@ abstract class JdbcDialect extends Serializable with Logging { | |
| } | ||
| } | ||
|
|
||
| override def visitAggregateFunction( | ||
| funcName: String, isDistinct: Boolean, inputs: Array[String]): String = { | ||
| if (isSupportedFunction(funcName)) { | ||
| super.visitAggregateFunction(dialectFunctionName(funcName), isDistinct, inputs) | ||
| } else { | ||
| throw new UnsupportedOperationException( | ||
| s"${this.getClass.getSimpleName} does not support aggregate function: $funcName"); | ||
| } | ||
| } | ||
|
|
||
| protected def dialectFunctionName(funcName: String): String = funcName | ||
|
|
||
| override def visitOverlay(inputs: Array[String]): String = { | ||
| if (isSupportedFunction("OVERLAY")) { | ||
| super.visitOverlay(inputs) | ||
|
|
@@ -303,26 +315,8 @@ abstract class JdbcDialect extends Serializable with Logging { | |
| * @return Converted value. | ||
| */ | ||
| @Since("3.3.0") | ||
| def compileAggregate(aggFunction: AggregateFunc): Option[String] = { | ||
|
||
| aggFunction match { | ||
| case min: Min => | ||
| compileExpression(min.column).map(v => s"MIN($v)") | ||
| case max: Max => | ||
| compileExpression(max.column).map(v => s"MAX($v)") | ||
| case count: Count => | ||
| val distinct = if (count.isDistinct) "DISTINCT " else "" | ||
| compileExpression(count.column).map(v => s"COUNT($distinct$v)") | ||
| case sum: Sum => | ||
| val distinct = if (sum.isDistinct) "DISTINCT " else "" | ||
| compileExpression(sum.column).map(v => s"SUM($distinct$v)") | ||
| case _: CountStar => | ||
| Some("COUNT(*)") | ||
| case avg: Avg => | ||
| val distinct = if (avg.isDistinct) "DISTINCT " else "" | ||
| compileExpression(avg.column).map(v => s"AVG($distinct$v)") | ||
| case _ => None | ||
| } | ||
| } | ||
| @deprecated("use org.apache.spark.sql.jdbc.JdbcDialect.compileExpression instead.", "3.4.0") | ||
| def compileAggregate(aggFunction: AggregateFunc): Option[String] = compileExpression(aggFunction) | ||
|
|
||
| /** | ||
| * List the user-defined functions in jdbc dialect. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we update
JDBCSQLBuilderto respectsupportedFunctionsinvisitAggregateFunction?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JDBCSQLBuilderalready checksupportedFunctions.