Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-12844][table-planner-blink] Use default conversion class LocalDate/LocalTime/LocalDateTime for DateType/TimeType/TimestampType in blink #8762

Closed
wants to merge 5 commits into from

Conversation

JingsongLi
Copy link
Contributor

What is the purpose of the change

Now we still use java.sql.Timestamp to be default conversion class for TimestampType.
We should use design of new Type System to use java.time.Local***.
NOTE, This may affect user behaviour:
eg: UDF with eval(Object o), now will pass a java.time.Local*** instead of java.sql..
Compatibility method: use DataType.bridgedTo(java.sql.
.class);

Verifying this change

ut

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)

@JingsongLi
Copy link
Contributor Author

This PR is rebased on #8757

@flinkbot
Copy link
Collaborator

flinkbot commented Jun 17, 2019

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

Please see the Pull Request Review Guide for a full explanation of the review process.


The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@JingsongLi JingsongLi force-pushed the time branch 2 times, most recently from 85bd1dd to c833a38 Compare July 5, 2019 08:13
Copy link
Contributor

@tsreaper tsreaper left a comment

Choose a reason for hiding this comment

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

LGTM

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 6, 2019

CI report for commit 772745b: ERROR Build

Copy link
Member

@wuchong wuchong left a comment

Choose a reason for hiding this comment

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

Thanks @JingsongLi . This is a great improvement for blink planner to have a better handling on timestamps. 👍

I left some comments below.

@@ -99,6 +102,9 @@
addMapping(Types.FLOAT, DataTypes.FLOAT().bridgedTo(Float.class));
addMapping(Types.DOUBLE, DataTypes.DOUBLE().bridgedTo(Double.class));
addMapping(Types.BIG_DEC, createLegacyType(LogicalTypeRoot.DECIMAL, Types.BIG_DEC));
addMapping(LocalTimeTypeInfo.LOCAL_DATE, DataTypes.DATE().bridgedTo(LocalDate.class));
addMapping(LocalTimeTypeInfo.LOCAL_TIME, DataTypes.TIME(0).bridgedTo(LocalTime.class));
addMapping(LocalTimeTypeInfo.LOCAL_DATE_TIME, DataTypes.TIMESTAMP(3).bridgedTo(LocalDateTime.class));
Copy link
Member

Choose a reason for hiding this comment

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

LocalTimeTypeInfo => Types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -500,7 +527,7 @@ class CodeGeneratorContext(val tableConfig: TableConfig) {
* Adds a reusable TimeZone to the member area of the generated class.
*/
def addReusableTimeZone(): String = {
Copy link
Member

Choose a reason for hiding this comment

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

Rename this method to addReusableLocalTimeZone or addReusableDefaultTimeZone? To have a better understanding from the method name that the time zone is not from TableConfig.getTimeZone but is JVM default time zone.

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 think it should read tableConfig.getTimeZone and used by next support for Timestamp with local zone.
addReusableLocalDateTime should just read TimeZone.getDefault.

Copy link
Contributor

@twalthr twalthr Jul 8, 2019

Choose a reason for hiding this comment

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

@JingsongLi Maybe we should update TableConfig and use ZoneId instead of the old TimeZone class. I haven't looked in to the details but I read:
A {@code ZoneId} is used to identify the rules used to convert between an {@link Instant} and a {@link LocalDateTime}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@twalthr good suggestion, +1, ZoneId for java 8 classes.
TimeZone is an outdated class and troublesome.

@@ -302,7 +302,7 @@ class StreamExecGroupWindowAggregate(
val builder = WindowOperatorBuilder
.builder()
.withInputFields(inputFields.toArray)
val timeZoneOffset = -config.getTimeZone.getOffset(Calendar.ZONE_OFFSET)
val timeZoneOffset = 0
Copy link
Member

Choose a reason for hiding this comment

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

Could you also remove the following constructor parameter for time zone? I think they are not needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, ok

@@ -399,6 +400,7 @@ class TemporalTypesTest extends ExpressionTestBase {
)
}

@Ignore // TODO support timestamp with local time zone
Copy link
Member

Choose a reason for hiding this comment

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

Will we support this before 1.9 release? Is that mean, the timeZone option in TableConfig will not work for blink planner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In next PR to support timestamp with local zone.

@@ -160,24 +160,16 @@ public TimeZone getNewInstance(String tz) {
* type used for UDF parameters ({@link java.sql.Timestamp}).
*
* <p>The internal long represents the time milliseconds since January 1, 1970, 00:00:00 GMT.
* So we don't need to take TimeZone into account.
* we need a TimeZone.
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment or add more details why we need time zone explicitly ?

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'll change it to calcite's implementation.

@@ -232,24 +237,43 @@ object BuiltInMethods {
val NOW_OFFSET = Types.lookupMethod(
classOf[SqlDateTimeUtils], "now", classOf[Long])

val DATE_FORMAT_STRING_STRING_STRING = Types.lookupMethod(
val DATE_FORMAT_STRING_STRING_STRING_TIME_ZONE = Types.lookupMethod(
Copy link
Member

Choose a reason for hiding this comment

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

We can remove all the TIME_ZONE suffix methods in this file. They are not used anymore.

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 think them will be used in next PR to support timestamp with local zone.

@@ -128,8 +135,21 @@
* lost its specific Java format. Only DataType retains all its
* Java format information.
*/
@SuppressWarnings("unchecked")
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

Please add a javadoc to declare which method should we use instead.
And we should replace all the places where this method is used with the new method?

* @param context context for converter.
*/
@SuppressWarnings("unchecked")
public static DataFormatConverter getConverterForDataType(DataType originDataType, Context context) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we pass a TimeZone instead of Context ? Will we add more parameters in the future?
To me, the way to construct a context is verbose.

public static DataFormatConverter getConverterForDataType(DataType originDataType) {
return getConverterForDataType(originDataType, new Context(DEFAULT_TIME_ZONE));
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use TableConfig.getTimeZone as the conversion time zone instead of local time zone in flink framework?

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 offline discussion with @wuchong , java.sql.Timestamp is a special format, valueOf and toString in sql.Timestamp will read the TimeZone.getDefault, So there, we should just use TimeZone.getDefault to correct valueOf and toString.

@@ -23,7 +23,7 @@ import org.apache.flink.api.java.typeutils.{MapTypeInfo, MultisetTypeInfo, Objec
import org.apache.flink.table.typeutils.TimeIntervalTypeInfo
import org.apache.flink.types.Row

import _root_.java.{lang, math, sql, util}
import _root_.java.{lang, math, sql, time, util}
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 this file can be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will delete it as first commit.

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 8, 2019

CI report for commit 3bdf6c3: SUCCESS Build

@JingsongLi
Copy link
Contributor Author

@wuchong @KurtYoung Updated, PTAL

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 8, 2019

CI report for commit 5f0e633: FAILURE Build

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 8, 2019

CI report for commit 7fe600a: FAILURE Build

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 8, 2019

CI report for commit 869712b: FAILURE Build

@flinkbot
Copy link
Collaborator

flinkbot commented Jul 8, 2019

CI report for commit da4c415: FAILURE Build

@KurtYoung KurtYoung closed this in 2e09d94 Jul 8, 2019
@JingsongLi JingsongLi deleted the time branch July 10, 2019 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants