Skip to content

Commit da190b3

Browse files
committed
[SPARK-53786][SQL] Default value should not conflict with special column name
1 parent e95f12b commit da190b3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
175175
u.copy(child = newChild)
176176
}
177177

178+
case d @ DefaultValueExpression(u: UnresolvedAttribute, _, _) =>
179+
d.copy(child = LiteralFunctionResolution.resolve(u.nameParts)
180+
.map {
181+
case Alias(child, _) if !isTopLevel => child
182+
case other => other
183+
}
184+
.getOrElse(u))
185+
178186
case _ => e.mapChildren(innerResolve(_, isTopLevel = false))
179187
}
180188
resolved.copyTagsFrom(e)

sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,17 @@ class DataSourceV2SQLSuiteV1Filter
38703870
}
38713871
}
38723872

3873+
test("test default value conflicting with special column name") {
3874+
val t = "testcat.ns.t"
3875+
withTable("t") {
3876+
sql(s"""CREATE table $t (
3877+
c1 STRING,
3878+
c2 TIMESTAMP,
3879+
c3 BOOLEAN DEFAULT FALSE,
3880+
current_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP)""")
3881+
}
3882+
}
3883+
38733884
private def testNotSupportedV2Command(
38743885
sqlCommand: String,
38753886
sqlParams: String,

0 commit comments

Comments
 (0)