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 2019/05/16 08:54:55 UTC
[flink] branch master updated: [hotfix][table-common] Summarize
VARCHAR(Int.MAX) to STRING
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
The following commit(s) were added to refs/heads/master by this push:
new 6a293ee [hotfix][table-common] Summarize VARCHAR(Int.MAX) to STRING
6a293ee is described below
commit 6a293ee5aeadae629bac0048931539a073a17687
Author: Timo Walther <tw...@apache.org>
AuthorDate: Tue May 14 16:14:46 2019 +0200
[hotfix][table-common] Summarize VARCHAR(Int.MAX) to STRING
---
.../org/apache/flink/table/types/logical/VarCharType.java | 13 ++++++++++++-
.../java/org/apache/flink/table/types/LogicalTypesTest.java | 13 +++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/VarCharType.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/VarCharType.java
index 4092558..1e1f04c 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/VarCharType.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/VarCharType.java
@@ -31,7 +31,8 @@ import java.util.Set;
*
* <p>The serialized string representation is {@code VARCHAR(n)} where {@code n} is the maximum
* number of code points. {@code n} must have a value between 1 and {@link Integer#MAX_VALUE} (both
- * inclusive). If no length is specified, {@code n} is equal to 1.
+ * inclusive). If no length is specified, {@code n} is equal to 1. {@code STRING} is a synonym for
+ * {@code VARCHAR(2147483647)}.
*
* <p>A conversion from and to {@code byte[]} assumes UTF-8 encoding.
*/
@@ -46,6 +47,8 @@ public final class VarCharType extends LogicalType {
private static final String FORMAT = "VARCHAR(%d)";
+ private static final String MAX_FORMAT = "STRING";
+
private static final Set<String> INPUT_OUTPUT_CONVERSION = conversionSet(
String.class.getName(),
byte[].class.getName(),
@@ -90,6 +93,14 @@ public final class VarCharType extends LogicalType {
}
@Override
+ public String asSummaryString() {
+ if (length == MAX_LENGTH) {
+ return withNullability(MAX_FORMAT);
+ }
+ return withNullability(FORMAT, length);
+ }
+
+ @Override
public boolean supportsInputConversion(Class<?> clazz) {
return INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
}
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
index 52f2778..e9ad9c9 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypesTest.java
@@ -104,6 +104,19 @@ public class LogicalTypesTest {
}
@Test
+ public void testVarCharTypeWithMaximumLength() {
+ testAll(
+ new VarCharType(Integer.MAX_VALUE),
+ "VARCHAR(2147483647)",
+ "STRING",
+ new Class[]{String.class, byte[].class},
+ new Class[]{String.class, byte[].class},
+ new LogicalType[]{},
+ new VarCharType(12)
+ );
+ }
+
+ @Test
public void testBooleanType() {
testAll(
new BooleanType(),