Skip to content

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Apr 2, 2019

What changes were proposed in this pull request?

  • Added new test for Java Bean encoder of the classes: java.time.LocalDate and java.time.Instant.
  • Updated comment for Encoders.bean
  • New Row getters: getLocalDate and getInstant
  • Extended inferDataType to infer types for java.time.LocalDate -> DateType and java.time.Instant -> TimestampType.

How was this patch tested?

By JavaBeanDeserializationSuite

@MaxGekk
Copy link
Member Author

MaxGekk commented Apr 2, 2019

@dongjoon-hyun @cloud-fan Please, review this PR.

@SparkQA
Copy link

SparkQA commented Apr 2, 2019

Test build #104188 has finished for PR 24273 at commit 2e366b9.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@viirya
Copy link
Member

viirya commented Apr 2, 2019

retest this please.

}

@Test
public void testSpark30() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what does 30 mean here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it is just an unique id. I followed style of the test suite:

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that was the JIRA ticket ID?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems it is. I can assign ticket number too like testSpark27344 or nicer name like testBeanOfLocalDateAndInstant. I would prefer the former one.

@SparkQA
Copy link

SparkQA commented Apr 2, 2019

Test build #104189 has finished for PR 24273 at commit 2e366b9.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@srowen srowen left a comment

Choose a reason for hiding this comment

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

Looking OK to me

}

@Override
public String toString() {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to bother implementing toString here?

Copy link
Member Author

Choose a reason for hiding this comment

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

In regular case, toString should not be called but it is called when the assert fails.

}

private static Row createLocalDateInstantRow(Long index) {
Object[] values = new Object[] { LocalDate.ofEpochDay(42), Instant.ofEpochSecond(42) };
Copy link
Member

Choose a reason for hiding this comment

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

Total nit, but I think you can omit "new Object[]"

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right it can be omitted. Should I remove it?

Copy link
Member

Choose a reason for hiding this comment

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

Not unless you're otherwise changing the code. It doesn't matter. Just a style convention I like to use

*
* @throws ClassCastException when data type does not match.
*/
def getInstant(i: Int): java.time.Instant = getAs[java.time.Instant](i)
Copy link
Member

Choose a reason for hiding this comment

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

Are getLocalDate and getInstant added just for test? If so, seems to be overkill.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was added for consistency with other supported java classes.

Copy link
Member

Choose a reason for hiding this comment

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

They are not native classes for native Spark SQL datatypes. Not necessarily to have native getters for them. If you're like to add them, I'm fine with it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I just checked and found you added them as external types in RowEncoder recently. Then it makes sense.

@SparkQA
Copy link

SparkQA commented Apr 2, 2019

Test build #104211 has finished for PR 24273 at commit c39b0d5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • public static final class LocalDateInstantRecord

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this Apr 3, 2019
cloud-fan pushed a commit that referenced this pull request Apr 3, 2019
… Java Bean encoders

## What changes were proposed in this pull request?

- Added new test for Java Bean encoder of the classes: `java.time.LocalDate` and `java.time.Instant`.
- Updated comment for `Encoders.bean`
- New Row getters: `getLocalDate` and `getInstant`
- Extended `inferDataType` to infer types for `java.time.LocalDate` -> `DateType` and `java.time.Instant` -> `TimestampType`.

## How was this patch tested?

By `JavaBeanDeserializationSuite`

Closes #24273 from MaxGekk/bean-instant-localdate.

Lead-authored-by: Maxim Gekk <[email protected]>
Co-authored-by: Maxim Gekk <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@MaxGekk MaxGekk deleted the bean-instant-localdate branch September 18, 2019 15:57
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.

5 participants