You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "dtenedor (via GitHub)" <gi...@apache.org> on 2023/05/17 16:47:14 UTC

[GitHub] [spark] dtenedor commented on a diff in pull request #41191: [SPARK-43529][SQL] Support general expressions as OPTIONS values in the parser

dtenedor commented on code in PR #41191:
URL: https://github.com/apache/spark/pull/41191#discussion_r1196805611


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -3187,7 +3187,24 @@ class AstBuilder extends SqlBaseParserBaseVisitor[AnyRef] with SQLConfHelper wit
       ctx: PropertyListContext): Map[String, String] = withOrigin(ctx) {
     val properties = ctx.property.asScala.map { property =>
       val key = visitPropertyKey(property.key)
-      val value = visitPropertyValue(property.value)
+      // A property value can be String, Integer, Boolean or Decimal. Here we extract the property
+      // value based on whether its a string, integer, boolean or decimal literal.
+      val value =
+      if (property.value == null) {
+        null
+      } else {
+        expression(property.value) match {
+          case Literal(str: UTF8String, StringType) => str.toString
+          case Literal(_, BooleanType) => property.value.getText.toLowerCase(Locale.ROOT)
+          case Literal(_, IntegerType | DecimalType()) => property.value.getText

Review Comment:
   Yea we could support foldable expressions in the future. And constant-fold them, and then store the text of the resulting constant in the option value instead.
   
   My idea was to separate concerns by doing just the parser change here first, but not doing this constant folding or changing the behavior yet. This PR only supports the same types of literal values for the option values as before the PR, simply improving error messages in other cases from generic `syntax error` to more descriptive messages indicating that only certain literals are supported. Then in another PR, we could implement the constant-folding.
   
   But if you prefer, I can implement the constant-folding in this PR as well, please let me know.



-- 
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