org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo Java Examples
The following examples show how to use
org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTupleWithPrimitiveArray() { RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>> function = new RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>>() { private static final long serialVersionUID = 1L; @Override public Tuple9<int[], double[], long[], byte[], char[], float[], short[], boolean[], String[]> map(Integer value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.INT_TYPE_INFO); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(2)); Assert.assertEquals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(3)); Assert.assertEquals(PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(4)); Assert.assertEquals(PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(5)); Assert.assertEquals(PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(6)); Assert.assertEquals(PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(7)); Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, tti.getTypeAt(8)); }
Example #2
Source File: JsonRowDeserializationSchema.java From flink with Apache License 2.0 | 6 votes |
private Optional<DeserializationRuntimeConverter> createContainerConverter(TypeInformation<?> typeInfo) { if (typeInfo instanceof RowTypeInfo) { return Optional.of(createRowConverter((RowTypeInfo) typeInfo)); } else if (typeInfo instanceof ObjectArrayTypeInfo) { return Optional.of(createObjectArrayConverter(((ObjectArrayTypeInfo) typeInfo).getComponentInfo())); } else if (typeInfo instanceof BasicArrayTypeInfo) { return Optional.of(createObjectArrayConverter(((BasicArrayTypeInfo) typeInfo).getComponentInfo())); } else if (isPrimitiveByteArray(typeInfo)) { return Optional.of(createByteArrayConverter()); } else if (typeInfo instanceof MapTypeInfo) { MapTypeInfo<?, ?> mapTypeInfo = (MapTypeInfo<?, ?>) typeInfo; return Optional.of(createMapConverter(mapTypeInfo.getKeyTypeInfo(), mapTypeInfo.getValueTypeInfo())); } else { return Optional.empty(); } }
Example #3
Source File: ArrayKeySelectorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testObjectArrays() { try { String[] array1 = { "a", "b", "c", "d", "e" }; String[] array2 = { "v", "w", "x", "y", "z" }; KeySelectorUtil.ArrayKeySelector<String[]> singleFieldSelector = KeySelectorUtil.getSelectorForArray(new int[] {1}, BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO); assertEquals(new Tuple1<>("b"), singleFieldSelector.getKey(array1)); assertEquals(new Tuple1<>("w"), singleFieldSelector.getKey(array2)); KeySelectorUtil.ArrayKeySelector<String[]> twoFieldsSelector = KeySelectorUtil.getSelectorForArray(new int[] {3, 0}, BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO); assertEquals(new Tuple2<>("d", "a"), twoFieldsSelector.getKey(array1)); assertEquals(new Tuple2<>("y", "v"), twoFieldsSelector.getKey(array2)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #4
Source File: ArrayKeySelectorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testObjectArrays() { try { String[] array1 = { "a", "b", "c", "d", "e" }; String[] array2 = { "v", "w", "x", "y", "z" }; KeySelectorUtil.ArrayKeySelector<String[]> singleFieldSelector = KeySelectorUtil.getSelectorForArray(new int[] {1}, BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO); assertEquals(new Tuple1<>("b"), singleFieldSelector.getKey(array1)); assertEquals(new Tuple1<>("w"), singleFieldSelector.getKey(array2)); KeySelectorUtil.ArrayKeySelector<String[]> twoFieldsSelector = KeySelectorUtil.getSelectorForArray(new int[] {3, 0}, BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO); assertEquals(new Tuple2<>("d", "a"), twoFieldsSelector.getKey(array1)); assertEquals(new Tuple2<>("y", "v"), twoFieldsSelector.getKey(array2)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #5
Source File: DataStreamTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testTupleNestedArrayKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "test-test")); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple2<Integer[], String>>( BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy(new KeySelector<Tuple2<Integer[], String>, Tuple2<Integer[], String>>() { @Override public Tuple2<Integer[], String> getKey(Tuple2<Integer[], String> value) throws Exception { return value; } }); }
Example #6
Source File: KeySelectorUtil.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static <X> ArrayKeySelector<X> getSelectorForArray(int[] positions, TypeInformation<X> typeInfo) { if (positions == null || positions.length == 0 || positions.length > Tuple.MAX_ARITY) { throw new IllegalArgumentException("Array keys must have between 1 and " + Tuple.MAX_ARITY + " fields."); } TypeInformation<?> componentType; if (typeInfo instanceof BasicArrayTypeInfo) { BasicArrayTypeInfo<X, ?> arrayInfo = (BasicArrayTypeInfo<X, ?>) typeInfo; componentType = arrayInfo.getComponentInfo(); } else if (typeInfo instanceof PrimitiveArrayTypeInfo) { PrimitiveArrayTypeInfo<X> arrayType = (PrimitiveArrayTypeInfo<X>) typeInfo; componentType = arrayType.getComponentType(); } else { throw new IllegalArgumentException("This method only supports arrays of primitives and boxed primitives."); } TypeInformation<?>[] primitiveInfos = new TypeInformation<?>[positions.length]; Arrays.fill(primitiveInfos, componentType); return new ArrayKeySelector<>(positions, new TupleTypeInfo<>(primitiveInfos)); }
Example #7
Source File: DataStreamTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTupleNestedArrayKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "test-test")); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple2<Integer[], String>>( BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy(new KeySelector<Tuple2<Integer[], String>, Tuple2<Integer[], String>>() { @Override public Tuple2<Integer[], String> getKey(Tuple2<Integer[], String> value) throws Exception { return value; } }); }
Example #8
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTupleWithPrimitiveArray() { RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>> function = new RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>>() { private static final long serialVersionUID = 1L; @Override public Tuple9<int[], double[], long[], byte[], char[], float[], short[], boolean[], String[]> map(Integer value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.INT_TYPE_INFO); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(2)); Assert.assertEquals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(3)); Assert.assertEquals(PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(4)); Assert.assertEquals(PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(5)); Assert.assertEquals(PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(6)); Assert.assertEquals(PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(7)); Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, tti.getTypeAt(8)); }
Example #9
Source File: TypeExtractorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testTupleWithPrimitiveArray() { RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>> function = new RichMapFunction<Integer, Tuple9<int[],double[],long[],byte[],char[],float[],short[], boolean[], String[]>>() { private static final long serialVersionUID = 1L; @Override public Tuple9<int[], double[], long[], byte[], char[], float[], short[], boolean[], String[]> map(Integer value) throws Exception { return null; } }; TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicTypeInfo.INT_TYPE_INFO); TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti; Assert.assertEquals(PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(0)); Assert.assertEquals(PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(1)); Assert.assertEquals(PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(2)); Assert.assertEquals(PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(3)); Assert.assertEquals(PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(4)); Assert.assertEquals(PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(5)); Assert.assertEquals(PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(6)); Assert.assertEquals(PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO, tti.getTypeAt(7)); Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, tti.getTypeAt(8)); }
Example #10
Source File: KeySelectorUtil.java From flink with Apache License 2.0 | 6 votes |
public static <X> ArrayKeySelector<X> getSelectorForArray(int[] positions, TypeInformation<X> typeInfo) { if (positions == null || positions.length == 0 || positions.length > Tuple.MAX_ARITY) { throw new IllegalArgumentException("Array keys must have between 1 and " + Tuple.MAX_ARITY + " fields."); } TypeInformation<?> componentType; if (typeInfo instanceof BasicArrayTypeInfo) { BasicArrayTypeInfo<X, ?> arrayInfo = (BasicArrayTypeInfo<X, ?>) typeInfo; componentType = arrayInfo.getComponentInfo(); } else if (typeInfo instanceof PrimitiveArrayTypeInfo) { PrimitiveArrayTypeInfo<X> arrayType = (PrimitiveArrayTypeInfo<X>) typeInfo; componentType = arrayType.getComponentType(); } else { throw new IllegalArgumentException("This method only supports arrays of primitives and boxed primitives."); } TypeInformation<?>[] primitiveInfos = new TypeInformation<?>[positions.length]; Arrays.fill(primitiveInfos, componentType); return new ArrayKeySelector<>(positions, new TupleTypeInfo<>(primitiveInfos)); }
Example #11
Source File: KeySelectorUtil.java From flink with Apache License 2.0 | 6 votes |
public static <X> ArrayKeySelector<X> getSelectorForArray(int[] positions, TypeInformation<X> typeInfo) { if (positions == null || positions.length == 0 || positions.length > Tuple.MAX_ARITY) { throw new IllegalArgumentException("Array keys must have between 1 and " + Tuple.MAX_ARITY + " fields."); } TypeInformation<?> componentType; if (typeInfo instanceof BasicArrayTypeInfo) { BasicArrayTypeInfo<X, ?> arrayInfo = (BasicArrayTypeInfo<X, ?>) typeInfo; componentType = arrayInfo.getComponentInfo(); } else if (typeInfo instanceof PrimitiveArrayTypeInfo) { PrimitiveArrayTypeInfo<X> arrayType = (PrimitiveArrayTypeInfo<X>) typeInfo; componentType = arrayType.getComponentType(); } else { throw new IllegalArgumentException("This method only supports arrays of primitives and boxed primitives."); } TypeInformation<?>[] primitiveInfos = new TypeInformation<?>[positions.length]; Arrays.fill(primitiveInfos, componentType); return new ArrayKeySelector<>(positions, new TupleTypeInfo<>(primitiveInfos)); }
Example #12
Source File: DataStreamTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTupleNestedArrayKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "test-test")); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple2<Integer[], String>>( BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy(new KeySelector<Tuple2<Integer[], String>, Tuple2<Integer[], String>>() { @Override public Tuple2<Integer[], String> getKey(Tuple2<Integer[], String> value) throws Exception { return value; } }); }
Example #13
Source File: ArrayKeySelectorTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testObjectArrays() { try { String[] array1 = { "a", "b", "c", "d", "e" }; String[] array2 = { "v", "w", "x", "y", "z" }; KeySelectorUtil.ArrayKeySelector<String[]> singleFieldSelector = KeySelectorUtil.getSelectorForArray(new int[] {1}, BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO); assertEquals(new Tuple1<>("b"), singleFieldSelector.getKey(array1)); assertEquals(new Tuple1<>("w"), singleFieldSelector.getKey(array2)); KeySelectorUtil.ArrayKeySelector<String[]> twoFieldsSelector = KeySelectorUtil.getSelectorForArray(new int[] {3, 0}, BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO); assertEquals(new Tuple2<>("d", "a"), twoFieldsSelector.getKey(array1)); assertEquals(new Tuple2<>("y", "v"), twoFieldsSelector.getKey(array2)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #14
Source File: DataStreamTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicArrayKeyRejection() { KeySelector<Tuple2<Integer[], String>, Integer[]> keySelector = new KeySelector<Tuple2<Integer[], String>, Integer[]>() { @Override public Integer[] getKey(Tuple2<Integer[], String> value) throws Exception { return value.f0; } }; testKeyRejection(keySelector, BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO); }
Example #15
Source File: FieldAccessorTest.java From flink with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testArray() { int[] a = new int[]{3, 5}; FieldAccessor<int[], Integer> fieldAccessor = (FieldAccessor<int[], Integer>) (Object) FieldAccessorFactory.getAccessor(PrimitiveArrayTypeInfo.getInfoFor(a.getClass()), 1, null); assertEquals(Integer.class, fieldAccessor.getFieldType().getTypeClass()); assertEquals((Integer) a[1], fieldAccessor.get(a)); a = fieldAccessor.set(a, 6); assertEquals((Integer) a[1], fieldAccessor.get(a)); Integer[] b = new Integer[]{3, 5}; FieldAccessor<Integer[], Integer> fieldAccessor2 = (FieldAccessor<Integer[], Integer>) (Object) FieldAccessorFactory.getAccessor(BasicArrayTypeInfo.getInfoFor(b.getClass()), 1, null); assertEquals(Integer.class, fieldAccessor2.getFieldType().getTypeClass()); assertEquals(b[1], fieldAccessor2.get(b)); b = fieldAccessor2.set(b, 6); assertEquals(b[1], fieldAccessor2.get(b)); }
Example #16
Source File: CsvRowSchemaConverter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Convert {@link TypeInformation} to {@link CsvSchema.ColumnType} based on Jackson's categories. */ private static CsvSchema.ColumnType convertType(String fieldName, TypeInformation<?> info) { if (STRING_TYPES.contains(info)) { return CsvSchema.ColumnType.STRING; } else if (NUMBER_TYPES.contains(info)) { return CsvSchema.ColumnType.NUMBER; } else if (BOOLEAN_TYPES.contains(info)) { return CsvSchema.ColumnType.BOOLEAN; } else if (info instanceof ObjectArrayTypeInfo) { validateNestedField(fieldName, ((ObjectArrayTypeInfo) info).getComponentInfo()); return CsvSchema.ColumnType.ARRAY; } else if (info instanceof BasicArrayTypeInfo) { validateNestedField(fieldName, ((BasicArrayTypeInfo) info).getComponentInfo()); return CsvSchema.ColumnType.ARRAY; } else if (info instanceof RowTypeInfo) { final TypeInformation<?>[] types = ((RowTypeInfo) info).getFieldTypes(); for (TypeInformation<?> type : types) { validateNestedField(fieldName, type); } return CsvSchema.ColumnType.ARRAY; } else if (info instanceof PrimitiveArrayTypeInfo && ((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) { return CsvSchema.ColumnType.STRING; } else { throw new IllegalArgumentException( "Unsupported type information '" + info.toString() + "' for field '" + fieldName + "'."); } }
Example #17
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 5 votes |
public static DataType toDataType(TypeInformation<?> typeInfo) { // time indicators first as their hashCode/equals is shared with those of regular timestamps if (typeInfo instanceof TimeIndicatorTypeInfo) { return convertToTimeAttributeType((TimeIndicatorTypeInfo) typeInfo); } final DataType foundDataType = typeInfoDataTypeMap.get(typeInfo); if (foundDataType != null) { return foundDataType; } if (typeInfo instanceof RowTypeInfo) { return convertToRowType((RowTypeInfo) typeInfo); } else if (typeInfo instanceof ObjectArrayTypeInfo) { return convertToArrayType( typeInfo.getTypeClass(), ((ObjectArrayTypeInfo) typeInfo).getComponentInfo()); } else if (typeInfo instanceof BasicArrayTypeInfo) { return createLegacyType(LogicalTypeRoot.ARRAY, typeInfo); } else if (typeInfo instanceof MultisetTypeInfo) { return convertToMultisetType(((MultisetTypeInfo) typeInfo).getElementTypeInfo()); } else if (typeInfo instanceof MapTypeInfo) { return convertToMapType((MapTypeInfo) typeInfo); } else if (typeInfo instanceof CompositeType) { return createLegacyType(LogicalTypeRoot.STRUCTURED_TYPE, typeInfo); } return createLegacyType(LogicalTypeRoot.RAW, typeInfo); }
Example #18
Source File: ParquetSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
private static TypeInformation<?> convertParquetPrimitiveListToFlinkArray(Type type) { // Backward-compatibility element group doesn't exist also allowed TypeInformation<?> flinkType = convertParquetTypeToTypeInfo(type); if (flinkType.isBasicType()) { return BasicArrayTypeInfo.getInfoFor(Array.newInstance(flinkType.getTypeClass(), 0).getClass()); } else { // flinkType here can be either SqlTimeTypeInfo or BasicTypeInfo.BIG_DEC_TYPE_INFO, // So it should be converted to ObjectArrayTypeInfo return ObjectArrayTypeInfo.getInfoFor(flinkType); } }
Example #19
Source File: CsvRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
/** * Convert {@link TypeInformation} to {@link CsvSchema.ColumnType} based on Jackson's categories. */ private static CsvSchema.ColumnType convertType(String fieldName, TypeInformation<?> info) { if (STRING_TYPES.contains(info)) { return CsvSchema.ColumnType.STRING; } else if (NUMBER_TYPES.contains(info)) { return CsvSchema.ColumnType.NUMBER; } else if (BOOLEAN_TYPES.contains(info)) { return CsvSchema.ColumnType.BOOLEAN; } else if (info instanceof ObjectArrayTypeInfo) { validateNestedField(fieldName, ((ObjectArrayTypeInfo) info).getComponentInfo()); return CsvSchema.ColumnType.ARRAY; } else if (info instanceof BasicArrayTypeInfo) { validateNestedField(fieldName, ((BasicArrayTypeInfo) info).getComponentInfo()); return CsvSchema.ColumnType.ARRAY; } else if (info instanceof RowTypeInfo) { final TypeInformation<?>[] types = ((RowTypeInfo) info).getFieldTypes(); for (TypeInformation<?> type : types) { validateNestedField(fieldName, type); } return CsvSchema.ColumnType.ARRAY; } else if (info instanceof PrimitiveArrayTypeInfo && ((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) { return CsvSchema.ColumnType.STRING; } else { throw new IllegalArgumentException( "Unsupported type information '" + info.toString() + "' for field '" + fieldName + "'."); } }
Example #20
Source File: JsonRowSerializationSchema.java From flink with Apache License 2.0 | 5 votes |
private Optional<SerializationRuntimeConverter> createContainerConverter(TypeInformation<?> typeInfo) { if (typeInfo instanceof RowTypeInfo) { return Optional.of(createRowConverter((RowTypeInfo) typeInfo)); } else if (typeInfo instanceof ObjectArrayTypeInfo) { return Optional.of(createObjectArrayConverter(((ObjectArrayTypeInfo) typeInfo).getComponentInfo())); } else if (typeInfo instanceof BasicArrayTypeInfo) { return Optional.of(createObjectArrayConverter(((BasicArrayTypeInfo) typeInfo).getComponentInfo())); } else if (isPrimitiveByteArray(typeInfo)) { return Optional.of((mapper, reuse, object) -> mapper.getNodeFactory().binaryNode((byte[]) object)); } else { return Optional.empty(); } }
Example #21
Source File: ParquetMapInputFormat.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void convert(Map<String, Object> map, Row row, TypeInformation<?>[] fieldTypes, String[] fieldNames) { for (int i = 0; i < fieldNames.length; i++) { if (row.getField(i) != null) { if (fieldTypes[i] instanceof BasicTypeInfo || fieldTypes[i] instanceof PrimitiveArrayTypeInfo || fieldTypes[i] instanceof BasicArrayTypeInfo) { map.put(fieldNames[i], row.getField(i)); } else if (fieldTypes[i] instanceof RowTypeInfo) { Map<String, Object> nestedRow = new HashMap<>(); RowTypeInfo nestedRowTypeInfo = (RowTypeInfo) fieldTypes[i]; convert(nestedRow, (Row) row.getField(i), nestedRowTypeInfo.getFieldTypes(), nestedRowTypeInfo.getFieldNames()); map.put(fieldNames[i], nestedRow); } else if (fieldTypes[i] instanceof MapTypeInfo) { Map<String, Object> nestedMap = new HashMap<>(); MapTypeInfo mapTypeInfo = (MapTypeInfo) fieldTypes[i]; convert(nestedMap, (Map<String, Object>) row.getField(i), mapTypeInfo); map.put(fieldNames[i], nestedMap); } else if (fieldTypes[i] instanceof ObjectArrayTypeInfo) { List<Object> nestedObjectList = new ArrayList<>(); ObjectArrayTypeInfo objectArrayTypeInfo = (ObjectArrayTypeInfo) fieldTypes[i]; convert(nestedObjectList, (Row[]) row.getField(i), objectArrayTypeInfo); map.put(fieldNames[i], nestedObjectList); } } } }
Example #22
Source File: OneInputOperatorTransformation.java From flink with Apache License 2.0 | 5 votes |
/** * Partitions the operator state of a {@link OperatorTransformation} by the given key positions. * * @param fields The position of the fields on which the {@code OperatorTransformation} will be grouped. * @return The {@code OperatorTransformation} with partitioned state. */ public KeyedOperatorTransformation<Tuple, T> keyBy(int... fields) { if (dataSet.getType() instanceof BasicArrayTypeInfo || dataSet.getType() instanceof PrimitiveArrayTypeInfo) { return keyBy(KeySelectorUtil.getSelectorForArray(fields, dataSet.getType())); } else { return keyBy(new Keys.ExpressionKeys<>(fields, dataSet.getType())); } }
Example #23
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testBasicArray() { // use getCoGroupReturnTypes() RichCoGroupFunction<?, ?, ?> function = new RichCoGroupFunction<String[], String[], String[]>() { private static final long serialVersionUID = 1L; @Override public void coGroup(Iterable<String[]> first, Iterable<String[]> second, Collector<String[]> out) throws Exception { // nothing to do } }; TypeInformation<?> ti = TypeExtractor.getCoGroupReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<String[]>(){}), (TypeInformation) TypeInformation.of(new TypeHint<String[]>(){})); Assert.assertFalse(ti.isBasicType()); Assert.assertFalse(ti.isTupleType()); // Due to a Java 6 bug the classification can be slightly wrong Assert.assertTrue(ti instanceof BasicArrayTypeInfo<?,?> || ti instanceof ObjectArrayTypeInfo<?,?>); if(ti instanceof BasicArrayTypeInfo<?,?>) { Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, ti); } else { Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ((ObjectArrayTypeInfo<?,?>) ti).getComponentInfo()); } }
Example #24
Source File: TypeExtractorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicArray2() { RichMapFunction<Boolean[], ?> function = new IdentityMapper<Boolean[]>(); TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, BasicArrayTypeInfo.BOOLEAN_ARRAY_TYPE_INFO); Assert.assertTrue(ti instanceof BasicArrayTypeInfo<?, ?>); BasicArrayTypeInfo<?, ?> bati = (BasicArrayTypeInfo<?, ?>) ti; Assert.assertTrue(bati.getComponentInfo().isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, bati.getComponentInfo()); }
Example #25
Source File: OneInputOperatorTransformation.java From flink with Apache License 2.0 | 5 votes |
/** * Partitions the operator state of a {@link OperatorTransformation} by the given key positions. * * @param fields The position of the fields on which the {@code OperatorTransformation} will be grouped. * @return The {@code OperatorTransformation} with partitioned state. */ public KeyedOperatorTransformation<Tuple, T> keyBy(int... fields) { if (dataSet.getType() instanceof BasicArrayTypeInfo || dataSet.getType() instanceof PrimitiveArrayTypeInfo) { return keyBy(KeySelectorUtil.getSelectorForArray(fields, dataSet.getType())); } else { return keyBy(new Keys.ExpressionKeys<>(fields, dataSet.getType())); } }
Example #26
Source File: DataStreamTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicArrayKeyRejection() { KeySelector<Tuple2<Integer[], String>, Integer[]> keySelector = new KeySelector<Tuple2<Integer[], String>, Integer[]>() { @Override public Integer[] getKey(Tuple2<Integer[], String> value) throws Exception { return value.f0; } }; assertArrayKeyRejection(keySelector, BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO); }
Example #27
Source File: FieldAccessorTest.java From flink with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testArray() { int[] a = new int[]{3, 5}; FieldAccessor<int[], Integer> fieldAccessor = (FieldAccessor<int[], Integer>) (Object) FieldAccessorFactory.getAccessor(PrimitiveArrayTypeInfo.getInfoFor(a.getClass()), 1, null); assertEquals(Integer.class, fieldAccessor.getFieldType().getTypeClass()); assertEquals((Integer) a[1], fieldAccessor.get(a)); a = fieldAccessor.set(a, 6); assertEquals((Integer) a[1], fieldAccessor.get(a)); Integer[] b = new Integer[]{3, 5}; FieldAccessor<Integer[], Integer> fieldAccessor2 = (FieldAccessor<Integer[], Integer>) (Object) FieldAccessorFactory.getAccessor(BasicArrayTypeInfo.getInfoFor(b.getClass()), 1, null); assertEquals(Integer.class, fieldAccessor2.getFieldType().getTypeClass()); assertEquals(b[1], fieldAccessor2.get(b)); b = fieldAccessor2.set(b, 6); assertEquals(b[1], fieldAccessor2.get(b)); }
Example #28
Source File: DataSetSerializer.java From toolbox with Apache License 2.0 | 5 votes |
public static <T> DataSet<T> deserializeDataSet(String pathFile){ final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); SerializedInputFormat inputFormat = new SerializedInputFormat(); inputFormat.setFilePath(new Path(pathFile)); DataSet<byte[]> tmp = env.createInput(inputFormat, BasicArrayTypeInfo.BYTE_ARRAY_TYPE_INFO); return tmp.map(new RichMapFunction<byte[], T>() { @Override public T map(byte[] value) throws Exception { return Serialization.deserializeObject(value); } }); }
Example #29
Source File: TypeExtractorTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testBasicArray() { // use getCoGroupReturnTypes() RichCoGroupFunction<?, ?, ?> function = new RichCoGroupFunction<String[], String[], String[]>() { private static final long serialVersionUID = 1L; @Override public void coGroup(Iterable<String[]> first, Iterable<String[]> second, Collector<String[]> out) throws Exception { // nothing to do } }; TypeInformation<?> ti = TypeExtractor.getCoGroupReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint<String[]>(){}), (TypeInformation) TypeInformation.of(new TypeHint<String[]>(){})); Assert.assertFalse(ti.isBasicType()); Assert.assertFalse(ti.isTupleType()); // Due to a Java 6 bug the classification can be slightly wrong Assert.assertTrue(ti instanceof BasicArrayTypeInfo<?,?> || ti instanceof ObjectArrayTypeInfo<?,?>); if(ti instanceof BasicArrayTypeInfo<?,?>) { Assert.assertEquals(BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO, ti); } else { Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ((ObjectArrayTypeInfo<?,?>) ti).getComponentInfo()); } }
Example #30
Source File: FieldAccessorTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testArray() { int[] a = new int[]{3, 5}; FieldAccessor<int[], Integer> fieldAccessor = (FieldAccessor<int[], Integer>) (Object) FieldAccessorFactory.getAccessor(PrimitiveArrayTypeInfo.getInfoFor(a.getClass()), 1, null); assertEquals(Integer.class, fieldAccessor.getFieldType().getTypeClass()); assertEquals((Integer) a[1], fieldAccessor.get(a)); a = fieldAccessor.set(a, 6); assertEquals((Integer) a[1], fieldAccessor.get(a)); Integer[] b = new Integer[]{3, 5}; FieldAccessor<Integer[], Integer> fieldAccessor2 = (FieldAccessor<Integer[], Integer>) (Object) FieldAccessorFactory.getAccessor(BasicArrayTypeInfo.getInfoFor(b.getClass()), 1, null); assertEquals(Integer.class, fieldAccessor2.getFieldType().getTypeClass()); assertEquals(b[1], fieldAccessor2.get(b)); b = fieldAccessor2.set(b, 6); assertEquals(b[1], fieldAccessor2.get(b)); }