Skip to content

[SPARK-59460][SQL] Assign a name to the error condition _LEGACY_ERROR_TEMP_1072 - #58759

Open
Ma77Ball wants to merge 5 commits into
apache:masterfrom
Ma77Ball:assign-name-legacy-error-1072
Open

Ma77Ball wants to merge 5 commits into
apache:masterfrom
Ma77Ball:assign-name-legacy-error-1072

Conversation

@Ma77Ball

@Ma77Ball Ma77Ball commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Rename the legacy error condition _LEGACY_ERROR_TEMP_1072 to TABLES_OR_VIEWS_NOT_IN_SAME_DATABASE (SQLSTATE 0AKD0). It is raised by SessionCatalog.getTablesByName when the requested tables/views span more than one database. The message is also reworded for clarity.

Why are the changes needed?

The error-conditions README disallows new _LEGACY_ERROR_TEMP_* entries and asks existing ones to be resolved. This resolves one (part of SPARK-37935).

Does this PR introduce any user-facing change?

Yes. The condition becomes TABLES_OR_VIEWS_NOT_IN_SAME_DATABASE with SQLSTATE 0AKD0 ("Cross catalog or schema operation not supported"), and the message is reworded to "Retrieving tables or views from more than one database is not supported. Requested: ." SQLSTATE 0AKD0 matches the cross-schema restriction and follows the precedent of CANNOT_RENAME_ACROSS_SCHEMA, rather than the more generic 0A000 ("feature not supported").

How was this patch tested?

Strengthened the existing SessionCatalogSuite test to assert the condition and parameters via checkError (it previously only intercepted the exception). SparkThrowableSuite passes.

Was this patch authored or co-authored using generative AI tooling?

Co-authored with Claude Opus 4.8

@Ma77Ball

Copy link
Copy Markdown
Contributor Author

@uros-b PTAL when available.

@Ma77Ball

Ma77Ball commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@uros-b friendly ping, PTAL when available. Thanks!

@nchammas nchammas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending wording suggestion.

Comment on lines +8151 to +8153
"Cannot retrieve tables or views that do not belong to the same database. Requested: <qualifiedTableNames>."
],
"sqlState" : "0A000"

@nchammas nchammas Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the error state maps to "feature not supported", I would tweak the message to use that wording.

For example: "Retrieving tables or views from more than one database is not supported. Requested: <qualifiedTableNames>."

This also avoids the double negative of "cannot retrieve ... that do not belong".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nchammas ty, I have updated to avoid the double negative and to account for the sqlState change mentioned below.

"message" : [
"Cannot retrieve tables or views that do not belong to the same database. Requested: <qualifiedTableNames>."
],
"sqlState" : "0A000"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0A000 right here?

0A000 is "feature not supported". This is a same-database restriction on SessionCatalog.getTablesByName, not an unimplemented feature.

CANNOT_RENAME_ACROSS_SCHEMA already uses 0AKD0 ("Cross catalog or schema operation not supported"), which is a closer match. RENAME_TABLE_SOURCE_DESTINATION_DATABASE_MISMATCH uses 3F000. I'd prefer 0AKD0 here unless there is a reason to stay on 0A000.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's cc @srielau here ^^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0AKD0 is Databricks-specific, no? It is a closer match, though.

@Ma77Ball Ma77Ball Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 0AKD0 is specific to Databricks (link). I also couldn't find any reference to it in the ISO/IEC 9075 standard.

However, I noticed in the repo that 0AKD0 is used in error-conditions.json on line 899:

  "CANNOT_RENAME_ACROSS_SCHEMA" : {
    "message" : [
      "Renaming a <type> across schemas is not allowed."
    ],
    "sqlState" : "0AKD0"
  },

I'm not sure whether this sets a precedent or whether this topic has been discussed before. I am OK with either option and can update the message and sqlState accordingly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, Databricks originated the subclass, but this doesn't necessarily mean that OSS Spark cannot use it. For example, CANNOT_RENAME_ACROSS_SCHEMA already ships 0AKD0 in Spark.

I still prefer 0AKD0 here. 0A000 is the generic "feature not supported" bucket. This is a cross-database restriction on SessionCatalog.getTablesByName, the same shape as a cross-schema rename.

@srielau WDYT? which state for this catalog restriction

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, from day one we have been using SQLSTATEs outside those listed in the SQL standard, which have been popularized by other vendors. The goal of 0AK vs 0AKD, was to minimize conflicts. Once a SQLSTATE has been assigned, everything speaks for reusing it, as long as we are faithful in its meaning.
That being said, we must remember that the SQL Standard does NOT Have error conditions or SQLCODEs. So our need to differentiate between different kinds of 0A*** is largely mitigated by being able to go all in with error condition names.
As such, I would not consider the debate of 0A000 vs 0AKD0 vs 0AK00 as fundamenmtal.
The finer the SQLSTATE, the easier it is to collect metrics on a set of condition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the 0A error class is appropriate, and the sub-class is not as important to get exactly right. I think 0AKD0 is a good choice, too.

the SQL Standard does NOT Have error conditions or SQLCODEs

Side point but: Did you mean to say SQLSTATE instead of SQLCODE here?

SQLCODE is a deprecated part of the SQL standard. SQLSTATE is a different thing (which maps to our error states), and the standard very much does have SQLSTATEs (search for "Table_23").

@srielau srielau Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"SQL Standard does NOT Have error conditions or SQLCODEs" I think we agree.
All the SQL Standard has are SQLSTATEs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srielau, thanks for the clarification. @uros-b, I have updated the SQLSTATE to the preferred state: 0AKD0.

…OT_IN_SAME_DATABASE

- Avoided the double negative in the message.
- Change the SQLSTATE from 0A000 to 0AKD0 ("Cross catalog or schema
operation not supported")
@Ma77Ball
Ma77Ball requested a review from uros-b October 9, 2026 02:51
…y-error-1072

# Conflicts:
#	common/utils/src/main/resources/error/error-conditions.json
@Ma77Ball
Ma77Ball force-pushed the assign-name-legacy-error-1072 branch from f23b7fe to fe89468 Compare October 10, 2026 18:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants