Skip to content

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Oct 25, 2019

What changes were proposed in this pull request?

In the PR, I propose to move all static methods from the CalendarInterval class to the IntervalUtils object. All those methods are rewritten from Java to Scala.

Why are the changes needed?

Does this PR introduce any user-facing change?

No

How was this patch tested?

  • By moved tests from CalendarIntervalSuite to IntervalUtilsSuite
  • By existing test suites

@MaxGekk
Copy link
Member Author

MaxGekk commented Oct 25, 2019

@cloud-fan @HyukjinKwon @dongjoon-hyun Please, take a look at the PR.

@SparkQA
Copy link

SparkQA commented Oct 25, 2019

Test build #112688 has finished for PR 26261 at commit 21c30c6.

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

@MaxGekk
Copy link
Member Author

MaxGekk commented Oct 25, 2019

jenkins, retest this, please

@SparkQA
Copy link

SparkQA commented Oct 26, 2019

Test build #112692 has finished for PR 26261 at commit 21c30c6.

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

@dongjoon-hyun
Copy link
Member

@MaxGekk . I left a few minor comments. In general, the logic is correctly migrated from Java to Scala.

And, I agree with @MaxGekk 's opinion. How do you think about this, @cloud-fan ?

@SparkQA
Copy link

SparkQA commented Oct 26, 2019

Test build #112713 has finished for PR 26261 at commit a417cbe.

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

@MaxGekk
Copy link
Member Author

MaxGekk commented Oct 26, 2019

jenkins, retest this, please

@SparkQA
Copy link

SparkQA commented Oct 26, 2019

Test build #112717 has finished for PR 26261 at commit a417cbe.

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

}
}

private val yearMonthPattern = Pattern.compile("^([+|-])?(\\d+)-(\\d+)$")
Copy link
Member

Choose a reason for hiding this comment

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

This can just use Scala regex primitives instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will require rewriting of dependent code but I wanted to just move methods and keep them closer to original methods as much as possible. Maybe we will refactor the code in a follow up PR?

Copy link
Member

Choose a reason for hiding this comment

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

You're already moving the code and converting to scala in other ways, so I think it's not a big deal to do it here rather than make another one for pretty minor adjustments. Or is there an argument that git won't really track the history of this code after move if it's changed a lot?

Copy link
Member Author

Choose a reason for hiding this comment

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

To use Scala regexp, I will have to restructure the code significantly, so, it will be impossible to track anything.

Copy link
Member

Choose a reason for hiding this comment

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

Why does it need any restructuring? "...".r gives you an object with pretty much the same API. You don't have to use regex pattern matching in Scala if it's disruptive. Well, I don't feel strongly about it, just doesn't seem any more of a change than you've already made in adapting this code to Scala.

*/
private def parseSecondNano(secondNano: String): Long = {
val parts = secondNano.split("\\.")
if (parts.length == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

use a match statement maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would do this refactoring in a separate PR too if you don't mind.

@SparkQA
Copy link

SparkQA commented Oct 26, 2019

Test build #112720 has finished for PR 26261 at commit e443921.

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

@SparkQA
Copy link

SparkQA commented Oct 27, 2019

Test build #112721 has finished for PR 26261 at commit a6fbc4d.

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

@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Oct 27, 2019

The following failure happens in master branch, too. It seems that irrelevant to this PR.

org.scalatest.exceptions.TestFailedException: 1572217200000000 was not 1572213600000000 plus or minus 30000000

@MaxGekk
Copy link
Member Author

MaxGekk commented Oct 27, 2019

jenkins, retest this, please

result
}

private val yearMonthPattern = "^\\s*([+|-])?(\\d+)-(\\d+)\\s*$".r
Copy link
Contributor

@cloud-fan cloud-fan Oct 28, 2019

Choose a reason for hiding this comment

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

The previous regex does not have the \\s* at the beginning and end. This is because we get the string from parser which already trims the white spaces. Shall we change it back?

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, we trim the input explicitly: b482367 . I just trim by the regexp.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will revert the regexp and add the assert: assert(input.length == input.trim.length)

Copy link
Member Author

Choose a reason for hiding this comment

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

I will do the same in fromDayTimeString()

s"Cannot support (interval '$s' $from to $to) expression")
}
new CalendarInterval(0, sign * (
days * DateTimeUtils.MICROS_PER_DAY + hours * MICROS_PER_HOUR +
Copy link
Contributor

Choose a reason for hiding this comment

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

inspired by https://github.com/apache/spark/pull/26261/files#diff-eba257f41b49f470321579875f054f00R152 , we should use exact math functions here too. This can be done in a followup.

Copy link
Contributor

@cloud-fan cloud-fan left a comment

Choose a reason for hiding this comment

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

LGTM except a minor comment

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented Oct 28, 2019

Test build #112791 has finished for PR 26261 at commit 38f7c78.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 28, 2019

Test build #112792 has finished for PR 26261 at commit 38f7c78.

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

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Oct 29, 2019

Test build #112817 has finished for PR 26261 at commit 38f7c78.

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

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Oct 29, 2019

Test build #112826 has finished for PR 26261 at commit 38f7c78.

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

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

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

Looks fine to me too

@HyukjinKwon
Copy link
Member

retest this please

1 similar comment
@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Oct 29, 2019

Test build #112832 has finished for PR 26261 at commit 38f7c78.

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

@cloud-fan cloud-fan closed this in 44c1c03 Oct 29, 2019
@cloud-fan
Copy link
Contributor

thanks, merging to master!

@dongjoon-hyun
Copy link
Member

Thank you all!

@MaxGekk MaxGekk deleted the refactoring-calendar-interval branch June 5, 2020 19:40
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.

6 participants