This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
fix reading properties without changing old configuration #119
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99e152f
fix reading properties
wuciawe 62ec418
fix reading properties
wuciawe cb32a90
filterKeys doesn't return a Serializable Map
wuciawe 9525121
Fixed broken filter
pfcoperez f23ecd6
Improved style
pfcoperez c9c7bad
Fixed spark incompatibility
pfcoperez 4480f0c
Merge pull request #2 from pfcoperez/pr119_suggestions
wuciawe 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 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 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 |
---|---|---|
|
@@ -62,7 +62,7 @@ abstract class ConfigBuilder[Builder<:ConfigBuilder[Builder] ]( | |
*/ | ||
def build(): Config = new Config { | ||
|
||
val properties = builder.properties | ||
val properties = builder.properties.map(kv => kv.copy(_1 = kv._1.toLowerCase)) | ||
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 approach is more readable:
|
||
|
||
require( | ||
requiredProperties.forall(properties.isDefinedAt), | ||
|
@@ -109,7 +109,7 @@ trait Config extends Serializable { | |
* @return the value associated with `key` if it exists, | ||
* otherwise the result of the `default` computation. | ||
*/ | ||
def getOrElse[T](key: Property, default: => T): T = properties.get(key) match { | ||
def getOrElse[T](key: Property, default: => T): T = properties.get(key.toLowerCase) match { | ||
case Some(v) => v.asInstanceOf[T] | ||
case None => default | ||
} | ||
|
@@ -121,7 +121,7 @@ trait Config extends Serializable { | |
* @return An optional value of expected type | ||
*/ | ||
def get[T: ClassTag](property: Property): Option[T] = | ||
properties.get(property).map(_.asInstanceOf[T]) | ||
properties.get(property.toLowerCase).map(_.asInstanceOf[T]) | ||
|
||
/** | ||
* Gets specified property from current configuration object. | ||
|
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.
The logic here is wrong: You are filtering those
config
properties which does not contain the whole option list.I'd try something like:
Or, cleaner:
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.
Looking at your commits I see you had already noticed that
filterKeys
isn't compatible with a map to be distributed to Spark workers as its return instance is not serializable. In any case, you should apply the logic I proposed: