aokolnychyi commented on code in PR #51002:
URL: https://github.com/apache/spark/pull/51002#discussion_r2114467809


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Util.scala:
##########
@@ -597,11 +597,31 @@ private[sql] object CatalogV2Util {
       // Note: the back-fill here is a logical concept. The data source can 
keep the existing
       //       data unchanged and let the data reader to return "exist 
default" for missing
       //       columns.
-      val existingDefault = Literal(default.getValue.value(), 
default.getValue.dataType()).sql
-      
f.withExistenceDefaultValue(existingDefault).withCurrentDefaultValue(default.getSql)
+      val existsDefault = extractExistsDefault(default)
+      val (sql, expr) = extractCurrentDefault(default)
+      val newMetadata = new MetadataBuilder()
+        .withMetadata(f.metadata)
+        .putString(EXISTS_DEFAULT_COLUMN_METADATA_KEY, existsDefault)
+        .putExpression(CURRENT_DEFAULT_COLUMN_METADATA_KEY, sql, expr)
+        .build()
+      f.copy(metadata = newMetadata)
     }.getOrElse(f)
   }
 
+  private def extractExistsDefault(default: ColumnDefaultValue): String = {
+    Literal(default.getValue.value(), default.getValue.dataType()).sql
+  }
+
+  private def extractCurrentDefault(default: ColumnDefaultValue): (String, 
Option[Expression]) = {
+    val expr = 
Option(default.getExpression).flatMap(V2ExpressionUtils.toCatalyst)

Review Comment:
   Generally yes, but I am not sure we would want to allow them in default 
values.



-- 
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-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to