spark-test commented on code in PR #60588:
URL: https://github.com/apache/spark/pull/60588#discussion_r4595637478
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -5791,6 +5850,11 @@
"LATERAL can only be used with subquery and table-valued functions."
]
},
+ "MULTIPLE_FROM_TO_INTERVAL_UNITS" : {
Review Comment:
**Non-blocking (P2):** `parseIntervalLiteral` (AstBuilder.scala:5345-5361)
raises this subcondition for all three shapes the grammar captures
(SqlBaseParser.g4:1913-1923): unit-value pairs followed by a from-to range, a
from-to range followed by unit-value pairs, and two from-to ranges. Only the
last has more than one range. The regenerated interval golden files record it
for four literals with exactly one range: `interval 1 year '2-1' year to
month`, `interval 1 year '12:11:10' hour to second`, `interval '10-9' year to
month '1' year` and `interval '12:11:10' hour to second '1' year`. For those,
the name says there are several from-to ranges and the message asks the user to
keep only one, which they already do. The rule they actually break, that a
from-to range cannot be combined with other units, appears in neither. The
check runs before `spark.sql.legacy.interval.enabled` is read and does not
depend on ANSI mode, and SET TIME ZONE INTERVAL reaches it too. Once released,
this na
me can only be fixed by renaming a released condition.
The simplest fix keeps one subcondition but gives it a name and message that
state the rule for every shape, for example "A from-to unit range, such as YEAR
TO MONTH, must be the only unit specification in an interval literal; it cannot
be combined with unit-value pairs or another from-to range." Splitting it the
way `INSERT_OVERWRITE_DIRECTORY_PATH` is split also works, with one
subcondition for two ranges and one for a range mixed with unit-value pairs,
since `parseIntervalLiteral` already tells the branches apart. Either way, the
interval golden files then need to be regenerated.
**Verification:**
- **Regression:** Parsing interval 1 year '2-1' year to month, interval
'10-9' year to month '1' year and interval '10-9' year to month '2-1' year to
month, which cover the three rejected shapes, fails with the renamed
subcondition and SQLSTATE 42000 with ANSI mode on and off.
- **Inspection:** The renamed subcondition's message states the
single-from-to-range rule in terms that hold both for a range combined with
unit-value pairs and for two ranges, and no source, test or golden file still
names MULTIPLE_FROM_TO_INTERVAL_UNITS.
##########
sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala:
##########
@@ -745,23 +760,27 @@ private[sql] object QueryParsingErrors extends
DataTypeErrorsBase {
}
def invalidTimeZoneDisplacementValueError(ctx: SetTimeZoneContext):
Throwable = {
- new ParseException(errorClass = "_LEGACY_ERROR_TEMP_0045", ctx)
+ new ParseException(errorClass =
"INVALID_SQL_SYNTAX.SET_TIME_ZONE_INVALID_VALUE", ctx)
}
def createTempTableNotSpecifyProviderError(ctx: CreateTableContext):
Throwable = {
- new ParseException(errorClass = "_LEGACY_ERROR_TEMP_0046", ctx)
+ new ParseException(errorClass =
"INVALID_SQL_SYNTAX.CREATE_TEMP_TABLE_WITHOUT_PROVIDER", ctx)
}
def rowFormatNotUsedWithStoredAsError(ctx: CreateTableLikeContext):
Throwable = {
- new ParseException(errorClass = "_LEGACY_ERROR_TEMP_0047", ctx)
+ new ParseException(errorClass =
"INVALID_SQL_SYNTAX.ROW_FORMAT_SERDE_WITHOUT_STORED_AS", ctx)
}
def useDefinedRecordReaderOrWriterClassesError(ctx: ParserRuleContext):
Throwable = {
- new ParseException(errorClass = "_LEGACY_ERROR_TEMP_0048", ctx)
+ new ParseException(errorClass =
"UNSUPPORTED_FEATURE.TRANSFORM_RECORD_READER_WRITER", ctx)
Review Comment:
**Nit (P3):** This new message answers the question in `// TODO: what does
this message mean?`, which sits directly above this helper's only call in
`SparkSqlAstBuilder.withScriptIOSchema` (SparkSqlParser.scala:1297). The TODO
was about the old "Used defined record reader/writer classes" text. With this
message in place, it points maintainers at a problem that no longer exists.
That line is outside the diff, so I'm noting it here: the TODO line can be
deleted.
**Verification:**
- **Inspection:** The parser's TRANSFORM record reader/writer check no
longer carries a comment questioning its error message, and neither the check
nor the error it raises has changed.
##########
sql/api/src/main/scala/org/apache/spark/sql/errors/QueryParsingErrors.scala:
##########
@@ -477,8 +480,8 @@ private[sql] object QueryParsingErrors extends
DataTypeErrorsBase {
def mixedIntervalUnitsError(literal: String, ctx: ParserRuleContext):
Throwable = {
new ParseException(
- errorClass = "_LEGACY_ERROR_TEMP_0029",
- messageParameters = Map("literal" -> literal),
+ errorClass =
"INVALID_INTERVAL_FORMAT.MIXED_YEAR_MONTH_AND_DAY_TIME_FIELDS",
+ messageParameters = Map("input" -> literal),
Review Comment:
**Nit (P3):** `literal` is `source(ctx)` from
`constructMultiUnitsIntervalLiteral` (AstBuilder.scala:5291-5292). That is the
whole SQL literal, INTERVAL keyword and quotes included, on both the typed
`INTERVAL '<string>'` path and the multi-unit path. The parent
INVALID_INTERVAL_FORMAT template already quotes `<input>` ("Error parsing
'<input>' to interval. ..."). Reading the templates, `select -interval '-1
month 1 day -1 second'` therefore renders "Error parsing 'interval '-1 month 1
day -1 second'' to interval. ...", and the golden files record `input` as
`interval '-1 month 1 day -1 second'`. The other parse-time raisers of this
parent, such as `fromToIntervalUnsupportedError` and the new
NON_NUMERIC_MULTI_UNIT_VALUE and FROM_TO_VALUE_NOT_STRING, pass only the value.
Passing the interval value here instead (the string value on the typed-literal
path, the unit-value text on the multi-unit path) fixes the rendering. The
ExpressionParserSuite expectations and the interval and cas
t golden files would then need updating.
**Verification:**
- **Regression:** Parsing -interval '-1 month 1 day -1 second' and interval
'30' year '25' month '-100' day '40' hour reports input as the bare interval
text, with no SQL quotes and no INTERVAL keyword, so the rendered message
contains no nested quotes.
- **Behavior:** Parsing the typed literal INTERVAL '1 year 2 second' and the
unquoted multi-unit literal interval 4 month 2 weeks 3 microseconds still fails
with MIXED_YEAR_MONTH_AND_DAY_TIME_FIELDS and SQLSTATE 22006, with input set to
the interval text without the INTERVAL keyword.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -7048,13 +7044,10 @@ class AstBuilder extends DataTypeAstBuilder
val columnNameParts = typedVisit[Seq[String]](ctx.colName)
if (!conf.resolver(columnNameParts.last,
getIdentifierText(ctx.colType().colName))) {
- throw
QueryParsingErrors.operationInHiveStyleCommandUnsupportedError("Renaming
column",
- "ALTER COLUMN", ctx, Some("please run RENAME COLUMN instead"))
+ throw QueryParsingErrors.changeColumnRenameUnsupportedError(ctx)
}
if (ctx.colType.NULL != null) {
- throw QueryParsingErrors.operationInHiveStyleCommandUnsupportedError(
- "NOT NULL", "ALTER COLUMN", ctx,
- Some("please run ALTER COLUMN ... SET/DROP NOT NULL instead"))
+ throw QueryParsingErrors.changeColumnNotNullUnsupportedError(ctx)
Review Comment:
**Nit (P3):** No test reaches this branch.
`UNSUPPORTED_CHANGE_COLUMN.NOT_NULL` appears only in `QueryParsingErrors.scala`
and `error-conditions.json`, and no suite or golden file parses a Hive-style
CHANGE COLUMN with NOT NULL. The other four helpers split from the shared one
are covered in catalyst `DDLParserSuite`. Every test would still pass if the
condition string were misspelled (an internal error at runtime), if it were
swapped for the RENAME subcondition, or if this guard were dropped. Without the
guard the NOT NULL would be silently ignored, because the `AlterColumnSpec`
below sets `newNullability = None`. A `checkError` for `ALTER TABLE table_name
CHANGE COLUMN a a INT NOT NULL`, next to the RENAME case in 'alter table: hive
style change column', would close the gap. It would assert this condition,
SQLSTATE 0A000, empty parameters and the whole statement as context.
**Verification:**
- **Behavior:** A Hive-style CHANGE COLUMN that keeps the column name and
adds NOT NULL fails at parse time with UNSUPPORTED_CHANGE_COLUMN.NOT_NULL,
SQLSTATE 0A000, no message parameters and the whole statement as the query
context. The assertion fails if the NOT NULL guard is removed or if the helper
raises another subcondition.
--
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]