|
18 | 18 | package org.apache.spark.sql.catalyst.util
|
19 | 19 |
|
20 | 20 | import scala.collection.mutable.ArrayBuffer
|
| 21 | +import scala.util.{Failure, Success, Try} |
21 | 22 | import scala.util.control.NonFatal
|
22 | 23 |
|
23 | 24 | import org.apache.spark.{SparkException, SparkUnsupportedOperationException}
|
@@ -379,27 +380,33 @@ object ResolveDefaultColumns extends QueryErrorsBase
|
379 | 380 | val defaultSQL = field.metadata.getString(EXISTS_DEFAULT_COLUMN_METADATA_KEY)
|
380 | 381 |
|
381 | 382 | // Parse the expression.
|
382 |
| - val expr = Literal.fromSQL(defaultSQL) match { |
383 |
| - // EXISTS_DEFAULT will have a cast from analyze() due to coerceDefaultValue |
384 |
| - // hence we need to add timezone to the cast if necessary |
385 |
| - case c: Cast if c.child.resolved && c.needsTimeZone => |
386 |
| - c.withTimeZone(SQLConf.get.sessionLocalTimeZone) |
387 |
| - case e: Expression => e |
388 |
| - } |
| 383 | + val resolvedExpr = Try(Literal.fromSQL(defaultSQL)) match { |
| 384 | + case Success(literal) => |
| 385 | + val expr = literal match { |
| 386 | + // EXISTS_DEFAULT will have a cast from analyze() due to coerceDefaultValue |
| 387 | + // hence we need to add timezone to the cast if necessary |
| 388 | + case c: Cast if c.child.resolved && c.needsTimeZone => |
| 389 | + c.withTimeZone(SQLConf.get.sessionLocalTimeZone) |
| 390 | + case e: Expression => e |
| 391 | + } |
389 | 392 |
|
390 |
| - // Check invariants |
391 |
| - if (expr.containsPattern(PLAN_EXPRESSION)) { |
392 |
| - throw QueryCompilationErrors.defaultValuesMayNotContainSubQueryExpressions( |
393 |
| - "", field.name, defaultSQL) |
394 |
| - } |
| 393 | + // Check invariants |
| 394 | + if (expr.containsPattern(PLAN_EXPRESSION)) { |
| 395 | + throw QueryCompilationErrors.defaultValuesMayNotContainSubQueryExpressions( |
| 396 | + "", field.name, defaultSQL) |
| 397 | + } |
| 398 | + |
| 399 | + expr match { |
| 400 | + case _: ExprLiteral => expr |
| 401 | + case c: Cast if c.resolved => expr |
| 402 | + case _ => |
| 403 | + fallbackResolveExistenceDefaultValue(field) |
| 404 | + } |
395 | 405 |
|
396 |
| - val resolvedExpr = expr match { |
397 |
| - case _: ExprLiteral => expr |
398 |
| - case c: Cast if c.resolved => expr |
399 |
| - case _ => |
| 406 | + case Failure(_) => |
| 407 | + // If Literal.fromSQL fails, use fallback resolution |
400 | 408 | fallbackResolveExistenceDefaultValue(field)
|
401 | 409 | }
|
402 |
| - |
403 | 410 | coerceDefaultValue(resolvedExpr, field.dataType, "", field.name, defaultSQL)
|
404 | 411 | }
|
405 | 412 |
|
|
0 commit comments