You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tw...@apache.org on 2020/05/16 11:00:33 UTC
[flink] 04/05: [hotfix][table-common] Fix conversion class of
element array data types
This is an automated email from the ASF dual-hosted git repository.
twalthr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit b02e7c0937248a5b5348fe176b166a313313abcf
Author: Timo Walther <tw...@apache.org>
AuthorDate: Fri May 15 09:50:08 2020 +0200
[hotfix][table-common] Fix conversion class of element array data types
---
.../flink/table/types/CollectionDataType.java | 13 ++++++++++-
.../apache/flink/table/types/DataTypesTest.java | 25 +++++++++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/CollectionDataType.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/CollectionDataType.java
index b69feaf..f896a94 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/CollectionDataType.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/CollectionDataType.java
@@ -80,7 +80,7 @@ public final class CollectionDataType extends DataType {
return new CollectionDataType(
logicalType,
Preconditions.checkNotNull(newConversionClass, "New conversion class must not be null."),
- elementDataType);
+ ensureElementConversionClass(elementDataType, newConversionClass));
}
@Override
@@ -126,4 +126,15 @@ public final class CollectionDataType extends DataType {
}
return clazz;
}
+
+ private DataType ensureElementConversionClass(
+ DataType elementDataType,
+ Class<?> clazz) {
+ // arrays are a special case because their element conversion class depends on the
+ // outer conversion class
+ if (logicalType.getTypeRoot() == LogicalTypeRoot.ARRAY && clazz.isArray()) {
+ return elementDataType.bridgedTo(clazz.getComponentType());
+ }
+ return elementDataType;
+ }
}
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java
index ec37360..072534b 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java
@@ -247,6 +247,12 @@ public class DataTypesTest {
.expectConversionClass(Integer[][].class),
TestSpec
+ .forDataType(ARRAY(ARRAY(INT().notNull())).bridgedTo(int[][].class))
+ .expectLogicalType(new ArrayType(new ArrayType(new IntType(false))))
+ .expectConversionClass(int[][].class)
+ .expectChildren(DataTypes.ARRAY(INT().notNull()).bridgedTo(int[].class)),
+
+ TestSpec
.forDataType(MULTISET(MULTISET(INT())))
.expectLogicalType(new MultisetType(new MultisetType(new IntType())))
.expectConversionClass(Map.class),
@@ -365,7 +371,9 @@ public class DataTypesTest {
assertThat(dataType, hasLogicalType(testSpec.expectedLogicalType));
- assertThat(toDataType(testSpec.expectedLogicalType), equalTo(dataType));
+ assertThat(
+ toDataType(testSpec.expectedLogicalType).bridgedTo(dataType.getConversionClass()),
+ equalTo(dataType));
assertThat(toLogicalType(dataType), equalTo(testSpec.expectedLogicalType));
}
@@ -380,6 +388,14 @@ public class DataTypesTest {
}
@Test
+ public void testChildren() {
+ if (testSpec.expectedChildren != null) {
+ final DataType dataType = testSpec.typeFactory.createDataType(testSpec.abstractDataType);
+ assertThat(dataType.getChildren(), equalTo(testSpec.expectedChildren));
+ }
+ }
+
+ @Test
public void testUnresolvedString() {
if (testSpec.expectedUnresolvedString != null) {
assertThat(testSpec.abstractDataType.toString(), equalTo(testSpec.expectedUnresolvedString));
@@ -406,6 +422,8 @@ public class DataTypesTest {
private @Nullable Class<?> expectedConversionClass;
+ private @Nullable List<DataType> expectedChildren;
+
private @Nullable String expectedUnresolvedString;
private @Nullable DataType expectedResolvedDataType;
@@ -432,6 +450,11 @@ public class DataTypesTest {
return this;
}
+ TestSpec expectChildren(DataType... expectedChildren) {
+ this.expectedChildren = Arrays.asList(expectedChildren);
+ return this;
+ }
+
TestSpec expectUnresolvedString(String expectedUnresolvedString) {
this.expectedUnresolvedString = expectedUnresolvedString;
return this;