viirya commented on code in PR #60712:
URL: https://github.com/apache/spark/pull/60712#discussion_r4634394167


##########
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:
   This also applies on the `predicateSql` path, which is analyzed under 
`StoredExpressionText.fixedConf`, so the writer's 
`spark.sql.legacy.charVarcharAsString` is ignored there. A session with that 
config stores CHAR values unpadded, but the literal now gets padded. So on a 
normally created table, `CHECK (status <> 'CLOSED' AND closed <= 
current_date())` accepts `'CLOSED'`, and `status = 'OPEN' AND ...` rejects 
`'OPEN'`. Both were correct before this PR. In the same session, the predicate 
path (without `current_date()`) still behaves correctly. Could this skip adding 
the metadata when `conf.charVarcharAsString && 
!conf.charVarcharStandardSemantics`, as `ApplyCharTypePadding.apply` does?



##########
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:
   nit: The attributes now carry CHAR metadata that the query output doesn't 
have, so "the same attributes as the query" is no longer exact. Maybe say they 
have the same expression IDs?



##########
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:
   The description says UPDATE and MERGE are affected too. Could you add a 
`rowLevelOPCatalog` case for them? Also, the comment above packs three points 
into one sentence. Splitting it would make it easier to follow.



-- 
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