-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-4699][SQL] make caseSensitive configurable in Analyzer.scala #3558
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
578d167
make caseSensitive configurable
f57f15c
add testcase
91b1b96
make caseSensitive configurable in Analyzer
e7bca31
make caseSensitive configuration in Analyzer and Catalog
fcbf0d9
fix scalastyle check
6332e0f
fix bug
005c56d
make SQLContext caseSensitivity configurable
9bf4cc7
fix bug in catalyst
73c16b1
fix bug in sql/hive
05b09a3
fix conflict base on the latest master branch
dee56e9
fix test case failure
39e369c
fix confilct after DataFrame PR
12eca9a
solve conflict with master
664d1e9
Merge branch 'master' of https://github.com/apache/spark into case
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
53 changes: 53 additions & 0 deletions
53
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/CatalystConf.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,53 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import scala.collection.immutable | ||
|
|
||
| private[spark] object CatalystConf{ | ||
| val CASE_SENSITIVE = "spark.sql.caseSensitive" | ||
| } | ||
|
|
||
| private[spark] trait CatalystConf { | ||
| def setConf(key: String, value: String) : Unit | ||
| def getConf(key: String) : String | ||
| def getConf(key: String, defaultValue: String) : String | ||
| def getAllConfs: immutable.Map[String, String] | ||
| } | ||
|
|
||
| /** | ||
| * A trivial conf that is empty. Used for testing when all | ||
| * relations are already filled in and the analyser needs only to resolve attribute references. | ||
| */ | ||
| object EmptyConf extends CatalystConf { | ||
| def setConf(key: String, value: String) : Unit = { | ||
| throw new UnsupportedOperationException | ||
| } | ||
|
|
||
| def getConf(key: String) : String = { | ||
| throw new UnsupportedOperationException | ||
| } | ||
|
|
||
| def getConf(key: String, defaultValue: String) : String = { | ||
| throw new UnsupportedOperationException | ||
| } | ||
|
|
||
| def getAllConfs: immutable.Map[String, String] = { | ||
| throw new UnsupportedOperationException | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -19,18 +19,19 @@ package org.apache.spark.sql.catalyst.analysis | |
|
|
||
| import org.apache.spark.util.collection.OpenHashSet | ||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.errors.TreeNodeException | ||
| import org.apache.spark.sql.catalyst.CatalystConf | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.rules._ | ||
| import org.apache.spark.sql.catalyst.test.SimpleConf | ||
| import org.apache.spark.sql.types._ | ||
|
|
||
| /** | ||
| * A trivial [[Analyzer]] with an [[EmptyCatalog]] and [[EmptyFunctionRegistry]]. Used for testing | ||
| * when all relations are already filled in and the analyser needs only to resolve attribute | ||
| * references. | ||
| */ | ||
| object SimpleAnalyzer extends Analyzer(EmptyCatalog, EmptyFunctionRegistry, true) | ||
| object SimpleAnalyzer extends Analyzer(EmptyCatalog, EmptyFunctionRegistry, new SimpleConf) | ||
|
|
||
| /** | ||
| * Provides a logical query plan analyzer, which translates [[UnresolvedAttribute]]s and | ||
|
|
@@ -39,11 +40,17 @@ object SimpleAnalyzer extends Analyzer(EmptyCatalog, EmptyFunctionRegistry, true | |
| */ | ||
| class Analyzer(catalog: Catalog, | ||
|
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. Existing: this indentation is wrong. |
||
| registry: FunctionRegistry, | ||
| caseSensitive: Boolean, | ||
| conf: CatalystConf, | ||
| maxIterations: Int = 100) | ||
| extends RuleExecutor[LogicalPlan] with HiveTypeCoercion { | ||
|
|
||
| val resolver = if (caseSensitive) caseSensitiveResolution else caseInsensitiveResolution | ||
| def resolver: Resolver = { | ||
| if (conf.getConf(CatalystConf.CASE_SENSITIVE, "true").toBoolean) { | ||
| caseSensitiveResolution | ||
| } else { | ||
| caseInsensitiveResolution | ||
| } | ||
| } | ||
|
|
||
| val fixedPoint = FixedPoint(maxIterations) | ||
|
|
||
|
|
||
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
41 changes: 41 additions & 0 deletions
41
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/test/SimpleConf.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,41 @@ | ||
| /* | ||
| * 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.test | ||
|
|
||
| import org.apache.spark.sql.catalyst.CatalystConf | ||
|
|
||
| import scala.collection.immutable | ||
| import scala.collection.mutable | ||
|
|
||
| /** A CatalystConf that can be used for local testing. */ | ||
| class SimpleConf extends CatalystConf{ | ||
| val map = mutable.Map[String, String]() | ||
|
|
||
| def setConf(key: String, value: String) : Unit = { | ||
| map.put(key, value) | ||
| } | ||
| def getConf(key: String) : String ={ | ||
| map.get(key).get | ||
| } | ||
| def getConf(key: String, defaultValue: String) : String = { | ||
| map.getOrElse(key, defaultValue) | ||
| } | ||
| def getAllConfs: immutable.Map[String, String] = { | ||
| map.toMap | ||
| } | ||
| } |
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
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
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.
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.
I think the catalyst conf can be as simple as a set of abstract methods that need to be implemented by some concrete conf.
We can have a trivial one for testing:
case class SimpleConf(caseSensitiveAnalysis: Boolean) extends CatalystConfand SQLConf can mix this trait in as you are already doing.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.
Also, most interfaces in catalyst are not private since this package is not part of our standard compatibility guarantees.