-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-27106][SQL] merge CaseInsensitiveStringMap and DataSourceOptions #24025
Changes from 4 commits
b8b3a3c
c60e2bf
a53748d
32fdb64
71e6ae1
7b922f9
5ff7202
4599659
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 |
---|---|---|
|
@@ -31,19 +31,20 @@ | |
* This is used to pass options to v2 implementations to ensure consistent case insensitivity. | ||
* <p> | ||
* Methods that return keys in this map, like {@link #entrySet()} and {@link #keySet()}, return | ||
* keys converted to lower case. | ||
* keys converted to lower case. This map doesn't allow null key. | ||
*/ | ||
@Experimental | ||
public class CaseInsensitiveStringMap implements Map<String, String> { | ||
|
||
public static CaseInsensitiveStringMap empty() { | ||
return new CaseInsensitiveStringMap(); | ||
return new CaseInsensitiveStringMap(new HashMap<>(0)); | ||
} | ||
|
||
private final Map<String, String> delegate; | ||
|
||
private CaseInsensitiveStringMap() { | ||
this.delegate = new HashMap<>(); | ||
public CaseInsensitiveStringMap(Map<String, String> originalMap) { | ||
this.delegate = new HashMap<>(originalMap.size()); | ||
putAll(originalMap); | ||
} | ||
|
||
@Override | ||
|
@@ -56,9 +57,13 @@ public boolean isEmpty() { | |
return delegate.isEmpty(); | ||
} | ||
|
||
private String toLowerCase(Object key) { | ||
return key.toString().toLowerCase(Locale.ROOT); | ||
} | ||
|
||
@Override | ||
public boolean containsKey(Object key) { | ||
return delegate.containsKey(key.toString().toLowerCase(Locale.ROOT)); | ||
return delegate.containsKey(toLowerCase(key)); | ||
} | ||
|
||
@Override | ||
|
@@ -68,17 +73,17 @@ public boolean containsValue(Object value) { | |
|
||
@Override | ||
public String get(Object key) { | ||
return delegate.get(key.toString().toLowerCase(Locale.ROOT)); | ||
return delegate.get(toLowerCase(key)); | ||
} | ||
|
||
@Override | ||
public String put(String key, String value) { | ||
return delegate.put(key.toLowerCase(Locale.ROOT), value); | ||
return delegate.put(toLowerCase(key), value); | ||
} | ||
|
||
@Override | ||
public String remove(Object key) { | ||
return delegate.remove(key.toString().toLowerCase(Locale.ROOT)); | ||
return delegate.remove(toLowerCase(key)); | ||
} | ||
|
||
@Override | ||
|
@@ -107,4 +112,49 @@ public Collection<String> values() { | |
public Set<Map.Entry<String, String>> entrySet() { | ||
return delegate.entrySet(); | ||
} | ||
|
||
/** | ||
* Returns the boolean value to which the specified key is mapped, | ||
* or defaultValue if there is no mapping for the key. The key match is case-insensitive | ||
*/ | ||
public boolean getBoolean(String key, boolean defaultValue) { | ||
String value = get(key); | ||
// We can't use `Boolean.parseBoolean` here, as it returns false for invalid strings. | ||
if (value == null) { | ||
return defaultValue; | ||
} else if (value.equalsIgnoreCase("true")) { | ||
return true; | ||
} else if (value.equalsIgnoreCase("false")) { | ||
return false; | ||
} else { | ||
throw new IllegalArgumentException(value + " is not a boolean string."); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the integer value to which the specified key is mapped, | ||
* or defaultValue if there is no mapping for the key. The key match is case-insensitive | ||
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. Nit: add 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. it's too minor to trigger another QA round. I'll fix it in another PR if the current QA round passes. |
||
*/ | ||
public int getInt(String key, int defaultValue) { | ||
String value = get(key); | ||
return value == null ? defaultValue : Integer.parseInt(value); | ||
} | ||
|
||
/** | ||
* Returns the long value to which the specified key is mapped, | ||
* or defaultValue if there is no mapping for the key. The key match is case-insensitive | ||
*/ | ||
public long getLong(String key, long defaultValue) { | ||
String value = get(key); | ||
return value == null ? defaultValue : Long.parseLong(value); | ||
} | ||
|
||
/** | ||
* Returns the double value to which the specified key is mapped, | ||
* or defaultValue if there is no mapping for the key. The key match is case-insensitive | ||
*/ | ||
public double getDouble(String key, double defaultValue) { | ||
String value = get(key); | ||
return value == null ? defaultValue : Double.parseDouble(value); | ||
} | ||
} |
This file was deleted.
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.
These 4 methods are from
DataSourceOptions
, which are pretty general and useful.