aokolnychyi commented on code in PR #50839: URL: https://github.com/apache/spark/pull/50839#discussion_r2082577092
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2AlterTableCommands.scala: ########## @@ -306,7 +309,32 @@ case class AddConstraint( Seq(TableChange.addConstraint(constraint, validatedTableVersion)) } - protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan = copy(table = newChild) + override protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan = + copy(table = newChild) +} + +/** + * The logical plan of the ALTER TABLE ... ADD CONSTRAINT command for Check constraints. + * It doesn't extend [[AlterTableCommand]] because its child is a filtered table scan rather than + * a table reference. + */ +case class AddCheckConstraint( + child: LogicalPlan, + checkConstraint: CheckConstraint) extends UnaryCommand { + + def changes: Seq[TableChange] = { + val constraint = checkConstraint.toV2Constraint + val validatedTableVersion = child.find(_.isInstanceOf[DataSourceV2ScanRelation]) match { + case Some(d: DataSourceV2ScanRelation) if constraint.enforced() => + d.relation.table.currentVersion() + case _ => + null + } + Seq(TableChange.addConstraint(constraint, validatedTableVersion)) Review Comment: Do we set validation status to VALIDATED? ########## common/utils/src/main/resources/error/error-conditions.json: ########## @@ -4120,6 +4120,12 @@ ], "sqlState" : "07501" }, + "NEW_CHECK_CONSTRAINT_VIOLATION" : { + "message" : [ + "The new check constraint (<expression>) is violated by the existing data in the table <tableName>." Review Comment: I would reword to something like `The check constraint (<expression>) cannot be added because ...`. -- 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