Commit 6806c8b
committed
[SPARK-55024][SQL][FOLLOWUP] Delay namespace length check to v1 identifier creation
### What changes were proposed in this pull request?
This is a followup to #53788 which moved the namespace length check from individual command handlers to the `CatalogAndIdentifier` extractor. That approach is too aggressive: users can extend the session catalog via `CatalogExtension` and support multi-part namespaces through v2 APIs. The check should only happen when we actually create v1 identifiers like `TableIdentifier`, not at the shared name-resolution layer.
### Changes
- **Remove the namespace check from `CatalogAndIdentifier.unapply`** so it remains a pure name-resolution mechanism, preserving `CatalogExtension` flexibility.
- **Tighten `CatalogV2Implicits.IdentifierHelper.asTableIdentifier` and `asFunctionIdentifier`** to require exactly one namespace part and throw `REQUIRES_SINGLE_PART_NAMESPACE` (instead of the less precise `IDENTIFIER_TOO_MANY_NAME_PARTS`). This centralizes the validation.
- **Remove the now-redundant `V2SessionCatalog.TableIdentifierHelper`** and use the unified `CatalogV2Implicits` conversion everywhere.
- **Simplify `ResolveSessionCatalog` extractors** (`ResolvedV1Identifier`, `ResolvedIdentifierInSessionCatalog`, `ResolvedViewIdentifier`) to delegate to `ident.asTableIdentifier`.
- **Fix `SparkSqlParser` temp view creation** to check name length before calling `asTableIdentifier`, so the user always sees `notAllowedToAddDBPrefixForTempViewError` instead of a generic error.
### Why are the changes needed?
`CatalogExtension` allows users to extend the built-in session catalog and potentially support multi-part namespaces for v2 operations. The early check in `CatalogAndIdentifier` would block such extensions. The namespace length should only be validated when we actually need to create v1 identifiers (e.g. `TableIdentifier`), which inherently require a single-part namespace.
Additionally, this PR unifies the scattered namespace validation into a single point (`CatalogV2Implicits.IdentifierHelper`), reducing code duplication and ensuring consistent `REQUIRES_SINGLE_PART_NAMESPACE` errors.
### Does this PR introduce _any_ user-facing change?
Yes. Multi-part namespace identifiers now flow through `CatalogAndIdentifier` without error, allowing `CatalogExtension` implementations to handle them. The error is only thrown when the session catalog actually needs to convert to a v1 identifier.
### How was this patch tested?
Existing tests updated:
- `LookupCatalogSuite` — removed the early-rejection test, added multi-part namespace cases back.
- `V2SessionCatalogSuite` — updated to expect `REQUIRES_SINGLE_PART_NAMESPACE`.
- `DataSourceV2SQLSuiteV1Filter` and `DataSourceV2FunctionSuite` — all 313 tests pass.
### Was this patch authored or co-authored using generative AI tooling?
Yes.
Made with [Cursor](https://cursor.com)
Closes #54247 from cloud-fan/follow.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent b604338 commit 6806c8b
File tree
20 files changed
+87
-134
lines changed- common/utils/src/main/resources/error
- sql
- catalyst/src
- main/scala/org/apache/spark/sql
- connector/catalog
- errors
- test/scala/org/apache/spark/sql/connector/catalog
- core/src
- main/scala/org/apache/spark/sql
- catalyst/analysis
- execution
- datasources/v2
- jdbc
- test
- resources/sql-tests
- analyzer-results
- results
- scala/org/apache/spark/sql
- connector
- errors
- execution
- command/v1
- datasources/v2
- jdbc
- hive/src/test/scala/org/apache/spark/sql/hive/execution/command
20 files changed
+87
-134
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5366 | 5366 | | |
5367 | 5367 | | |
5368 | 5368 | | |
5369 | | - | |
| 5369 | + | |
5370 | 5370 | | |
5371 | 5371 | | |
5372 | 5372 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
170 | 169 | | |
171 | | - | |
| 170 | + | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | 195 | | |
197 | | - | |
| 196 | + | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
Lines changed: 5 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
109 | 107 | | |
110 | 108 | | |
111 | 109 | | |
112 | | - | |
113 | | - | |
| 110 | + | |
| 111 | + | |
114 | 112 | | |
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | | - | |
| 119 | + | |
122 | 120 | | |
123 | 121 | | |
124 | | - | |
| 122 | + | |
125 | 123 | | |
126 | 124 | | |
127 | | - | |
| 125 | + | |
128 | 126 | | |
129 | 127 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | 128 | | |
136 | 129 | | |
137 | 130 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1542 | 1542 | | |
1543 | 1543 | | |
1544 | 1544 | | |
1545 | | - | |
| 1545 | + | |
1546 | 1546 | | |
1547 | 1547 | | |
1548 | 1548 | | |
1549 | 1549 | | |
1550 | | - | |
| 1550 | + | |
1551 | 1551 | | |
1552 | 1552 | | |
1553 | 1553 | | |
| |||
Lines changed: 2 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 82 | | |
98 | 83 | | |
99 | 84 | | |
| |||
Lines changed: 6 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
727 | 726 | | |
728 | 727 | | |
729 | 728 | | |
730 | | - | |
731 | | - | |
| 729 | + | |
732 | 730 | | |
733 | | - | |
| 731 | + | |
| 732 | + | |
734 | 733 | | |
735 | 734 | | |
736 | 735 | | |
| |||
763 | 762 | | |
764 | 763 | | |
765 | 764 | | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
| 765 | + | |
771 | 766 | | |
772 | 767 | | |
773 | 768 | | |
774 | 769 | | |
775 | 770 | | |
776 | | - | |
| 771 | + | |
777 | 772 | | |
778 | 773 | | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
| 774 | + | |
784 | 775 | | |
785 | 776 | | |
786 | 777 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
701 | | - | |
702 | | - | |
| 701 | + | |
703 | 702 | | |
704 | 703 | | |
705 | | - | |
| 704 | + | |
706 | 705 | | |
| 706 | + | |
707 | 707 | | |
708 | 708 | | |
709 | 709 | | |
| |||
Lines changed: 2 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
367 | 368 | | |
368 | 369 | | |
369 | 370 | | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | 371 | | |
391 | 372 | | |
392 | 373 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
434 | 433 | | |
435 | 434 | | |
436 | 435 | | |
437 | | - | |
| 436 | + | |
438 | 437 | | |
439 | 438 | | |
440 | 439 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
886 | | - | |
| 886 | + | |
887 | 887 | | |
888 | 888 | | |
889 | 889 | | |
| |||
897 | 897 | | |
898 | 898 | | |
899 | 899 | | |
900 | | - | |
| 900 | + | |
901 | 901 | | |
902 | 902 | | |
903 | 903 | | |
| |||
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
914 | | - | |
| 914 | + | |
915 | 915 | | |
916 | 916 | | |
917 | 917 | | |
| |||
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
928 | | - | |
| 928 | + | |
929 | 929 | | |
930 | 930 | | |
931 | 931 | | |
| |||
939 | 939 | | |
940 | 940 | | |
941 | 941 | | |
942 | | - | |
| 942 | + | |
943 | 943 | | |
944 | 944 | | |
945 | 945 | | |
| |||
975 | 975 | | |
976 | 976 | | |
977 | 977 | | |
978 | | - | |
| 978 | + | |
979 | 979 | | |
980 | 980 | | |
981 | 981 | | |
| |||
0 commit comments