File tree 2 files changed +17
-4
lines changed
catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
core/src/test/scala/org/apache/spark/sql/connector
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1022,13 +1022,25 @@ trait CheckAnalysis extends LookupCatalog with QueryErrorsBase with PlanToString
1022
1022
}
1023
1023
}
1024
1024
1025
+ def checkExistsDefaultDeterministic (colsToAdd : Seq [QualifiedColType ]): Unit = {
1026
+ colsToAdd.foreach { col =>
1027
+ col.default.foreach { d =>
1028
+ if (! d.deterministic) {
1029
+ throw QueryCompilationErrors .defaultValueNotConstantError(
1030
+ " ALTER TABLE" , col.colName, d.originalSQL)
1031
+ }
1032
+ }
1033
+ }
1034
+ }
1035
+
1025
1036
alter match {
1026
1037
case AddColumns (table : ResolvedTable , colsToAdd) =>
1027
1038
colsToAdd.foreach { colToAdd =>
1028
1039
checkColumnNotExists(" add" , colToAdd.name, table.schema)
1029
1040
}
1030
1041
checkColumnNameDuplication(colsToAdd)
1031
1042
checkNoCollationsInMapKeys(colsToAdd)
1043
+ checkExistsDefaultDeterministic(colsToAdd)
1032
1044
1033
1045
case ReplaceColumns (_ : ResolvedTable , colsToAdd) =>
1034
1046
checkColumnNameDuplication(colsToAdd)
Original file line number Diff line number Diff line change @@ -3560,10 +3560,11 @@ class DataSourceV2SQLSuiteV1Filter
3560
3560
val exception = analysisException(
3561
3561
// Rand function is not foldable
3562
3562
s " ALTER TABLE tab ADD COLUMN col2 DOUBLE DEFAULT rand() " )
3563
- assert(exception.getSqlState == " 42K0E" )
3564
- assert(exception.errorClass.get == " INVALID_NON_DETERMINISTIC_EXPRESSIONS" )
3565
- assert(exception.messageParameters(" sqlExprs" ) ==
3566
- " \" qualifiedcoltype(defaultvalueexpression(rand()))\" " )
3563
+ assert(exception.getSqlState == " 42623" )
3564
+ assert(exception.errorClass.get == " INVALID_DEFAULT_VALUE.NOT_CONSTANT" )
3565
+ assert(exception.messageParameters(" colName" ) == " `col2`" )
3566
+ assert(exception.messageParameters(" defaultValue" ) == " rand()" )
3567
+ assert(exception.messageParameters(" statement" ) == " ALTER TABLE" )
3567
3568
}
3568
3569
foldableExpressions.foreach(expr => {
3569
3570
withTable(" tab" ) {
You can’t perform that action at this time.
0 commit comments