dongjoon-hyun commented on code in PR #60712:
URL: https://github.com/apache/spark/pull/60712#discussion_r4634666673


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableConstraintResolution.scala:
##########
@@ -56,15 +58,39 @@ private[sql] class TableConstraintResolution(
       condition => v2Write.withNewQuery(Filter(condition, v2Write.query)))
   }
 
-  private def buildCheckInvariant(c: Check, query: LogicalPlan): Expression = {
+  /**
+   * The output of the query of a write, with the CHAR and VARCHAR types of 
the table columns that
+   * `TableOutputResolver` removes from it. A CHECK condition resolved against 
it pads a string
+   * literal compared with a CHAR column, as the stored values are padded.
+   */
+  private def withCharVarcharTypes(

Review Comment:
   You're right. I reproduced it: under `spark.sql.legacy.charVarcharAsString`, 
a write accepted `'CLOSED'` for `CHECK (status <> 'CLOSED' AND closed <= 
current_date())` on a normally created table, and rejected `'OPEN'` for `status 
= 'OPEN' AND closed <= current_date()`. `withCharVarcharTypes` now keeps the 
output as it is when `conf.charVarcharAsString && 
!conf.charVarcharStandardSemantics`, as `ApplyCharTypePadding.apply` does, and 
the test has this case.
   



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableConstraintResolution.scala:
##########
@@ -77,10 +103,10 @@ private[sql] class TableConstraintResolution(
    * again. The result is resolved against the same attributes as the query, 
so it can go to the

Review Comment:
   Thanks. I updated it to say that the attributes have the same expression IDs 
as the output of the query.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/CheckConstraintSuite.scala:
##########
@@ -497,6 +497,35 @@ class CheckConstraintSuite extends QueryTest with 
CommandSuiteBase with DDLComma
     }
   }
 
+  test("SPARK-62070: Check constraint of CREATE TABLE comparing a CHAR 
column") {

Review Comment:
   I added `SPARK-62070: UPDATE and MERGE with a check constraint comparing a 
CHAR column` with `rowLevelOPCatalog`, which fails without this PR. I also 
split the comment.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to