beliefer commented on code in PR #36593:
URL: https://github.com/apache/spark/pull/36593#discussion_r907951030
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala:
##########
@@ -41,6 +43,45 @@ private[sql] object H2Dialect extends JdbcDialect {
override def isSupportedFunction(funcName: String): Boolean =
supportedFunctions.contains(funcName)
+ class H2SQLBuilder extends JDBCSQLBuilder {
+ override def visitUserDefinedScalarFunction(
+ funcName: String, canonicalName: String, inputs: Array[String]):
String = {
+ funcName match {
+ case "CHAR_LENGTH" =>
+ s"$funcName(${inputs.mkString(", ")})"
+ case _ => super.visitUserDefinedScalarFunction(funcName,
canonicalName, inputs)
+ }
+ }
+
+ override def visitUserDefinedAggregateFunction(
+ funcName: String,
+ canonicalName: String,
+ isDistinct: Boolean,
+ inputs: Array[String]): String = {
+ funcName match {
+ case "IAVG" =>
+ if (isDistinct) {
+ s"$funcName(DISTINCT ${inputs.mkString(", ")})"
+ } else {
+ s"$funcName(${inputs.mkString(", ")})"
+ }
+ case _ =>
+ super.visitUserDefinedAggregateFunction(funcName, canonicalName,
isDistinct, inputs)
+ }
+ }
+ }
+
+ override def compileExpression(expr: Expression): Option[String] = {
+ val h2SQLBuilder = new H2SQLBuilder()
+ try {
+ Some(h2SQLBuilder.build(expr))
+ } catch {
+ case NonFatal(e) =>
+ logWarning("Error occurs while compiling V2 expression", e)
+ None
+ }
+ }
+
override def compileAggregate(aggFunction: AggregateFunc): Option[String] = {
Review Comment:
`compileAggregate` only used to compile Aggregate functions, but
`compileExpression` used to compile expressions.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]