jerryshao commented on code in PR #14991:
URL: https://github.com/apache/gravitino/pull/14991#discussion_r4596014018
##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.java:
##########
@@ -348,9 +354,55 @@ public Table loadTable(Identifier ident) throws
NoSuchTableException {
@Override
public Table loadTable(Identifier ident, Set<TableWritePrivilege>
writePrivileges)
throws NoSuchTableException {
+ if (isDataSourceReference(ident)) {
+ throw new NoSuchTableException(ident);
+ }
return loadTableForWriting(ident);
}
+ /**
+ * Detects Spark's DataSource shortcut syntax after the analyzer expands the
identifier against
+ * this catalog as the current catalog, for example {@code SELECT * FROM
parquet.`path`} or {@code
+ * SELECT * FROM csv.`s3a://bucket/file.csv`}. The expanded identifier has a
single-part namespace
+ * (the format name) and the table name itself is a file path.
+ *
+ * <p>Such a lookup must not reach the Gravitino table APIs: the path may
contain dots, so the
+ * server splits the full name into more than three parts and {@code
MetadataObjects.of(TABLE,
+ * names)} throws {@code IllegalArgumentException}, which the Spark analyzer
does not treat as
+ * non-existence. Reporting "not found" lets the analyzer fall back to its
SQL-on-file resolver,
+ * the same path vanilla Spark takes.
+ *
+ * <p>The path characters ({@code /} or {@code \}) are only a cheap
structural prefilter: some
+ * Gravitino backends (for example PostgreSQL quoted identifiers) allow them
in table names. The
+ * decisive check is that the single-part namespace names no Gravitino
schema, so a real table
+ * reference such as {@code db."a/b"} keeps resolving when the schema
exists. Only the prefiltered
+ * identifiers pay the extra schema lookup.
+ */
+ @VisibleForTesting
+ protected boolean isDataSourceReference(Identifier ident) {
+ if (!looksLikeDataSourceReference(ident)) {
Review Comment:
[P2] A valid file query such as SELECT * FROM parquet.`data.parquet` never
reaches the new fallback because it has no path separator. Likewise, merely
having a schema named `parquet` prevents fallback for `/tmp/data.parquet`, even
when that table does not exist. Both cases still send the dotted filename
through the failing table lookup. Please accommodate relative filenames and
distinguish an existing table from an existing schema, while preserving
real-table precedence. Add regression coverage through Spark's analyzer for
both cases.
--
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]