Skip to content

Commit b0350a5

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

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,19 @@ class DataSourceV2SQLSuiteV1Filter
38703870
}
38713871
}
38723872

3873+
test("test default value conflicting with special column name") {
3874+
withSQLConf(SQLConf.DEFAULT_COLUMN_ALLOWED_PROVIDERS.key -> s"$v2Format, ") {
3875+
val t = "testcat.ns.t"
3876+
withTable("t") {
3877+
sql(s"""CREATE table $t (
3878+
c1 STRING,
3879+
c2 TIMESTAMP,
3880+
c3 BOOLEAN DEFAULT FALSE,
3881+
current_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP)""")
3882+
}
3883+
}
3884+
}
3885+
38733886
private def testNotSupportedV2Command(
38743887
sqlCommand: String,
38753888
sqlParams: String,

0 commit comments

Comments
 (0)