-
Notifications
You must be signed in to change notification settings - Fork 14k
[FLINK-37925][table] Support casting from VARIANT to primitive types #28733
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
Changes from all commits
d1f1a22
6c422be
cca9d90
3bfbb43
0ebbdb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import org.apache.flink.table.types.logical.IntType; | ||
| import org.apache.flink.table.types.logical.LocalZonedTimestampType; | ||
| import org.apache.flink.table.types.logical.LogicalType; | ||
| import org.apache.flink.table.types.logical.MapType; | ||
| import org.apache.flink.table.types.logical.NullType; | ||
| import org.apache.flink.table.types.logical.RawType; | ||
| import org.apache.flink.table.types.logical.RowType; | ||
|
|
@@ -46,6 +47,7 @@ | |
| import org.apache.flink.table.types.logical.TinyIntType; | ||
| import org.apache.flink.table.types.logical.VarBinaryType; | ||
| import org.apache.flink.table.types.logical.VarCharType; | ||
| import org.apache.flink.table.types.logical.VariantType; | ||
| import org.apache.flink.table.types.logical.YearMonthIntervalType; | ||
| import org.apache.flink.table.types.logical.ZonedTimestampType; | ||
| import org.apache.flink.table.types.logical.utils.LogicalTypeCasts; | ||
|
|
@@ -57,6 +59,7 @@ | |
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
@@ -262,7 +265,37 @@ private static Stream<Arguments> testData() { | |
| new RawType<>(Integer.class, IntSerializer.INSTANCE), | ||
| VarCharType.STRING_TYPE, | ||
| false, | ||
| true)); | ||
| true), | ||
|
|
||
| // variant to scalar is explicit only | ||
| Arguments.of(new VariantType(), new BooleanType(), false, true), | ||
| Arguments.of(new VariantType(), new TinyIntType(), false, true), | ||
| Arguments.of(new VariantType(), new IntType(), false, true), | ||
| Arguments.of(new VariantType(), new BigIntType(), false, true), | ||
| Arguments.of(new VariantType(), new DoubleType(), false, true), | ||
| Arguments.of(new VariantType(), new DecimalType(10, 2), false, true), | ||
| Arguments.of(new VariantType(), new DateType(), false, true), | ||
| Arguments.of(new VariantType(), new TimestampType(), false, true), | ||
|
raminqaf marked this conversation as resolved.
|
||
| Arguments.of(new VariantType(), new TimestampType(3), false, true), | ||
| Arguments.of(new VariantType(), new LocalZonedTimestampType(), false, true), | ||
| Arguments.of(new VariantType(), new LocalZonedTimestampType(9), false, true), | ||
| Arguments.of( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is interval intentionally skipped?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variant.Type has no interval kind. Please refer to: https://cwiki.apache.org/confluence/spaces/FLINK/pages/349637099/FLIP-521+Integrating+Variant+Type+into+Flink+Enabling+Efficient+Semi-Structured+Data+Processing#FLIP521:IntegratingVariantTypeintoFlink:EnablingEfficientSemiStructuredDataProcessing-Casting |
||
| new VariantType(), | ||
| new VarBinaryType(VarBinaryType.MAX_LENGTH), | ||
| false, | ||
| true), | ||
| // variant identity cast is implicit | ||
| Arguments.of(new VariantType(), new VariantType(), true, true), | ||
| // TIME, character strings and constructed targets are not castable from variant | ||
| Arguments.of(new VariantType(), new TimeType(), false, false), | ||
| Arguments.of(new VariantType(), VarCharType.STRING_TYPE, false, false), | ||
| Arguments.of(new VariantType(), new ArrayType(new IntType()), false, false), | ||
| Arguments.of(new VariantType(), new RowType(List.of()), false, false), | ||
| Arguments.of( | ||
| new VariantType(), | ||
| new MapType(new IntType(), new CharType()), | ||
| false, | ||
| false)); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "{index}: [From: {0}, To: {1}, Implicit: {2}, Explicit: {3}]") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the cast is to a string then we could issue a helpful exception message indicating which SQL functions the user should use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this is a good idea and helpful for the user. Implementing it is a bit messy. Still I kept the changes for you to review. Since it adds lots of nose in the method. But let me know what you think. See
getUnsupportedCastHintandCastInputTypeStrategy.