viirya commented on code in PR #50593: URL: https://github.com/apache/spark/pull/50593#discussion_r2048310479
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/ColumnDefinition.scala: ########## @@ -194,17 +194,32 @@ object ColumnDefinition { /** * A fake expression to hold the column/variable default value expression and its original SQL text. */ -case class DefaultValueExpression(child: Expression, originalSQL: String) +case class DefaultValueExpression( + child: Expression, + originalSQL: String, + exposeCurrentDefaultAsExprV2: Boolean) extends UnaryExpression with Unevaluable { override def dataType: DataType = child.dataType + override def stringArgs: Iterator[Any] = Iterator(child, originalSQL) override protected def withNewChildInternal(newChild: Expression): Expression = copy(child = newChild) // Convert the default expression to ColumnDefaultValue, which is required by DS v2 APIs. def toV2(statement: String, colName: String): ColumnDefaultValue = child match { case Literal(value, dataType) => - new ColumnDefaultValue(originalSQL, LiteralValue(value, dataType)) + val literalV2 = LiteralValue(value, dataType) + val exprV2 = if (exposeCurrentDefaultAsExprV2) literalV2 else null + new ColumnDefaultValue(originalSQL, exprV2, literalV2) case _ => throw QueryCompilationErrors.defaultValueNotConstantError(statement, colName, originalSQL) } } + +object DefaultValueExpression { + def apply(expr: Expression, originalSQL: String): DefaultValueExpression = { + // only expose V2 expressions as current defaults if all Catalyst expressions are evaluable + // Catalyst expressions like CURRENT_USER or CURRENT_DATE will require special handling + val exposeCurrentDefaultAsExprV2 = !expr.exists(_.isInstanceOf[FoldableUnevaluable]) Review Comment: Hmm, looks like you only handle `Literal` in `DefaultValueExpression.toV2` for `exposeCurrentDefaultAsExprV2 = true` case? Then why not just allow literals here for `exposeCurrentDefaultAsExprV2` like @cloud-fan said? -- 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