gengliangwang commented on code in PR #36415: URL: https://github.com/apache/spark/pull/36415#discussion_r866976275
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveDefaultColumns.scala: ########## @@ -98,44 +101,74 @@ case class ResolveDefaultColumns( node = node.children(0) } val table = node.asInstanceOf[UnresolvedInlineTable] - val insertTableSchemaWithoutPartitionColumns: StructType = + val insertTableSchemaWithoutPartitionColumns: Option[StructType] = getInsertTableSchemaWithoutPartitionColumns(i) - .getOrElse(return i) - val regenerated: InsertIntoStatement = - regenerateUserSpecifiedCols(i, insertTableSchemaWithoutPartitionColumns) - val expanded: UnresolvedInlineTable = - addMissingDefaultValuesForInsertFromInlineTable( - table, insertTableSchemaWithoutPartitionColumns) - val replaced: LogicalPlan = - replaceExplicitDefaultValuesForInputOfInsertInto( - analyzer, insertTableSchemaWithoutPartitionColumns, expanded) - .getOrElse(return i) - node = replaced - for (child <- children.reverse) { - node = child.withNewChildren(Seq(node)) - } - regenerated.copy(query = node) + insertTableSchemaWithoutPartitionColumns.map { schema: StructType => + val regenerated: InsertIntoStatement = + regenerateUserSpecifiedCols(i, schema) + val expanded: UnresolvedInlineTable = + addMissingDefaultValuesForInsertFromInlineTable(table, schema) + val replaced: Option[LogicalPlan] = + replaceExplicitDefaultValuesForInputOfInsertInto(analyzer, schema, expanded) + replaced.map { r: LogicalPlan => + node = r + for (child <- children.reverse) { + node = child.withNewChildren(Seq(node)) + } + regenerated.copy(query = node) + }.getOrElse(i) + }.getOrElse(i) } /** * Resolves DEFAULT column references for an INSERT INTO command whose query is a general * projection. */ private def resolveDefaultColumnsForInsertFromProject(i: InsertIntoStatement): LogicalPlan = { - val insertTableSchemaWithoutPartitionColumns: StructType = + val insertTableSchemaWithoutPartitionColumns: Option[StructType] = getInsertTableSchemaWithoutPartitionColumns(i) - .getOrElse(return i) - val regenerated: InsertIntoStatement = - regenerateUserSpecifiedCols(i, insertTableSchemaWithoutPartitionColumns) - val project: Project = i.query.asInstanceOf[Project] - val expanded: Project = - addMissingDefaultValuesForInsertFromProject( - project, insertTableSchemaWithoutPartitionColumns) - val replaced: LogicalPlan = - replaceExplicitDefaultValuesForInputOfInsertInto( - analyzer, insertTableSchemaWithoutPartitionColumns, expanded) - .getOrElse(return i) - regenerated.copy(query = replaced) + insertTableSchemaWithoutPartitionColumns.map { schema => + val regenerated: InsertIntoStatement = regenerateUserSpecifiedCols(i, schema) + val project: Project = i.query.asInstanceOf[Project] + val expanded: Project = + addMissingDefaultValuesForInsertFromProject(project, schema) + val replaced: Option[LogicalPlan] = + replaceExplicitDefaultValuesForInputOfInsertInto(analyzer, schema, expanded) + replaced.map { r => + regenerated.copy(query = r) + }.getOrElse(i) + }.getOrElse(i) + } + + /** + * Resolves DEFAULT column references for an UPDATE command. + */ + private def resolveDefaultColumnsForUpdate(u: UpdateTable): LogicalPlan = { + // Return a more descriptive error message if the user tries to use a DEFAULT column reference + // inside an UPDATE command's WHERE clause; this is not allowed. + u.condition.foreach { c: Expression => + if (c.find(isExplicitDefaultColumn).isDefined) { + throw QueryCompilationErrors.defaultReferencesNotAllowedInUpdateWhereClause() Review Comment: Let's have a test case for this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org