spark-test commented on code in PR #60588:
URL: https://github.com/apache/spark/pull/60588#discussion_r4620241605


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/PlanParserSuite.scala:
##########
@@ -2722,8 +2736,9 @@ class PlanParserSuite extends AnalysisTest {
     val fragment = "TIMESTAMP AS OF col"
     checkError(
       exception = parseException(sql),
-      condition = "_LEGACY_ERROR_TEMP_0056",
-      parameters = Map("reason" -> "timestamp expression cannot refer to any 
columns"),
+      condition = "INVALID_TIME_TRAVEL_TIMESTAMP_EXPR.COLUMN_REFERENCE",
+      sqlState = "42K0E",
+      parameters = Map("expr" -> "\"col\""),

Review Comment:
   **Nit (P3):** This assertion and the CHANGES one at 
PlanParserSuite.scala:3081 are the only checks on the new `expr` parameter, and 
both use a bare identifier, for which `SparkParserUtils.source`, `getText` and 
an SQL rendering all produce `"col"`. Reading the helper 
(QueryParsingErrors.scala:932-936), if it switched to `ctx.getText`, the 
rendering this PR already replaced once for TABLESAMPLE, `SELECT * FROM t 
TIMESTAMP AS OF col + INTERVAL 1 DAY` would report `"col+INTERVAL1DAY"` and 
both tests would still pass. Two of the helper's four call sites have no test 
at all, the batch CHANGES end bound (AstBuilder.scala:3146) and the streaming 
CHANGES start bound (AstBuilder.scala:3186), so passing the wrong context at 
either, such as the start bound's context at the end-bound check, would also go 
unnoticed. Adding a time travel case with a multi-token expression next to this 
one, a batch case such as `SELECT * FROM t CHANGES FROM TIMESTAMP '2026-01-01' 
TO TIMESTAMP col_name`, and a st
 reaming case such as `SELECT * FROM STREAM t CHANGES FROM TIMESTAMP col_name` 
in StreamRelationParserSuite would pin the rendering and every call site, as 
the new `TABLESAMPLE(CAST(1 AS INT))` case does for sampling.
   
   **Verification:**
   - **Regression:** Parsing a time travel query whose timestamp is a 
multi-token expression that references a column, such as SELECT * FROM t 
TIMESTAMP AS OF col + INTERVAL 1 DAY, fails with 
INVALID_TIME_TRAVEL_TIMESTAMP_EXPR.COLUMN_REFERENCE, SQLSTATE 42K0E and an expr 
parameter equal to the quoted expression with its spaces, so the check fails if 
the parameter is built from the whitespace-free token text.
   - **Regression:** Parsing a batch CHANGES query whose end bound alone 
references a column, such as SELECT * FROM t CHANGES FROM TIMESTAMP 
'2026-01-01' TO TIMESTAMP col_name, fails with the same condition and an expr 
parameter naming the end-bound expression, and parsing a streaming CHANGES 
query whose start bound references a column, such as SELECT * FROM STREAM t 
CHANGES FROM TIMESTAMP col_name, fails with the same condition and an expr 
parameter naming that expression.



##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -9346,6 +9425,24 @@
     },
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_CHANGE_COLUMN" : {
+    "message" : [
+      "ALTER TABLE ... CHANGE COLUMN does not support"
+    ],
+    "subClass" : {
+      "NOT_NULL" : {
+        "message" : [
+          "setting NOT NULL. Use ALTER TABLE ... ALTER COLUMN ... SET NOT NULL 
instead."

Review Comment:
   **Nit (P3):** Only NOT NULL in the Hive-style column definition reaches this 
subcondition: `visitHiveChangeColumn` raises it for statements such as `ALTER 
TABLE t CHANGE COLUMN c c INT NOT NULL` (AstBuilder.scala:7117-7118). The 
native form takes either verb, since `#alterTableAlterColumn` is `ALTER TABLE 
... (ALTER | CHANGE) COLUMN? ...` with a `SET NOT NULL` action 
(SqlBaseParser.g4:501-502 and 2374), and `visitAlterTableAlterColumn` builds 
the same column change for `CHANGE` as for `ALTER` 
(AstBuilder.scala:7040-7057). Reading the parser, `ALTER TABLE t CHANGE COLUMN 
c SET NOT NULL` therefore behaves exactly like the `ALTER COLUMN ... SET NOT 
NULL` form this message recommends (on v1 session-catalog tables both are 
rejected the same way), yet the rendered message, "ALTER TABLE ... CHANGE 
COLUMN does not support setting NOT NULL. ...", tells users that CHANGE COLUMN 
cannot set NOT NULL. The legacy text limited the claim to Hive-style syntax. 
Naming the rejected form keeps the re
 medy and still reads correctly after the parent message:
   
   ```suggestion
             "NOT NULL in the column definition. Use ALTER TABLE ... ALTER 
COLUMN ... SET NOT NULL instead."
   ```
   
   The message then reads "ALTER TABLE ... CHANGE COLUMN does not support NOT 
NULL in the column definition. Use ALTER TABLE ... ALTER COLUMN ... SET NOT 
NULL instead." The condition name, SQLSTATE and the DDLParserSuite assertion 
stay as they are.
   
   **Verification:**
   - **Inspection:** Read with its parent message, the 
UNSUPPORTED_CHANGE_COLUMN.NOT_NULL message limits the unsupported case to NOT 
NULL in the CHANGE COLUMN column definition, no longer says that CHANGE COLUMN 
cannot set NOT NULL, and still recommends ALTER TABLE ... ALTER COLUMN ... SET 
NOT NULL, while the condition name, SQLSTATE 0A000 and its lack of message 
parameters are unchanged.



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