You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/06/30 22:00:48 UTC

[GitHub] [spark] gengliangwang commented on a diff in pull request #36960: [SPARK-39557][SQL] Support ARRAY, STRUCT, MAP types as DEFAULT values

gengliangwang commented on code in PR #36960:
URL: https://github.com/apache/spark/pull/36960#discussion_r911475487


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ResolveDefaultColumnsUtil.scala:
##########
@@ -120,6 +120,54 @@ object ResolveDefaultColumns {
     }
   }
 
+  /**
+   * Computes the string representation of an expression suitable for use when storing the
+   * constant-folded result of DEFAULT column values.
+   */
+  private def expressionToString(expression: Expression): String = {
+    expression match {
+      case Cast(child, dataType, _, _) =>
+        s"CAST(${expressionToString(child)} AS ${dataType.catalogString})"
+      case Literal(value, dataType: DataType) =>
+        valueToString(value, dataType)
+      case _ =>
+        expression.sql
+    }
+  }
+
+  /**
+   * Computes the string representation of a value suitable for use when storing the
+   * constant-folded result of DEFAULT column values.
+   */
+  private def valueToString(value: Any, dataType: DataType): String = {
+    (value, dataType) match {
+      case (data: GenericArrayData, arrayType: ArrayType) =>

Review Comment:
   Shall we fix the `sql` method of `Literal` instead?



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