Skip to content

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Jun 22, 2020

What changes were proposed in this pull request?

Extract common code from the expressions that get date or time fields from input dates/timestamps to new expressions GetDateField and GetTimeField, and re-use the common traits from the affected classes.

Why are the changes needed?

Code deduplication improves maintainability.

Does this PR introduce any user-facing change?

No

How was this patch tested?

By DateExpressionsSuite

@SparkQA
Copy link

SparkQA commented Jun 22, 2020

Test build #124365 has finished for PR 28894 at commit f2a278e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class DayOfWeek(child: Expression) extends GetDateField
  • case class WeekDay(child: Expression) extends GetDateField
  • case class WeekOfYear(child: Expression) extends GetDateField

case class Hour(child: Expression, timeZoneId: Option[String] = None)
extends UnaryExpression with TimeZoneAwareExpression with ImplicitCastInputTypes
with NullIntolerant {
trait GetTimeField extends UnaryExpression
Copy link
Member Author

@MaxGekk MaxGekk Jun 22, 2020

Choose a reason for hiding this comment

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

When I made it as abstract class with 2 args func and funcName, I got the following exception on tests from DateExpressionsSuite:

org.apache.spark.sql.catalyst.expressions.Second; no valid constructor
java.io.InvalidClassException: org.apache.spark.sql.catalyst.expressions.Second; no valid constructor
	at java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(ObjectStreamClass.java:169)
	at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:885)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2100)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1625)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:465)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:423)
	at org.apache.spark.serializer.JavaDeserializationStream.readObject(JavaSerializer.scala:76)
	at org.apache.spark.serializer.JavaSerializerInstance.deserialize(JavaSerializer.scala:109)
	at org.apache.spark.sql.catalyst.expressions.ExpressionEvalHelper.prepareEvaluation(ExpressionEvalHelper.scala:75)

I decided to leave it as a trait.

@MaxGekk
Copy link
Member Author

MaxGekk commented Jun 22, 2020

@cloud-fan @srowen @dongjoon-hyun @HyukjinKwon Could you review the refactoring, please.

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

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

Nice one

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in fcf9768 Jun 23, 2020
@HyukjinKwon
Copy link
Member

late LGTM too

@MaxGekk MaxGekk deleted the get-date-time-field-expr branch December 11, 2020 20:26
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.

5 participants