Skip to content

[SPARK-22452][SQL]Add getInt, getLong, getBoolean to DataSourceV2Options#19902

Closed
skambha wants to merge 5 commits intoapache:masterfrom
skambha:spark22452
Closed

[SPARK-22452][SQL]Add getInt, getLong, getBoolean to DataSourceV2Options#19902
skambha wants to merge 5 commits intoapache:masterfrom
skambha:spark22452

Conversation

@skambha
Copy link
Copy Markdown
Contributor

@skambha skambha commented Dec 5, 2017

  • Implemented methods getInt, getLong, getBoolean for DataSourceV2Options
  • Added new unit tests to exercise these methods

@gatorsmile
Copy link
Copy Markdown
Member

ok to test

@SparkQA
Copy link
Copy Markdown

SparkQA commented Dec 6, 2017

Test build #84514 has finished for PR 19902 at commit bb01ff5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

return Optional.ofNullable(keyLowerCasedMap.get(toLowerCase(key)));
}

public Optional<Boolean> getBoolean(String key) {
Copy link
Copy Markdown
Contributor

@cloud-fan cloud-fan Dec 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid the expensive boxing, how about public boolean getBoolean(String key, boolean defaultValue)? This is also consistent with SparkConf.getXXX

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.

  1. So I have implemented the getBoolean, getInt, and getLong using the defaultValue and added unit tests for it.

  2. For now, I have left the other methods as well that return Optional<> keeping in line with the getString as it may still have some value.

Please take a look.

If we don't want (2), I can remove the version of the getBoolean, getLong, getInt that doesn't take the defaultValue.

Thanks for your comments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per @gatorsmile , I have gone and removed the version of the methods that doesn't take the default value.

Integer.parseInt(keyLowerCasedMap.get(lcaseKey)) : null);
}

public Optional<Long> getLong(String key) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also remove the three APIs without the default values?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Let me post another commit. Thanks.

public Optional<String> get(String key) {
return Optional.ofNullable(keyLowerCasedMap.get(toLowerCase(key)));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Get a parameter as a boolean, falling back to a default if not set */

Copy link
Copy Markdown
Contributor Author

@skambha skambha Dec 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Is it ok if I modify the comment for the method a bit to this:

  /**
   * 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
   */

Boolean.parseBoolean(keyLowerCasedMap.get(lcaseKey)) : defaultValue;
}

public int getInt(String key, int defaultValue) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Get a parameter as an integer, falling back to a default if not set */

Integer.parseInt(keyLowerCasedMap.get(lcaseKey)) : defaultValue;
}

public long getLong(String key, long defaultValue) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Get a parameter as a long, falling back to a default if not set */

@gatorsmile
Copy link
Copy Markdown
Member

LGTM except three comments.

@skambha
Copy link
Copy Markdown
Contributor Author

skambha commented Dec 6, 2017

great! Thanks @gatorsmile for your comments.

I have updated with code comments, please take a look. Thanks.

@SparkQA
Copy link
Copy Markdown

SparkQA commented Dec 7, 2017

Test build #84578 has finished for PR 19902 at commit 15e8ce5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link
Copy Markdown

SparkQA commented Dec 7, 2017

Test build #84579 has finished for PR 19902 at commit 5de7962.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link
Copy Markdown

SparkQA commented Dec 7, 2017

Test build #84582 has finished for PR 19902 at commit 7d87edc.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Copy Markdown
Contributor

thanks, merging to master!

@skambha would you like to open a new PR to add the rest of getXXX methods?

@asfgit asfgit closed this in 2be4482 Dec 7, 2017
@skambha
Copy link
Copy Markdown
Contributor Author

skambha commented Dec 7, 2017

great! Thanks @gatorsmile , @cloud-fan.

Yes. I would be happy to open a new PR to add the rest of them.

If I compare with the getXXX (for datatype) in SparkConf, it looks like the only missing one is to add getDouble. Do we want to add only that or any of the other datatypes or any other getXXX? Let me know and I would be happy to open a new PR to address it. Thank you!

@cloud-fan
Copy link
Copy Markdown
Contributor

ah i see, yea looks like getByte, getShort won't be very useful, let's add getDouble

@skambha
Copy link
Copy Markdown
Contributor Author

skambha commented Dec 7, 2017

cool! I will add that and submit a new PR.

@skambha
Copy link
Copy Markdown
Contributor Author

skambha commented Dec 7, 2017

Opened a new PR to add the getDouble method. #19921

@skambha skambha deleted the spark22452 branch December 8, 2017 18:31
jzhuge pushed a commit to jzhuge/spark that referenced this pull request Aug 20, 2018
…ions

- Implemented methods getInt, getLong, getBoolean for DataSourceV2Options
- Added new unit tests to exercise these methods

Author: Sunitha Kambhampati <skambha@us.ibm.com>

Closes apache#19902 from skambha/spark22452.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants