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-31091][Table SQL/Client] Add Ser/de for Interval types #21945

Merged
merged 4 commits into from Feb 22, 2023

Conversation

snuyanzin
Copy link
Contributor

What is the purpose of the change

The adds support for serialization/deserialization of interval types on sql gateway level to make queries

SELECT INTERVAL '1' DAY;
SELECT INTERVAL '2' YEAR;

working again.

Also it hardens modifiers for tests since in case of junit5 package private is enough

Verifying this change

There were added tests for month year and date time intervals

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: (yes )
  • The runtime per-record code paths (performance sensitive): ( no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: ( no )
  • The S3 file system connector: ( no)

Documentation

  • Does this pull request introduce a new feature? ( no)
  • If yes, how is the feature documented? (not applicable)

@flinkbot
Copy link
Collaborator

flinkbot commented Feb 15, 2023

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

Copy link
Member

@fsk119 fsk119 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. Could you add an ITCase about the case in the jira to verify we solve the problem?

@@ -71,23 +72,32 @@

/** Tests for {@link LogicalType} serialization and deserialization. */
@Execution(CONCURRENT)
public class LogicalTypeJsonSerDeTest {
class LogicalTypeJsonSerDeTest {

private final ObjectMapper mapper = buildObjectMapper();

@ParameterizedTest
@MethodSource("generateTestData")
Copy link
Member

Choose a reason for hiding this comment

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

Please also add a test about the serialization/deserialization of the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for interval types

@@ -123,7 +131,7 @@ public void testResultInfoSerDeWithNullValues(RowFormat rowFormat) throws Except

@ParameterizedTest
@ValueSource(strings = {"result_info_json_format.txt", "result_info_plain_text_format.txt"})
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 modify the JSON in the text to make sure others will not break the serialization results in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -87,6 +89,10 @@ public final class LogicalTypeJsonSerializer extends StdSerializer<LogicalType>
public static final String FIELD_NAME_CLASS = "class";
public static final String FIELD_NAME_SERIALIZER = "serializer";

// INTERVAL
Copy link
Member

Choose a reason for hiding this comment

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

I just wonder whether it's better to serialize the INTERVAL type as follows:

{
    "type": "INTERVAL",
    "upperResolution": {
          "precision": ...,
          "intervalUnit": "..."
    },
    "lowerResolution": ...
}

So we can align with the API in DataTypes#INTERVAL. WDYT? @twalthr @lincoln-lil

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for the alignment with datatype api, it can be easier to understand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From one side I'm ok to add upper/lowerResolution
however from another side current ser/de is based on LogicalTypeRoot. And INTERVAL is NOT a LogicalTypeRoot... it is just a LogicalTypeFamily. So it will require extra parsing to differentiate between YearMonthIntervalType and DayTimeIntervalType.
Or am I missing something here?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@snuyanzin snuyanzin Feb 21, 2023

Choose a reason for hiding this comment

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

updated usage of precision with usage of yearPrecision and dayPrecision based on offline discussion in slack

After another round of discussion it was decided not to do it

…son_format and result_info_plain_text_format, add tests for interval types
@snuyanzin
Copy link
Contributor Author

Could you add an ITCase about the case in the jira to verify we solve the problem?

done

Copy link
Member

@fsk119 fsk119 left a comment

Choose a reason for hiding this comment

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

Thanks for your update!

@@ -219,6 +231,25 @@ private static List<LogicalType> generateTestData() {
// ignore nullable for NullType
testTypes.add(new NullType());

// interval types
testTypes.add(new YearMonthIntervalType(YearMonthIntervalType.YearMonthResolution.MONTH));
Copy link
Member

Choose a reason for hiding this comment

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

We should move the cases into the types. In line 225, we will create test cases with or without nullbility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@fsk119 fsk119 left a comment

Choose a reason for hiding this comment

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

Thanks for your update. LGTM

@snuyanzin
Copy link
Contributor Author

@flinkbot run azure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants