cloud-fan commented on a change in pull request #35101:
URL: https://github.com/apache/spark/pull/35101#discussion_r779323246
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala
##########
@@ -19,14 +19,58 @@ package org.apache.spark.sql.jdbc
import java.sql.SQLException
import java.util.Locale
-
import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.analysis.{NoSuchNamespaceException,
NoSuchTableException, TableAlreadyExistsException}
+import org.apache.spark.sql.connector.expressions.aggregate.{AggregateFunc,
Count, CountStar, GeneralAggregateFunc, Max, Min, Sum}
private object H2Dialect extends JdbcDialect {
override def canHandle(url: String): Boolean =
url.toLowerCase(Locale.ROOT).startsWith("jdbc:h2")
+ override def compileAggregate(aggFunction: AggregateFunc): Option[String] = {
+ aggFunction match {
+ case min: Min =>
+ if (min.column.fieldNames.length != 1) return None
+ Some(s"MIN(${quoteIdentifier(min.column.fieldNames.head)})")
+ case max: Max =>
+ if (max.column.fieldNames.length != 1) return None
+ Some(s"MAX(${quoteIdentifier(max.column.fieldNames.head)})")
+ case count: Count =>
+ if (count.column.fieldNames.length != 1) return None
+ val distinct = if (count.isDistinct) "DISTINCT " else ""
+ val column = quoteIdentifier(count.column.fieldNames.head)
+ Some(s"COUNT($distinct$column)")
+ case sum: Sum =>
+ if (sum.column.fieldNames.length != 1) return None
+ val distinct = if (sum.isDistinct) "DISTINCT " else ""
+ val column = quoteIdentifier(sum.column.fieldNames.head)
+ Some(s"SUM($distinct$column)")
+ case _: CountStar =>
+ Some("COUNT(*)")
+ case f: GeneralAggregateFunc if f.name() == "AVG" =>
Review comment:
OK I see it now. They are not that common, at least H2 doesn't support
all of them. I think your previous code is better.
--
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]