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 118d121054c534126cfab5d9b65a01a298038ffa
Author: Timo Walther <twal...@apache.org>
AuthorDate: Wed Jul 31 17:32:26 2019 +0200

    [FLINK-10257][table-common] Generalize variable strings for varying lengths
    
    The Blink planner generalizes multiple CHAR literals into VARCHAR. It seems
    likely that we will adopt this behavior in the future to prevent unwanted
    side-effects for users. This PR updates the existing type generalization 
classes.
---
 .../logical/utils/LogicalTypeGeneralization.java     | 15 +++++++++++++--
 .../table/types/LogicalTypeGeneralizationTest.java   | 20 +++++++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeGeneralization.java
 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeGeneralization.java
index 18ffeb3..c9d6e25 100644
--- 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeGeneralization.java
+++ 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeGeneralization.java
@@ -76,6 +76,8 @@ import static 
org.apache.flink.table.types.logical.LogicalTypeFamily.TIME;
 import static org.apache.flink.table.types.logical.LogicalTypeFamily.TIMESTAMP;
 import static org.apache.flink.table.types.logical.LogicalTypeRoot.ANY;
 import static org.apache.flink.table.types.logical.LogicalTypeRoot.ARRAY;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.BINARY;
+import static org.apache.flink.table.types.logical.LogicalTypeRoot.CHAR;
 import static org.apache.flink.table.types.logical.LogicalTypeRoot.DATE;
 import static org.apache.flink.table.types.logical.LogicalTypeRoot.DECIMAL;
 import static org.apache.flink.table.types.logical.LogicalTypeRoot.DOUBLE;
@@ -266,10 +268,19 @@ public final class LogicalTypeGeneralization {
                                final int length = combineLength(resultType, 
type);
 
                                if (hasRoot(resultType, VARCHAR) || 
hasRoot(resultType, VARBINARY)) {
-                                       // for variable length type we are done 
here
+                                       // variable length types remain 
variable length types
                                        resultType = 
createStringType(resultType.getTypeRoot(), length);
+                               } else if (getLength(resultType) != 
getLength(type)) {
+                                       // for different fixed lengths
+                                       // this is different from the SQL 
standard but prevents whitespace
+                                       // padding/modification of strings
+                                       if (hasRoot(resultType, CHAR)) {
+                                               resultType = 
createStringType(VARCHAR, length);
+                                       } else if (hasRoot(resultType, BINARY)) 
{
+                                               resultType = 
createStringType(VARBINARY, length);
+                                       }
                                } else {
-                                       // for mixed fixed/variable or 
fixed/fixed lengths
+                                       // for same type with same length
                                        resultType = createStringType(typeRoot, 
length);
                                }
                        }
diff --git 
a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeGeneralizationTest.java
 
b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeGeneralizationTest.java
index 44209e7..d860aed 100644
--- 
a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeGeneralizationTest.java
+++ 
b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeGeneralizationTest.java
@@ -86,6 +86,12 @@ public class LogicalTypeGeneralizationTest {
                                        null
                                },
 
+                               // incompatible types
+                               {
+                                       Arrays.asList(new BinaryType(), new 
VarCharType(23)),
+                                       null
+                               },
+
                                // NOT NULL types
                                {
                                        Arrays.asList(new IntType(false), new 
IntType(false)),
@@ -144,10 +150,16 @@ public class LogicalTypeGeneralizationTest {
                                        RowType.of(new BigIntType(), new 
IntType(), new BigIntType())
                                },
 
+                               // CHAR types of same length
+                               {
+                                       Arrays.asList(new CharType(2), new 
CharType(2)),
+                                       new CharType(2)
+                               },
+
                                // CHAR types of different length
                                {
                                        Arrays.asList(new CharType(2), new 
CharType(4)),
-                                       new CharType(4)
+                                       new VarCharType(4)
                                },
 
                                // VARCHAR types of different length
@@ -168,6 +180,12 @@ public class LogicalTypeGeneralizationTest {
                                        new VarCharType(7)
                                },
 
+                               // BINARY types of different length
+                               {
+                                       Arrays.asList(new BinaryType(2), new 
BinaryType(4)),
+                                       new VarBinaryType(4)
+                               },
+
                                // mixed BINARY and VARBINARY types
                                {
                                        Arrays.asList(new BinaryType(5), new 
VarBinaryType(2), new VarBinaryType(7)),

Reply via email to