/** * Create a new {@code MapStateDescriptor} with the given name and the given type information. * * @param name The name of the {@code MapStateDescriptor}. * @param keyTypeInfo The type information for the keys in the state. * @param valueTypeInfo The type information for the values in the state. */ public MapStateDescriptor(String name, TypeInformation<UK> keyTypeInfo, TypeInformation<UV> valueTypeInfo) { super(name, new MapTypeInfo<>(keyTypeInfo, valueTypeInfo), null); }
/** * Create a new {@code MapStateDescriptor} with the given name and the given type information. * * <p>If this constructor fails (because it is not possible to describe the type via a class), * consider using the {@link #MapStateDescriptor(String, TypeInformation, TypeInformation)} constructor. * * @param name The name of the {@code MapStateDescriptor}. * @param keyClass The class of the type of keys in the state. * @param valueClass The class of the type of values in the state. */ public MapStateDescriptor(String name, Class<UK> keyClass, Class<UV> valueClass) { super(name, new MapTypeInfo<>(keyClass, valueClass), null); }
/** * Returns type information for a Java {@link java.util.Map}. A map must not be null. Null values * in keys are not supported. An entry's value can be null. * * <p>By default, maps are untyped and treated as a generic type in Flink; therefore, it is useful * to pass type information whenever a map is used. * * <p><strong>Note:</strong> Flink does not preserve the concrete {@link Map} type. It converts a map into {@link HashMap} when * copying or deserializing. * * @param keyType type information for the map's keys * @param valueType type information for the map's values */ public static <K, V> TypeInformation<Map<K, V>> MAP(TypeInformation<K> keyType, TypeInformation<V> valueType) { return new MapTypeInfo<>(keyType, valueType); }
@Override protected MapTypeInfo<?, ?>[] getTestData() { return new MapTypeInfo<?, ?>[] { new MapTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.INT_TYPE_INFO), new MapTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO), new MapTypeInfo<>(String.class, Boolean.class) }; } }
TypeInformation<?> keyType = schemaToTypeInfo(keySchema); TypeInformation<?> valType = schemaToTypeInfo(valSchema); return new MapTypeInfo<>(keyType, valType); case UNION: throw new UnsupportedOperationException("UNION type is not supported yet.");
@Test public void testMap() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config()); List<Tuple2<Integer, Map<String, String>>> rows = new ArrayList<>(); rows.add(new Tuple2<>(1, Collections.singletonMap("foo", "bar"))); rows.add(new Tuple2<>(2, Collections.singletonMap("foo", "spam"))); TypeInformation<Tuple2<Integer, Map<String, String>>> ty = new TupleTypeInfo<>( BasicTypeInfo.INT_TYPE_INFO, new MapTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO)); DataSet<Tuple2<Integer, Map<String, String>>> ds1 = env.fromCollection(rows, ty); tableEnv.registerDataSet("t1", ds1, "a, b"); String sqlQuery = "SELECT b['foo'] FROM t1"; Table result = tableEnv.sqlQuery(sqlQuery); DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class); List<Row> results = resultSet.collect(); String expected = "bar\n" + "spam\n"; compareResultAsText(results, expected); } }
/** * Create a new {@code MapStateDescriptor} with the given name and the given type information. * * @param name The name of the {@code MapStateDescriptor}. * @param keyTypeInfo The type information for the keys in the state. * @param valueTypeInfo The type information for the values in the state. */ public MapStateDescriptor(String name, TypeInformation<UK> keyTypeInfo, TypeInformation<UV> valueTypeInfo) { super(name, new MapTypeInfo<>(keyTypeInfo, valueTypeInfo), null); }
/** * Create a new {@code MapStateDescriptor} with the given name and the given type information. * * @param name The name of the {@code MapStateDescriptor}. * @param keyTypeInfo The type information for the keys in the state. * @param valueTypeInfo The type information for the values in the state. */ public MapStateDescriptor(String name, TypeInformation<UK> keyTypeInfo, TypeInformation<UV> valueTypeInfo) { super(name, new MapTypeInfo<>(keyTypeInfo, valueTypeInfo), null); }
/** * Create a new {@code MapStateDescriptor} with the given name and the given type information. * * <p>If this constructor fails (because it is not possible to describe the type via a class), * consider using the {@link #MapStateDescriptor(String, TypeInformation, TypeInformation)} constructor. * * @param name The name of the {@code MapStateDescriptor}. * @param keyClass The class of the type of keys in the state. * @param valueClass The class of the type of values in the state. */ public MapStateDescriptor(String name, Class<UK> keyClass, Class<UV> valueClass) { super(name, new MapTypeInfo<>(keyClass, valueClass), null); }
/** * Create a new {@code MapStateDescriptor} with the given name and the given type information. * * <p>If this constructor fails (because it is not possible to describe the type via a class), * consider using the {@link #MapStateDescriptor(String, TypeInformation, TypeInformation)} constructor. * * @param name The name of the {@code MapStateDescriptor}. * @param keyClass The class of the type of keys in the state. * @param valueClass The class of the type of values in the state. */ public MapStateDescriptor(String name, Class<UK> keyClass, Class<UV> valueClass) { super(name, new MapTypeInfo<>(keyClass, valueClass), null); }
/** * Returns type information for a Java {@link java.util.Map}. A map must not be null. Null values * in keys are not supported. An entry's value can be null. * * <p>By default, maps are untyped and treated as a generic type in Flink; therefore, it is useful * to pass type information whenever a map is used. * * <p><strong>Note:</strong> Flink does not preserve the concrete {@link Map} type. It converts a map into {@link HashMap} when * copying or deserializing. * * @param keyType type information for the map's keys * @param valueType type information for the map's values */ public static <K, V> TypeInformation<Map<K, V>> MAP(TypeInformation<K> keyType, TypeInformation<V> valueType) { return new MapTypeInfo<>(keyType, valueType); }
/** * Returns type information for a Java {@link java.util.Map}. A map must not be null. Null values * in keys are not supported. An entry's value can be null. * * <p>By default, maps are untyped and treated as a generic type in Flink; therefore, it is useful * to pass type information whenever a map is used. * * <p><strong>Note:</strong> Flink does not preserve the concrete {@link Map} type. It converts a map into {@link HashMap} when * copying or deserializing. * * @param keyType type information for the map's keys * @param valueType type information for the map's values */ public static <K, V> TypeInformation<Map<K, V>> MAP(TypeInformation<K> keyType, TypeInformation<V> valueType) { return new MapTypeInfo<>(keyType, valueType); }