-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26946][SQL][FOLLOWUP] Require lookup function #24689
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b62182f
[SPARK-26946][SQL][FOLLOWUP] Handle lookupCatalog function not defined
jzhuge d2085e5
Add unit test
jzhuge d5564a8
Revert "Add unit test"
jzhuge bb4514c
Revert "[SPARK-26946][SQL][FOLLOWUP] Handle lookupCatalog function no…
jzhuge 0f4d9aa
[SPARK-26946][SQL][FOLLOWUP] Require lookup function
jzhuge 0f73998
Make Analyzer abstract and add TestAnalyzer
jzhuge cecbea0
Revert "Make Analyzer abstract and add TestAnalyzer"
jzhuge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TestAnalyzer.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.catalog.v2.{CatalogNotFoundException, CatalogPlugin} | ||
| import org.apache.spark.sql.catalyst.catalog._ | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| class TestAnalyzer( | ||
| catalog: SessionCatalog, | ||
| conf: SQLConf) extends Analyzer(catalog, conf) { | ||
|
|
||
| override protected def lookupCatalog(name: String): CatalogPlugin = | ||
| throw new CatalogNotFoundException("No catalog lookup function") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...catalyst/src/test/scala/org/apache/spark/sql/catalyst/catalog/v2/LookupCatalogSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.spark.sql.catalyst.catalog.v2 | ||
|
|
||
| import org.scalatest.Inside | ||
| import org.scalatest.Matchers._ | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.catalog.v2.{CatalogNotFoundException, CatalogPlugin, Identifier, LookupCatalog} | ||
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser | ||
| import org.apache.spark.sql.util.CaseInsensitiveStringMap | ||
|
|
||
| private case class TestCatalogPlugin(override val name: String) extends CatalogPlugin { | ||
|
|
||
| override def initialize(name: String, options: CaseInsensitiveStringMap): Unit = Unit | ||
| } | ||
|
|
||
| class LookupCatalogSuite extends SparkFunSuite with LookupCatalog with Inside { | ||
| import CatalystSqlParser._ | ||
|
|
||
| private val catalogs = Seq("prod", "test").map(x => x -> new TestCatalogPlugin(x)).toMap | ||
|
|
||
| override def lookupCatalog(name: String): CatalogPlugin = | ||
| catalogs.getOrElse(name, throw new CatalogNotFoundException(s"$name not found")) | ||
|
|
||
| test("catalog object identifier") { | ||
| Seq( | ||
| ("tbl", None, Seq.empty, "tbl"), | ||
| ("db.tbl", None, Seq("db"), "tbl"), | ||
| ("prod.func", catalogs.get("prod"), Seq.empty, "func"), | ||
| ("ns1.ns2.tbl", None, Seq("ns1", "ns2"), "tbl"), | ||
| ("prod.db.tbl", catalogs.get("prod"), Seq("db"), "tbl"), | ||
| ("test.db.tbl", catalogs.get("test"), Seq("db"), "tbl"), | ||
| ("test.ns1.ns2.ns3.tbl", catalogs.get("test"), Seq("ns1", "ns2", "ns3"), "tbl"), | ||
| ("`db.tbl`", None, Seq.empty, "db.tbl"), | ||
| ("parquet.`file:/tmp/db.tbl`", None, Seq("parquet"), "file:/tmp/db.tbl"), | ||
| ("`org.apache.spark.sql.json`.`s3://buck/tmp/abc.json`", None, | ||
| Seq("org.apache.spark.sql.json"), "s3://buck/tmp/abc.json")).foreach { | ||
| case (sql, expectedCatalog, namespace, name) => | ||
| inside(parseMultipartIdentifier(sql)) { | ||
| case CatalogObjectIdentifier(catalog, ident) => | ||
| catalog shouldEqual expectedCatalog | ||
| ident shouldEqual Identifier.of(namespace.toArray, name) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("table identifier") { | ||
| Seq( | ||
| ("tbl", "tbl", None), | ||
| ("db.tbl", "tbl", Some("db")), | ||
| ("`db.tbl`", "db.tbl", None), | ||
| ("parquet.`file:/tmp/db.tbl`", "file:/tmp/db.tbl", Some("parquet")), | ||
| ("`org.apache.spark.sql.json`.`s3://buck/tmp/abc.json`", "s3://buck/tmp/abc.json", | ||
| Some("org.apache.spark.sql.json"))).foreach { | ||
| case (sql, table, db) => | ||
| inside (parseMultipartIdentifier(sql)) { | ||
| case AsTableIdentifier(ident) => | ||
| ident shouldEqual TableIdentifier(table, db) | ||
| } | ||
| } | ||
| Seq( | ||
| "prod.func", | ||
| "prod.db.tbl", | ||
| "ns1.ns2.tbl").foreach { sql => | ||
| parseMultipartIdentifier(sql) match { | ||
| case AsTableIdentifier(_) => | ||
| fail(s"$sql should not be resolved as TableIdentifier") | ||
| case _ => | ||
| } | ||
| } | ||
| } | ||
| } |
99 changes: 0 additions & 99 deletions
99
...test/scala/org/apache/spark/sql/catalyst/catalog/v2/ResolveMultipartIdentifierSuite.scala
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Why not continue to pass a lookup function in some paths and default the analyzer to use one that throws
CatalogNotFoundException? That would avoid a lot of these changes.Uh oh!
There was an error while loading. Please reload this page.
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.
Reverted commit
Make Analyzer abstract and add TestAnalyzerto minimize changes to test classes.If you feel strongly, I can add the 4th parameter
override val lookupCatalog: String => CatalogPluginto Analyzer constructor. Although users can override in the following manner: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.
Sounds good to me.