Skip to content

Conversation

@aokolnychyi
Copy link
Contributor

This PR adds years transform function to Spark 3.3.

@github-actions github-actions bot added the spark label Nov 17, 2022
@aokolnychyi
Copy link
Contributor Author


@Test
public void testDates() {
Assert.assertEquals(
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion but I prefer to also have a property style test, maybe something like

for (i in 1 to 1000) {
  x = random()
  assert(0, system.years(add_months(epoch, 12 * x) + system.years(add_months(epoch, -12 * x))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was inspired by our existing tests in core but let me add one more test for this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a closer look, I think current tests are easier to read as we provide the expected value explicitly.


@Override
public Integer produceResult(InternalRow input) {
// return null for null input to match what Spark does in codegen
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, as long as this is what Spark does 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's what we decided to do in other functions such as bucket and truncate.

Copy link
Member

@RussellSpitzer RussellSpitzer left a comment

Choose a reason for hiding this comment

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

Looks good to me, added a suggestion for some testing and there is one typo that needs to be cleaned up in a test.

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

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

overall LGTM, just some tiny nits/suggestions

}

@Override
public Integer produceResult(InternalRow input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this method appears to be the same for TimestampToYearsFunction + DateToYearsFunction, should we maybe move it to BaseToYearsFunction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are slightly different. One fetches integers and the other one fetches longs from input.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah good call, I missed this tiny detail :)

@aokolnychyi aokolnychyi merged commit 3a95e6a into apache:master Nov 24, 2022
@aokolnychyi
Copy link
Contributor Author

Thanks for reviewing, @RussellSpitzer @nastra!

sunchao pushed a commit to sunchao/iceberg that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants