Github user twalthr commented on a diff in the pull request:
https://github.com/apache/flink/pull/4746#discussion_r142641600
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/literals.scala
---
@@ -103,13 +148,21 @@ case class Literal(value: Any, resultType:
TypeInformation[_]) extends LeafExpre
}
}
- private def dateToCalendar: Calendar = {
+ /**
+ * Convert a date value to a utc calendar.
+ * <p>
+ * We're assuming that when the user passes in a Date its constructed
from fields,
+ * such as days and hours, and that they want those fields to be in the
same timezone as the
+ * Calcite times, which are UTC. Since we need to convert a Date to a
Calendar, that means we
+ * have to shift the epoch millisecond timestamp to account for the
difference between UTC and
+ * local time.
+ * @return Get the Calendar value
+ */
+ private def valueAsUtcCalendar: Calendar = {
val date = value.asInstanceOf[java.util.Date]
- val cal = Calendar.getInstance(Literal.GMT)
- val t = date.getTime
- // according to Calcite's SqlFunctions.internalToXXX methods
- cal.setTimeInMillis(t + TimeZone.getDefault.getOffset(t))
--- End diff --
Could you explain why `cal.setTimeInMillis(t +
TimeZone.getDefault.getOffset(t))` did not produce the correct result? Calcite
is also doing it like that.
---