-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-36108][SQL] Refactor first set of 20 query parsing errors to use error classes #33535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32b28e0
bb4e1fb
9aea3eb
c46d4a0
91d05b9
907e96d
b1f97b0
f3380a5
3971047
86ea00d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
| "message" : [ "Field name %s is ambiguous and has %s matching fields in the struct." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "COLUMN_ALIASES_NOT_ALLOWED_IN_OPERATION" : { | ||
| "message" : [ "Column aliases are not allowed in %s." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "DIVIDE_BY_ZERO" : { | ||
| "message" : [ "divide by zero" ], | ||
| "sqlState" : "22012" | ||
|
|
@@ -11,6 +15,14 @@ | |
| "message" : [ "Found duplicate keys '%s'" ], | ||
| "sqlState" : "23000" | ||
| }, | ||
| "EMPTY_PARTITION_KEY" : { | ||
| "message" : [ "Found an empty partition key '%s'." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "EMPTY_SOURCE_FOR_MERGE" : { | ||
| "message" : [ "Empty source for merge: you should specify a source table/subquery in merge." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "GROUPING_COLUMN_MISMATCH" : { | ||
| "message" : [ "Column of grouping (%s) can't be found in grouping columns %s" ], | ||
| "sqlState" : "42000" | ||
|
|
@@ -29,10 +41,26 @@ | |
| "message" : [ "Invalid pivot column '%s'. Pivot columns must be comparable." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "INSERTED_VALUE_NUMBER_NOT_MATCH_FIELD_NUMBER" : { | ||
| "message" : [ "The number of inserted values cannot match the fields." ], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
| "sqlState" : "42000" | ||
| }, | ||
| "INVALID_FIELD_NAME" : { | ||
| "message" : [ "Field name %s is invalid: %s is not a struct." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "INVALID_LATERAL_JOIN_RELATION" : { | ||
| "message" : [ "LATERAL can only be used with subquery" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "LATERAL_WITH_PIVOT_IN_FROM_CLAUSE_NOT_ALLOWED" : { | ||
| "message" : [ "LATERAL cannot be used together with PIVOT in FROM clause" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "MERGE_STATEMENT_WITHOUT_WHEN_CLAUSE" : { | ||
| "message" : [ "There must be at least one WHEN clause in a MERGE statement" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "MISSING_COLUMN" : { | ||
| "message" : [ "cannot resolve '%s' given input columns: [%s]" ], | ||
| "sqlState" : "42000" | ||
|
|
@@ -41,6 +69,10 @@ | |
| "message" : [ "Unknown static partition column: %s" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "NON_LAST_CLAUSE_OMIT_CONDITION" : { | ||
| "message" : [ "When there are more than one %s clauses in a MERGE statement, only the last %s clause can omit the condition." ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "NON_LITERAL_PIVOT_VALUES" : { | ||
| "message" : [ "Literal expressions required for pivot values, found '%s'" ], | ||
| "sqlState" : "42000" | ||
|
|
@@ -49,6 +81,10 @@ | |
| "message" : [ "PARTITION clause cannot contain a non-partition column name: %s" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "OPERATION_UNSUPPORTED" : { | ||
| "message" : [ "%s is not supported" ], | ||
| "sqlState" : "0A000" | ||
| }, | ||
| "PIVOT_VALUE_DATA_TYPE_MISMATCH" : { | ||
| "message" : [ "Invalid pivot value '%s': value data type %s does not match pivot column data type %s" ], | ||
| "sqlState" : "42000" | ||
|
|
@@ -57,9 +93,25 @@ | |
| "message" : [ "The second argument of '%s' function needs to be an integer." ], | ||
| "sqlState" : "22023" | ||
| }, | ||
| "TRANSFORM_NOT_SUPPORT_QUANTIFIER" : { | ||
| "message" : [ "TRANSFORM does not support DISTINCT/ALL in inputs" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "TRANSFORM_WITH_SERDE_UNSUPPORTED" : { | ||
| "message" : [ "TRANSFORM with serde is only supported in hive mode" ], | ||
| "sqlState" : "42000" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be 0A000 |
||
| }, | ||
| "UNABLE_TO_ACQUIRE_MEMORY" : { | ||
| "message" : [ "Unable to acquire %s bytes of memory, got %s" ] | ||
| }, | ||
| "UNRECOGNIZED_ACTION" : { | ||
| "message" : [ "Unrecognized %s action: %s" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
| "UNSUPPORTED_LATERAL_JOIN_TYPE" : { | ||
| "message" : [ "Unsupported LATERAL join type %s" ], | ||
| "sqlState" : "42000" | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be 0A000 |
||
| "WRITING_JOB_ABORTED" : { | ||
| "message" : [ "Writing job aborted" ], | ||
| "sqlState" : "40000" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,8 +292,6 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg | |
| case hiveDir: InsertOverwriteHiveDirContext => | ||
| val (isLocal, storage, provider) = visitInsertOverwriteHiveDir(hiveDir) | ||
| InsertIntoDir(isLocal, storage, provider, query, overwrite = true) | ||
| case _ => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed? |
||
| throw QueryParsingErrors.invalidInsertIntoError(ctx) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,91 +29,84 @@ import org.apache.spark.sql.catalyst.trees.Origin | |
| */ | ||
| object QueryParsingErrors { | ||
|
|
||
| def invalidInsertIntoError(ctx: InsertIntoContext): Throwable = { | ||
| new ParseException("Invalid InsertIntoContext", ctx) | ||
| } | ||
|
|
||
| def insertOverwriteDirectoryUnsupportedError(ctx: InsertIntoContext): Throwable = { | ||
| new ParseException("INSERT OVERWRITE DIRECTORY is not supported", ctx) | ||
| new ParseException("OPERATION_UNSUPPORTED", Array("INSERT OVERWRITE DIRECTORY"), ctx) | ||
| } | ||
|
|
||
| def columnAliasInOperationNotAllowedError(op: String, ctx: TableAliasContext): Throwable = { | ||
| new ParseException(s"Columns aliases are not allowed in $op.", ctx.identifierList()) | ||
| new ParseException("COLUMN_ALIASES_NOT_ALLOWED_IN_OPERATION", Array(op), ctx.identifierList()) | ||
| } | ||
|
|
||
| def emptySourceForMergeError(ctx: MergeIntoTableContext): Throwable = { | ||
| new ParseException("Empty source for merge: you should specify a source" + | ||
| " table/subquery in merge.", ctx.source) | ||
| new ParseException("EMPTY_SOURCE_FOR_MERGE", Array.empty, ctx.source) | ||
| } | ||
|
|
||
| def unrecognizedMatchedActionError(ctx: MatchedClauseContext): Throwable = { | ||
| new ParseException(s"Unrecognized matched action: ${ctx.matchedAction().getText}", | ||
| ctx.matchedAction()) | ||
| new ParseException("UNRECOGNIZED_ACTION", | ||
| Array("matched", ctx.matchedAction().getText), ctx.matchedAction()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make |
||
| } | ||
|
|
||
| def insertedValueNumberNotMatchFieldNumberError(ctx: NotMatchedClauseContext): Throwable = { | ||
| new ParseException("The number of inserted values cannot match the fields.", | ||
| new ParseException("INSERTED_VALUE_NUMBER_NOT_MATCH_FIELD_NUMBER", Array.empty, | ||
| ctx.notMatchedAction()) | ||
| } | ||
|
|
||
| def unrecognizedNotMatchedActionError(ctx: NotMatchedClauseContext): Throwable = { | ||
| new ParseException(s"Unrecognized not matched action: ${ctx.notMatchedAction().getText}", | ||
| ctx.notMatchedAction()) | ||
| new ParseException("UNRECOGNIZED_ACTION", | ||
| Array("not matched", ctx.notMatchedAction().getText), ctx.notMatchedAction()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make |
||
| } | ||
|
|
||
| def mergeStatementWithoutWhenClauseError(ctx: MergeIntoTableContext): Throwable = { | ||
| new ParseException("There must be at least one WHEN clause in a MERGE statement", ctx) | ||
| new ParseException("MERGE_STATEMENT_WITHOUT_WHEN_CLAUSE", Array.empty, ctx) | ||
| } | ||
|
|
||
| def nonLastMatchedClauseOmitConditionError(ctx: MergeIntoTableContext): Throwable = { | ||
| new ParseException("When there are more than one MATCHED clauses in a MERGE " + | ||
| "statement, only the last MATCHED clause can omit the condition.", ctx) | ||
| new ParseException("NON_LAST_CLAUSE_OMIT_CONDITION", Array("MATCHED", "MATCHED"), ctx) | ||
| } | ||
|
|
||
| def nonLastNotMatchedClauseOmitConditionError(ctx: MergeIntoTableContext): Throwable = { | ||
| new ParseException("When there are more than one NOT MATCHED clauses in a MERGE " + | ||
| "statement, only the last NOT MATCHED clause can omit the condition.", ctx) | ||
| new ParseException("NON_LAST_CLAUSE_OMIT_CONDITION", Array("NOT MATCHED", "NOT MATCHED"), ctx) | ||
| } | ||
|
|
||
| def emptyPartitionKeyError(key: String, ctx: PartitionSpecContext): Throwable = { | ||
| new ParseException(s"Found an empty partition key '$key'.", ctx) | ||
| new ParseException("EMPTY_PARTITION_KEY", Array(key), ctx) | ||
| } | ||
|
|
||
| def combinationQueryResultClausesUnsupportedError(ctx: QueryOrganizationContext): Throwable = { | ||
| new ParseException( | ||
| "Combination of ORDER BY/SORT BY/DISTRIBUTE BY/CLUSTER BY is not supported", ctx) | ||
| new ParseException("OPERATION_UNSUPPORTED", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably have a separate error class for unsupported combinations. |
||
| Array("Combination of ORDER BY/SORT BY/DISTRIBUTE BY/CLUSTER BY"), ctx) | ||
| } | ||
|
|
||
| def distributeByUnsupportedError(ctx: QueryOrganizationContext): Throwable = { | ||
| new ParseException("DISTRIBUTE BY is not supported", ctx) | ||
| new ParseException("OPERATION_UNSUPPORTED", Array("DISTRIBUTE BY"), ctx) | ||
| } | ||
|
|
||
| def transformNotSupportQuantifierError(ctx: ParserRuleContext): Throwable = { | ||
| new ParseException("TRANSFORM does not support DISTINCT/ALL in inputs", ctx) | ||
| new ParseException("TRANSFORM_NOT_SUPPORT_QUANTIFIER", Array.empty, ctx) | ||
| } | ||
|
|
||
| def transformWithSerdeUnsupportedError(ctx: ParserRuleContext): Throwable = { | ||
| new ParseException("TRANSFORM with serde is only supported in hive mode", ctx) | ||
| new ParseException("TRANSFORM_WITH_SERDE_UNSUPPORTED", Array.empty, ctx) | ||
| } | ||
|
|
||
| def lateralWithPivotInFromClauseNotAllowedError(ctx: FromClauseContext): Throwable = { | ||
| new ParseException("LATERAL cannot be used together with PIVOT in FROM clause", ctx) | ||
| new ParseException("LATERAL_WITH_PIVOT_IN_FROM_CLAUSE_NOT_ALLOWED", Array.empty, ctx) | ||
| } | ||
|
|
||
| def lateralJoinWithNaturalJoinUnsupportedError(ctx: ParserRuleContext): Throwable = { | ||
| new ParseException("LATERAL join with NATURAL join is not supported", ctx) | ||
| new ParseException("OPERATION_UNSUPPORTED", Array("LATERAL join with NATURAL join"), ctx) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can also make a separate error class here as well, maybe about how different join types are incompatible. |
||
| } | ||
|
|
||
| def lateralJoinWithUsingJoinUnsupportedError(ctx: ParserRuleContext): Throwable = { | ||
| new ParseException("LATERAL join with USING join is not supported", ctx) | ||
| new ParseException("OPERATION_UNSUPPORTED", Array("LATERAL join with USING join"), ctx) | ||
| } | ||
|
|
||
| def unsupportedLateralJoinTypeError(ctx: ParserRuleContext, joinType: String): Throwable = { | ||
| new ParseException(s"Unsupported LATERAL join type $joinType", ctx) | ||
| new ParseException("UNSUPPORTED_LATERAL_JOIN_TYPE", Array(joinType), ctx) | ||
| } | ||
|
|
||
| def invalidLateralJoinRelationError(ctx: RelationPrimaryContext): Throwable = { | ||
| new ParseException(s"LATERAL can only be used with subquery", ctx) | ||
| new ParseException("INVALID_LATERAL_JOIN_RELATION", Array.empty, ctx) | ||
| } | ||
|
|
||
| def repetitiveWindowDefinitionError(name: String, ctx: WindowClauseContext): Throwable = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The grammar is a bit strange. Maybe
INSERTED_VALUE_AND_FIELD_NUMBER_MISMATCH?