-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-27162][SQL] Add new method asCaseSensitiveMap in CaseInsensitiveStringMap #24094
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
Changes from 3 commits
7d711eb
66792a5
33a15fd
f0f59e3
e153f03
d252211
08ab550
2245766
28e05f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,9 +40,12 @@ public static CaseInsensitiveStringMap empty() { | |
| return new CaseInsensitiveStringMap(new HashMap<>(0)); | ||
| } | ||
|
|
||
| private final Map<String, String> original; | ||
|
|
||
| private final Map<String, String> delegate; | ||
|
|
||
| public CaseInsensitiveStringMap(Map<String, String> originalMap) { | ||
| this.original = new HashMap<>(originalMap.size()); | ||
| this.delegate = new HashMap<>(originalMap.size()); | ||
| putAll(originalMap); | ||
| } | ||
|
|
@@ -78,11 +81,13 @@ public String get(Object key) { | |
|
|
||
| @Override | ||
| public String put(String key, String value) { | ||
| original.put(key, value); | ||
| return delegate.put(toLowerCase(key), value); | ||
| } | ||
|
|
||
| @Override | ||
| public String remove(Object key) { | ||
| original.remove(key); | ||
| return delegate.remove(toLowerCase(key)); | ||
| } | ||
|
|
||
|
|
@@ -95,6 +100,7 @@ public void putAll(Map<? extends String, ? extends String> m) { | |
|
|
||
| @Override | ||
| public void clear() { | ||
| original.clear(); | ||
| delegate.clear(); | ||
| } | ||
|
|
||
|
|
@@ -157,4 +163,11 @@ public double getDouble(String key, double defaultValue) { | |
| String value = get(key); | ||
| return value == null ? defaultValue : Double.parseDouble(value); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the original case-sensitive map. | ||
| */ | ||
| public Map<String, String> getOriginalMap() { | ||
|
Contributor
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. What about |
||
| return original; | ||
|
Contributor
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. This should return a read-only version of original. You can use |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ package org.apache.spark.sql.internal | |
|
|
||
| import java.io.File | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.fs.Path | ||
|
|
||
|
|
@@ -32,7 +34,7 @@ import org.apache.spark.sql.catalyst.parser.ParserInterface | |
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.execution._ | ||
| import org.apache.spark.sql.streaming.StreamingQueryManager | ||
| import org.apache.spark.sql.util.{ExecutionListenerManager, QueryExecutionListener} | ||
| import org.apache.spark.sql.util.{CaseInsensitiveStringMap, ExecutionListenerManager, QueryExecutionListener} | ||
|
gengliangwang marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * A class that holds all session-specific state in a given [[SparkSession]]. | ||
|
|
@@ -96,6 +98,11 @@ private[sql] class SessionState( | |
| hadoopConf | ||
| } | ||
|
|
||
| def newHadoopConfWithCaseInsensitiveOptions(options: CaseInsensitiveStringMap): Configuration = { | ||
|
Contributor
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. I don't think we should pollute
Member
Author
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. Otherwise, developers might not be aware of using
Contributor
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. Then we should document it in
Contributor
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. I agree with @cloud-fan, I'd rather use
Contributor
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. I don't think we should pollute |
||
| // Hadoop configurations are case sensitive. | ||
| newHadoopConfWithOptions(options.getOriginalMap.asScala.toMap) | ||
| } | ||
|
|
||
| /** | ||
| * Get an identical copy of the `SessionState` and associate it with the given `SparkSession` | ||
| */ | ||
|
|
||
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.
The thing worries me most is the inconsistency between the case insensitive map and the original map. I think we should either fail or keep the latter entry if
a -> 1, A -> 2appears together.One thing we can simplify is,
CaseInsensitiveStringMapis read by data source and can be read-only. Then it can be easier to resolve conflicting entries at the beginning.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.
But the method
put/remove/clearstill need to be implemented...Do you mean that we can ignore original map in these method ?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.
We can just throw exception in these methods, and say this map is readonly.
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.
@cloud-fan This is a good solution!
@rdblue What do you think?
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.
That works for me. It is always a good idea to avoid passing mutable state to plugin code.