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/10/16 15:45:08 UTC

[flink] branch master updated (ff249bc -> 94b444e)

This is an automated email from the ASF dual-hosted git repository.

twalthr pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git.


    from ff249bc  [FLINK-12979][formats] Allow empty line delimiter for CsvRowSerializationSchema
     new 8e81fc2  [FLINK-14409][table] Fix MapType and MultisetType doesn't accept any subclass of java.util.Map for inputs
     new 94b444e  [hotfix][docs] Add MAP data type docs

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/dev/table/types.md                            | 38 ++++++++++++++++++++++
 .../apache/flink/table/types/logical/MapType.java  |  3 ++
 .../flink/table/types/logical/MultisetType.java    |  3 ++
 .../flink/table/expressions/ExpressionTest.java    | 19 +++++++++++
 .../apache/flink/table/types/LogicalTypesTest.java |  8 +++--
 5 files changed, 68 insertions(+), 3 deletions(-)


[flink] 02/02: [hotfix][docs] Add MAP data type docs

Posted by tw...@apache.org.
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 94b444e3ec128e7a4daaaf4a49ceeeca9d886f1d
Author: Timo Walther <tw...@apache.org>
AuthorDate: Wed Oct 16 17:33:39 2019 +0200

    [hotfix][docs] Add MAP data type docs
---
 docs/dev/table/types.md | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/docs/dev/table/types.md b/docs/dev/table/types.md
index 13139ff..8a913bc 100644
--- a/docs/dev/table/types.md
+++ b/docs/dev/table/types.md
@@ -1005,6 +1005,43 @@ equivalent to `ARRAY<INT>`.
 |:----------|:-----:|:------:|:----------------------------------|
 |*t*`[]`    | (X)   | (X)    | Depends on the subtype. *Default* |
 
+#### `MAP`
+
+Data type of an associative array that maps keys (including `NULL`) to values (including `NULL`). A map
+cannot contain duplicate keys; each key can map to at most one value.
+
+There is no restriction of element types; it is the responsibility of the user to ensure uniqueness.
+
+The map type is an extension to the SQL standard.
+
+**Declaration**
+
+<div class="codetabs" markdown="1">
+
+<div data-lang="SQL" markdown="1">
+{% highlight text %}
+MAP<kt, vt>
+{% endhighlight %}
+</div>
+
+<div data-lang="Java/Scala" markdown="1">
+{% highlight java %}
+DataTypes.MAP(kt, vt)
+{% endhighlight %}
+</div>
+
+</div>
+
+The type can be declared using `MAP<kt, vt>` where `kt` is the data type of the key elements
+and `vt` is the data type of the value elements.
+
+**Bridging to JVM Types**
+
+| Java Type                             | Input | Output | Remarks   |
+|:--------------------------------------|:-----:|:------:|:----------|
+| `java.util.Map<kt, vt>`               | X     | X      | *Default* |
+| *subclass* of `java.util.Map<kt, vt>` | X     |        |           |
+
 #### `MULTISET`
 
 Data type of a multiset (=bag). Unlike a set, it allows for multiple instances for each of its
@@ -1042,6 +1079,7 @@ equivalent to `MULTISET<INT>`.
 | Java Type                            | Input | Output | Remarks                                                  |
 |:-------------------------------------|:-----:|:------:|:---------------------------------------------------------|
 |`java.util.Map<t, java.lang.Integer>` | X     | X      | Assigns each value to an integer multiplicity. *Default* |
+| *subclass* of `java.util.Map<kt, java.lang.Integer>` | X     |        | Assigns each value to an integer multiplicity. |
 
 #### `ROW`
 


[flink] 01/02: [FLINK-14409][table] Fix MapType and MultisetType doesn't accept any subclass of java.util.Map for inputs

Posted by tw...@apache.org.
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 8e81fc265d95f634401269b2acf9a4e80c0c1044
Author: Jark Wu <im...@gmail.com>
AuthorDate: Wed Oct 16 18:24:01 2019 +0800

    [FLINK-14409][table] Fix MapType and MultisetType doesn't accept any subclass of java.util.Map for inputs
    
    This closes #9913.
---
 .../org/apache/flink/table/types/logical/MapType.java |  3 +++
 .../flink/table/types/logical/MultisetType.java       |  3 +++
 .../flink/table/expressions/ExpressionTest.java       | 19 +++++++++++++++++++
 .../apache/flink/table/types/LogicalTypesTest.java    |  8 +++++---
 4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MapType.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MapType.java
index 4d77265..cd0ab71 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MapType.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MapType.java
@@ -91,6 +91,9 @@ public final class MapType extends LogicalType {
 
 	@Override
 	public boolean supportsInputConversion(Class<?> clazz) {
+		if (Map.class.isAssignableFrom(clazz)) {
+			return true;
+		}
 		return INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
 	}
 
diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MultisetType.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MultisetType.java
index 54aa7e4..cd4b7ee 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MultisetType.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/MultisetType.java
@@ -82,6 +82,9 @@ public final class MultisetType extends LogicalType {
 
 	@Override
 	public boolean supportsInputConversion(Class<?> clazz) {
+		if (Map.class.isAssignableFrom(clazz)) {
+			return true;
+		}
 		return INPUT_OUTPUT_CONVERSION.contains(clazz.getName());
 	}
 
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/expressions/ExpressionTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/expressions/ExpressionTest.java
index eb80d25..c9d265b 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/expressions/ExpressionTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/expressions/ExpressionTest.java
@@ -30,6 +30,8 @@ import org.junit.rules.ExpectedException;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.singletonList;
@@ -86,6 +88,23 @@ public class ExpressionTest {
 					new String[][]{null, null, {"1", "2", "3", "Dog's"}},
 					DataTypes.ARRAY(DataTypes.ARRAY(DataTypes.STRING())))
 				.toString());
+
+		final Map<String, Integer> map = new HashMap<>();
+		map.put("key1", 1);
+		map.put("key2", 2);
+		map.put("key3", 3);
+		assertEquals(
+			"{key1=1, key2=2, key3=3}",
+			new ValueLiteralExpression(
+					map,
+					DataTypes.MAP(DataTypes.STRING(), DataTypes.INT()))
+				.toString());
+		assertEquals(
+			"{key1=1, key2=2, key3=3}",
+			new ValueLiteralExpression(
+					map,
+					DataTypes.MULTISET(DataTypes.STRING()))
+				.toString());
 	}
 
 	@Test
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 6bbbc80..5ce9937 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
@@ -68,7 +68,9 @@ import org.junit.Test;
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.TreeMap;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -426,7 +428,7 @@ public class LogicalTypesTest {
 			new MultisetType(new TimestampType()),
 			"MULTISET<TIMESTAMP(6)>",
 			"MULTISET<TIMESTAMP(6)>",
-			new Class[]{Map.class},
+			new Class[]{Map.class, HashMap.class, TreeMap.class},
 			new Class[]{Map.class},
 			new LogicalType[]{new TimestampType()},
 			new MultisetType(new SmallIntType())
@@ -436,7 +438,7 @@ public class LogicalTypesTest {
 			new MultisetType(new MultisetType(new TimestampType())),
 			"MULTISET<MULTISET<TIMESTAMP(6)>>",
 			"MULTISET<MULTISET<TIMESTAMP(6)>>",
-			new Class[]{Map.class},
+			new Class[]{Map.class, HashMap.class, TreeMap.class},
 			new Class[]{Map.class},
 			new LogicalType[]{new MultisetType(new TimestampType())},
 			new MultisetType(new MultisetType(new SmallIntType()))
@@ -449,7 +451,7 @@ public class LogicalTypesTest {
 			new MapType(new VarCharType(20), new TimestampType()),
 			"MAP<VARCHAR(20), TIMESTAMP(6)>",
 			"MAP<VARCHAR(20), TIMESTAMP(6)>",
-			new Class[]{Map.class},
+			new Class[]{Map.class, HashMap.class, TreeMap.class},
 			new Class[]{Map.class},
 			new LogicalType[]{new VarCharType(20), new TimestampType()},
 			new MapType(new VarCharType(99), new TimestampType())