File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
core/src/test/scala/org/apache/spark/sql/connector Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -175,13 +175,8 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
175
175
u.copy(child = newChild)
176
176
}
177
177
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))
178
+ case d @ DefaultValueExpression (c : Expression , _, _) =>
179
+ d.copy(child = resolveLiteralColumns(c))
185
180
186
181
case _ => e.mapChildren(innerResolve(_, isTopLevel = false ))
187
182
}
@@ -203,6 +198,13 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
203
198
}
204
199
}
205
200
201
+ private def resolveLiteralColumns (e : Expression ) = {
202
+ e.transformWithPruning(_.containsPattern(UNRESOLVED_ATTRIBUTE )) {
203
+ case u @ UnresolvedAttribute (nameParts) =>
204
+ LiteralFunctionResolution .resolve(nameParts).getOrElse(u)
205
+ }
206
+ }
207
+
206
208
// Resolves `UnresolvedAttribute` to `OuterReference`.
207
209
protected def resolveOuterRef (e : Expression ): Expression = {
208
210
val outerPlan = AnalysisContext .get.outerPlan
Original file line number Diff line number Diff line change @@ -3898,6 +3898,19 @@ class DataSourceV2SQLSuiteV1Filter
3898
3898
}
3899
3899
}
3900
3900
3901
+ test(" test default value special column name nested in function" ) {
3902
+ val t = " testcat.ns.t"
3903
+ withTable(" t" ) {
3904
+ sql(s """ CREATE table $t (
3905
+ c1 STRING,
3906
+ current_date DATE DEFAULT DATE_ADD(current_date, 7)) """ )
3907
+ sql(s " INSERT INTO $t (c1) VALUES ('a') " )
3908
+ val result = sql(s " SELECT * FROM $t" ).collect()
3909
+ assert(result.length == 1 )
3910
+ assert(result(0 ).getString(0 ) == " a" )
3911
+ }
3912
+ }
3913
+
3901
3914
test(" test default value should not refer to real column" ) {
3902
3915
val t = " testcat.ns.t"
3903
3916
withTable(" t" ) {
@@ -3907,7 +3920,7 @@ class DataSourceV2SQLSuiteV1Filter
3907
3920
c1 STRING,
3908
3921
current_timestamp TIMESTAMP DEFAULT c1) """ )
3909
3922
},
3910
- condition = " INVALID_DEFAULT_VALUE.UNRESOLVED_EXPRESSION " ,
3923
+ condition = " INVALID_DEFAULT_VALUE.NOT_CONSTANT " ,
3911
3924
parameters = Map (
3912
3925
" statement" -> " CREATE TABLE" ,
3913
3926
" colName" -> " `current_timestamp`" ,
You can’t perform that action at this time.
0 commit comments