Java Code Examples for org.apache.flink.api.java.typeutils.GenericTypeInfo

The following examples show how to use org.apache.flink.api.java.typeutils.GenericTypeInfo. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: OuterJoinITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithAtomicType1() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
	DataSet<Integer> ds2 = env.fromElements(1, 2);

	DataSet<Tuple2<Tuple3<Integer, Long, String>, Integer>> joinDs = ds1
			.fullOuterJoin(ds2)
			.where(0)
			.equalTo("*")
			.with(new ProjectBothFunction<Tuple3<Integer, Long, String>, Integer>())
			.returns(new GenericTypeInfo(Tuple2.class));

	List<Tuple2<Tuple3<Integer, Long, String>, Integer>> result = joinDs.collect();

	String expected = "(1,1,Hi),1\n" +
			"(2,2,Hello),2\n" +
			"(3,2,Hello world),null\n";

	compareResultAsTuples(result, expected);
}
 
Example 2
Source Project: Flink-CEPplus   Source File: OuterJoinITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithAtomicType2() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Integer> ds1 = env.fromElements(1, 2);
	DataSet<Tuple3<Integer, Long, String>> ds2 = CollectionDataSets.getSmall3TupleDataSet(env);

	DataSet<Tuple2<Integer, Tuple3<Integer, Long, String>>> joinDs = ds1
			.fullOuterJoin(ds2)
			.where("*")
			.equalTo(0)
			.with(new ProjectBothFunction<Integer, Tuple3<Integer, Long, String>>())
			.returns(new GenericTypeInfo(Tuple2.class));

	List<Tuple2<Integer, Tuple3<Integer, Long, String>>> result = joinDs.collect();

	String expected = "1,(1,1,Hi)\n" +
			"2,(2,2,Hello)\n" +
			"null,(3,2,Hello world)\n";

	compareResultAsTuples(result, expected);
}
 
Example 3
Source Project: flink   Source File: SerializersTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTypeRegistrationFromTypeInfo() {
	ExecutionConfig conf = new ExecutionConfig();
	Serializers.recursivelyRegisterType(new GenericTypeInfo<>(ClassWithNested.class), conf, new HashSet<Class<?>>());

	KryoSerializer<String> kryo = new KryoSerializer<>(String.class, conf); // we create Kryo from another type.

	assertTrue(kryo.getKryo().getRegistration(FromNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(ClassWithNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Path.class).getId() > 0);

	// check if the generic type from one field is also registered (its very likely that
	// generic types are also used as fields somewhere.
	assertTrue(kryo.getKryo().getRegistration(FromGeneric1.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(FromGeneric2.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Node.class).getId() > 0);
}
 
Example 4
Source Project: flink   Source File: MapViewTypeInfoFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public TypeInformation<MapView<K, V>> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
	TypeInformation<?> keyType = genericParameters.get("K");
	TypeInformation<?> valueType = genericParameters.get("V");

	if (keyType == null) {
		// we might can get the keyType later from the MapView constructor
		keyType = new GenericTypeInfo<>(Object.class);
	}

	if (valueType == null) {
		// we might can get the keyType later from the MapView constructor
		valueType = new GenericTypeInfo<>(Object.class);
	}

	//noinspection unchecked
	return new MapViewTypeInfo<>((TypeInformation<K>) keyType, (TypeInformation<V>) valueType);
}
 
Example 5
Source Project: Flink-CEPplus   Source File: Serializers.java    License: Apache License 2.0 6 votes vote down vote up
public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) {
	if (typeInfo instanceof GenericTypeInfo) {
		GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
		Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen);
	}
	else if (typeInfo instanceof CompositeType) {
		List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
		getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite);
		for (GenericTypeInfo<?> gt : genericTypesInComposite) {
			Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
		}
	}
	else if (typeInfo instanceof ObjectArrayTypeInfo) {
		ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
		recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
	}
}
 
Example 6
Source Project: Flink-CEPplus   Source File: SerializersTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTypeRegistrationFromTypeInfo() {
	ExecutionConfig conf = new ExecutionConfig();
	Serializers.recursivelyRegisterType(new GenericTypeInfo<>(ClassWithNested.class), conf, new HashSet<Class<?>>());

	KryoSerializer<String> kryo = new KryoSerializer<>(String.class, conf); // we create Kryo from another type.

	assertTrue(kryo.getKryo().getRegistration(FromNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(ClassWithNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Path.class).getId() > 0);

	// check if the generic type from one field is also registered (its very likely that
	// generic types are also used as fields somewhere.
	assertTrue(kryo.getKryo().getRegistration(FromGeneric1.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(FromGeneric2.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Node.class).getId() > 0);
}
 
Example 7
Source Project: flink   Source File: Keys.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <E> void validateCustomPartitioner(Partitioner<E> partitioner, TypeInformation<E> typeInfo) {

	if (keyFields.size() != 1) {
		throw new InvalidProgramException("Custom partitioners can only be used with keys that have one key field.");
	}
	
	if (typeInfo == null) {
		// try to extract key type from partitioner
		try {
			typeInfo = TypeExtractor.getPartitionerTypes(partitioner);
		}
		catch (Throwable t) {
			// best effort check, so we ignore exceptions
		}
	}

	// only check if type is known and not a generic type
	if (typeInfo != null && !(typeInfo instanceof GenericTypeInfo)) {
		// check equality of key and partitioner type
		if (!keyType.equals(typeInfo)) {
			throw new InvalidProgramException("The partitioner is incompatible with the key type. "
				+ "Partitioner type: " + typeInfo + " , key type: " + keyType);
		}
	}
}
 
Example 8
Source Project: flink   Source File: DataTypeExtractorTest.java    License: Apache License 2.0 6 votes vote down vote up
private static DataType getPojoWithRawSelfReferenceDataType() {
	final StructuredType.Builder builder = StructuredType.newBuilder(PojoWithRawSelfReference.class);
	builder.attributes(
		Arrays.asList(
			new StructuredAttribute(
				"integer",
				new IntType()),
			new StructuredAttribute(
				"reference",
				new TypeInformationRawType<>(new GenericTypeInfo<>(PojoWithRawSelfReference.class)))));
	builder.setFinal(true);
	builder.setInstantiable(true);
	final StructuredType structuredType = builder.build();

	final List<DataType> fieldDataTypes = Arrays.asList(
		DataTypes.INT(),
		DataTypes.RAW(new GenericTypeInfo<>(PojoWithRawSelfReference.class))
	);

	return new FieldsDataType(structuredType, PojoWithRawSelfReference.class, fieldDataTypes);
}
 
Example 9
Source Project: Flink-CEPplus   Source File: DataStreamTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testObjectArrayKeyRejection() {

	KeySelector<Tuple2<Integer[], String>, Object[]> keySelector =
			new KeySelector<Tuple2<Integer[], String>, Object[]>() {

				@Override
				public Object[] getKey(Tuple2<Integer[], String> value) throws Exception {
					Object[] ks = new Object[value.f0.length];
					for (int i = 0; i < ks.length; i++) {
						ks[i] = new Object();
					}
					return ks;
				}
			};

	ObjectArrayTypeInfo<Object[], Object> keyTypeInfo = ObjectArrayTypeInfo.getInfoFor(
			Object[].class, new GenericTypeInfo<>(Object.class));

	testKeyRejection(keySelector, keyTypeInfo);
}
 
Example 10
Source Project: flink   Source File: NestedRowTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedRowWithMultipleSegments() {
	BinaryRow row = getBinaryRow();
	GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
	TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());

	MemorySegment[] segments = splitBytes(row.getSegments()[0].getHeapMemory(), 3);
	row.pointTo(segments, 3, row.getSizeInBytes());
	{
		BaseRow nestedRow = row.getRow(0, 5);
		assertEquals(nestedRow.getInt(0), 1);
		assertEquals(nestedRow.getLong(1), 5L);
		assertEquals(nestedRow.getString(2), BinaryString.fromString("12345678"));
		assertTrue(nestedRow.isNullAt(3));
		assertEquals(new MyObj(15, 5),
			BinaryGeneric.getJavaObjectFromBinaryGeneric(nestedRow.getGeneric(4), genericSerializer));
	}
}
 
Example 11
Source Project: flink   Source File: MapViewTypeInfoFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public TypeInformation<MapView<K, V>> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
	TypeInformation<?> keyType = genericParameters.get("K");
	TypeInformation<?> valueType = genericParameters.get("V");

	if (keyType == null) {
		// we might can get the keyType later from the MapView constructor
		keyType = new GenericTypeInfo<>(Object.class);
	}

	if (valueType == null) {
		// we might can get the keyType later from the MapView constructor
		valueType = new GenericTypeInfo<>(Object.class);
	}

	//noinspection unchecked
	return new MapViewTypeInfo<>((TypeInformation<K>) keyType, (TypeInformation<V>) valueType);
}
 
Example 12
Source Project: flink   Source File: FieldInfoUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static <A> List<FieldInfo> extractFieldInformation(
	TypeInformation<A> inputType,
	Expression[] exprs) {
	final List<FieldInfo> fieldInfos;
	if (inputType instanceof GenericTypeInfo && inputType.getTypeClass() == Row.class) {
		throw new ValidationException(
			"An input of GenericTypeInfo<Row> cannot be converted to Table. " +
				"Please specify the type of the input with a RowTypeInfo.");
	} else if (inputType instanceof TupleTypeInfoBase) {
		fieldInfos = extractFieldInfosFromTupleType((TupleTypeInfoBase<?>) inputType, exprs);
	} else if (inputType instanceof PojoTypeInfo) {
		fieldInfos = extractFieldInfosByNameReference((CompositeType<?>) inputType, exprs);
	} else {
		fieldInfos = extractFieldInfoFromAtomicType(inputType, exprs);
	}
	return fieldInfos;
}
 
Example 13
Source Project: flink   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
private static <T> String getSerializerTree(TypeInformation<T> ti, int indent) {
	String ret = "";
	if (ti instanceof CompositeType) {
		ret += StringUtils.repeat(' ', indent) + ti.getClass().getSimpleName() + "\n";
		CompositeType<T> cti = (CompositeType<T>) ti;
		String[] fieldNames = cti.getFieldNames();
		for (int i = 0; i < cti.getArity(); i++) {
			TypeInformation<?> fieldType = cti.getTypeAt(i);
			ret += StringUtils.repeat(' ', indent + 2) + fieldNames[i] + ":" + getSerializerTree(fieldType, indent);
		}
	} else {
		if (ti instanceof GenericTypeInfo) {
			ret += StringUtils.repeat(' ', indent) + "GenericTypeInfo (" + ti.getTypeClass().getSimpleName() + ")\n";
			ret += getGenericTypeTree(ti.getTypeClass(), indent + 4);
		} else {
			ret += StringUtils.repeat(' ', indent) + ti.toString() + "\n";
		}
	}
	return ret;
}
 
Example 14
Source Project: flink   Source File: Serializers.java    License: Apache License 2.0 6 votes vote down vote up
public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) {
	if (typeInfo instanceof GenericTypeInfo) {
		GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
		Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen);
	}
	else if (typeInfo instanceof CompositeType) {
		List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
		getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite);
		for (GenericTypeInfo<?> gt : genericTypesInComposite) {
			Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
		}
	}
	else if (typeInfo instanceof ObjectArrayTypeInfo) {
		ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
		recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
	}
}
 
Example 15
Source Project: flink   Source File: Keys.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <E> void validateCustomPartitioner(Partitioner<E> partitioner, TypeInformation<E> typeInfo) {

	if (keyFields.size() != 1) {
		throw new InvalidProgramException("Custom partitioners can only be used with keys that have one key field.");
	}
	
	if (typeInfo == null) {
		// try to extract key type from partitioner
		try {
			typeInfo = TypeExtractor.getPartitionerTypes(partitioner);
		}
		catch (Throwable t) {
			// best effort check, so we ignore exceptions
		}
	}

	// only check if type is known and not a generic type
	if (typeInfo != null && !(typeInfo instanceof GenericTypeInfo)) {
		// check equality of key and partitioner type
		if (!keyType.equals(typeInfo)) {
			throw new InvalidProgramException("The partitioner is incompatible with the key type. "
				+ "Partitioner type: " + typeInfo + " , key type: " + keyType);
		}
	}
}
 
Example 16
Source Project: flink   Source File: SerializersTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTypeRegistrationFromTypeInfo() {
	ExecutionConfig conf = new ExecutionConfig();
	Serializers.recursivelyRegisterType(new GenericTypeInfo<>(ClassWithNested.class), conf, new HashSet<Class<?>>());

	KryoSerializer<String> kryo = new KryoSerializer<>(String.class, conf); // we create Kryo from another type.

	assertTrue(kryo.getKryo().getRegistration(FromNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(ClassWithNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Path.class).getId() > 0);

	// check if the generic type from one field is also registered (its very likely that
	// generic types are also used as fields somewhere.
	assertTrue(kryo.getKryo().getRegistration(FromGeneric1.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(FromGeneric2.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Node.class).getId() > 0);
}
 
Example 17
Source Project: flink   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
private static <T> String getSerializerTree(TypeInformation<T> ti, int indent) {
	String ret = "";
	if (ti instanceof CompositeType) {
		ret += StringUtils.repeat(' ', indent) + ti.getClass().getSimpleName() + "\n";
		CompositeType<T> cti = (CompositeType<T>) ti;
		String[] fieldNames = cti.getFieldNames();
		for (int i = 0; i < cti.getArity(); i++) {
			TypeInformation<?> fieldType = cti.getTypeAt(i);
			ret += StringUtils.repeat(' ', indent + 2) + fieldNames[i] + ":" + getSerializerTree(fieldType, indent);
		}
	} else {
		if (ti instanceof GenericTypeInfo) {
			ret += StringUtils.repeat(' ', indent) + "GenericTypeInfo (" + ti.getTypeClass().getSimpleName() + ")\n";
			ret += getGenericTypeTree(ti.getTypeClass(), indent + 4);
		} else {
			ret += StringUtils.repeat(' ', indent) + ti.toString() + "\n";
		}
	}
	return ret;
}
 
Example 18
Source Project: flink   Source File: ExecutionConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableGenericTypes() {
	ExecutionConfig conf = new ExecutionConfig();
	TypeInformation<Object> typeInfo = new GenericTypeInfo<Object>(Object.class);

	// by default, generic types are supported
	TypeSerializer<Object> serializer = typeInfo.createSerializer(conf);
	assertTrue(serializer instanceof KryoSerializer);

	// expect an exception when generic types are disabled
	conf.disableGenericTypes();
	try {
		typeInfo.createSerializer(conf);
		fail("should have failed with an exception");
	}
	catch (UnsupportedOperationException e) {
		// expected
	}
}
 
Example 19
Source Project: flink   Source File: OuterJoinITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJoinWithAtomicType2() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Integer> ds1 = env.fromElements(1, 2);
	DataSet<Tuple3<Integer, Long, String>> ds2 = CollectionDataSets.getSmall3TupleDataSet(env);

	DataSet<Tuple2<Integer, Tuple3<Integer, Long, String>>> joinDs = ds1
			.fullOuterJoin(ds2)
			.where("*")
			.equalTo(0)
			.with(new ProjectBothFunction<Integer, Tuple3<Integer, Long, String>>())
			.returns(new GenericTypeInfo(Tuple2.class));

	List<Tuple2<Integer, Tuple3<Integer, Long, String>>> result = joinDs.collect();

	String expected = "1,(1,1,Hi)\n" +
			"2,(2,2,Hello)\n" +
			"null,(3,2,Hello world)\n";

	compareResultAsTuples(result, expected);
}
 
Example 20
Source Project: flink   Source File: ExecutionConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableGenericTypes() {
	ExecutionConfig conf = new ExecutionConfig();
	TypeInformation<Object> typeInfo = new GenericTypeInfo<Object>(Object.class);

	// by default, generic types are supported
	TypeSerializer<Object> serializer = typeInfo.createSerializer(conf);
	assertTrue(serializer instanceof KryoSerializer);

	// expect an exception when generic types are disabled
	conf.disableGenericTypes();
	try {
		typeInfo.createSerializer(conf);
		fail("should have failed with an exception");
	}
	catch (UnsupportedOperationException e) {
		// expected
	}
}
 
Example 21
private static <TWarningType extends IWarning> DataStream<TWarningType> toWarningStream(DataStream<LocalWeatherData> localWeatherDataDataStream, IWarningPattern<LocalWeatherData, TWarningType> warningPattern) {
    PatternStream<LocalWeatherData> tempPatternStream = CEP.pattern(
            localWeatherDataDataStream.keyBy(new KeySelector<LocalWeatherData, String>() {
                @Override
                public String getKey(LocalWeatherData localWeatherData) throws Exception {
                    return localWeatherData.getStation().getWban();
                }
            }),
            warningPattern.getEventPattern());

    DataStream<TWarningType> warnings = tempPatternStream.select(new PatternSelectFunction<LocalWeatherData, TWarningType>() {
        @Override
        public TWarningType select(Map<String, List<LocalWeatherData>> map) throws Exception {
            return warningPattern.create(map);
        }
    }, new GenericTypeInfo<TWarningType>(warningPattern.getWarningTargetType()));

    return warnings;
}
 
Example 22
Source Project: beam   Source File: FlinkStateInternalsTest.java    License: Apache License 2.0 6 votes vote down vote up
public static KeyedStateBackend<ByteBuffer> createStateBackend() throws Exception {
  MemoryStateBackend backend = new MemoryStateBackend();

  AbstractKeyedStateBackend<ByteBuffer> keyedStateBackend =
      backend.createKeyedStateBackend(
          new DummyEnvironment("test", 1, 0),
          new JobID(),
          "test_op",
          new GenericTypeInfo<>(ByteBuffer.class).createSerializer(new ExecutionConfig()),
          2,
          new KeyGroupRange(0, 1),
          new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()),
          TtlTimeProvider.DEFAULT,
          null,
          Collections.emptyList(),
          new CloseableRegistry());

  changeKey(keyedStateBackend);

  return keyedStateBackend;
}
 
Example 23
Source Project: flink   Source File: FieldInfoUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static <A> List<FieldInfo> extractFieldInformation(
		TypeInformation<A> inputType,
		Expression[] exprs) {
	final List<FieldInfo> fieldInfos;
	if (inputType instanceof GenericTypeInfo && inputType.getTypeClass() == Row.class) {
		throw new ValidationException(
			"An input of GenericTypeInfo<Row> cannot be converted to Table. " +
				"Please specify the type of the input with a RowTypeInfo.");
	} else if (inputType instanceof TupleTypeInfoBase) {
		fieldInfos = extractFieldInfosFromTupleType((TupleTypeInfoBase<?>) inputType, exprs);
	} else if (inputType instanceof PojoTypeInfo) {
		fieldInfos = extractFieldInfosByNameReference((CompositeType<?>) inputType, exprs);
	} else {
		fieldInfos = extractFieldInfoFromAtomicType(inputType, exprs);
	}
	return fieldInfos;
}
 
Example 24
Source Project: flink   Source File: NestedRowDataTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedRowDataWithMultipleSegments() {
	BinaryRowData row = getBinaryRowData();
	GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
	TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());

	MemorySegment[] segments = splitBytes(row.getSegments()[0].getHeapMemory(), 3);
	row.pointTo(segments, 3, row.getSizeInBytes());
	{
		RowData nestedRow = row.getRow(0, 5);
		assertEquals(nestedRow.getInt(0), 1);
		assertEquals(nestedRow.getLong(1), 5L);
		assertEquals(nestedRow.getString(2), StringData.fromString("12345678"));
		assertTrue(nestedRow.isNullAt(3));
		assertEquals(new MyObj(15, 5), nestedRow.<MyObj>getRawValue(4).toObject(genericSerializer));
	}
}
 
Example 25
Source Project: Flink-CEPplus   Source File: HCatInputFormatBase.java    License: Apache License 2.0 5 votes vote down vote up
private TypeInformation getFieldType(HCatFieldSchema fieldSchema) {

		switch(fieldSchema.getType()) {
			case INT:
				return BasicTypeInfo.INT_TYPE_INFO;
			case TINYINT:
				return BasicTypeInfo.BYTE_TYPE_INFO;
			case SMALLINT:
				return BasicTypeInfo.SHORT_TYPE_INFO;
			case BIGINT:
				return BasicTypeInfo.LONG_TYPE_INFO;
			case BOOLEAN:
				return BasicTypeInfo.BOOLEAN_TYPE_INFO;
			case FLOAT:
				return BasicTypeInfo.FLOAT_TYPE_INFO;
			case DOUBLE:
				return BasicTypeInfo.DOUBLE_TYPE_INFO;
			case STRING:
				return BasicTypeInfo.STRING_TYPE_INFO;
			case BINARY:
				return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;
			case ARRAY:
				return new GenericTypeInfo(List.class);
			case MAP:
				return new GenericTypeInfo(Map.class);
			case STRUCT:
				return new GenericTypeInfo(List.class);
			default:
				throw new IllegalArgumentException("Unknown data type \"" + fieldSchema.getType() + "\" encountered.");
		}
	}
 
Example 26
Source Project: Flink-CEPplus   Source File: JavaTableEnvironmentITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = TableException.class)
public void testGenericRow() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env, config());

	// use null value the enforce GenericType
	DataSet<Row> dataSet = env.fromElements(Row.of(1, 2L, "Hello", null));
	assertTrue(dataSet.getType() instanceof GenericTypeInfo);
	assertTrue(dataSet.getType().getTypeClass().equals(Row.class));

	// Must fail. Cannot import DataSet<Row> with GenericTypeInfo.
	tableEnv.fromDataSet(dataSet);
}
 
Example 27
Source Project: Flink-CEPplus   Source File: JavaTableEnvironmentITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = TableException.class)
public void testGenericRowWithAlias() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env, config());

	// use null value the enforce GenericType
	DataSet<Row> dataSet = env.fromElements(Row.of((Integer) null));
	assertTrue(dataSet.getType() instanceof GenericTypeInfo);
	assertTrue(dataSet.getType().getTypeClass().equals(Row.class));

	// Must fail. Cannot import DataSet<Row> with GenericTypeInfo.
	tableEnv.fromDataSet(dataSet, "nullField");
}
 
Example 28
Source Project: flink   Source File: FieldInfoUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link TypeInfoSchema} for a given {@link TypeInformation}.
 *
 * @param inputType The TypeInformation to extract the mapping from.
 * @param <A> The type of the TypeInformation.
 * @return A description of the input that enables creation of a {@link TableSchema}.
 * @see TypeInfoSchema
 */
public static <A> TypeInfoSchema getFieldsInfo(TypeInformation<A> inputType) {

	if (inputType instanceof GenericTypeInfo && inputType.getTypeClass() == Row.class) {
		throw new ValidationException(
			"An input of GenericTypeInfo<Row> cannot be converted to Table. " +
				"Please specify the type of the input with a RowTypeInfo.");
	} else {
		return new TypeInfoSchema(
			getFieldNames(inputType),
			getFieldIndices(inputType),
			fromLegacyInfoToDataType(getFieldTypes(inputType)),
			false);
	}
}
 
Example 29
Source Project: flink   Source File: ListViewTypeInfoFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeInformation<ListView<T>> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
	TypeInformation<?> elementType = genericParameters.get("T");

	if (elementType == null) {
		// we might can get the elementType later from the ListView constructor
		elementType = new GenericTypeInfo<>(Object.class);
	}

	//noinspection unchecked
	return new ListViewTypeInfo<>((TypeInformation<T>) elementType);
}
 
Example 30
Source Project: Flink-CEPplus   Source File: Serializers.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns all GenericTypeInfos contained in a composite type.
 *
 * @param typeInfo {@link CompositeType}
 */
private static void getContainedGenericTypes(CompositeType<?> typeInfo, List<GenericTypeInfo<?>> target) {
	for (int i = 0; i < typeInfo.getArity(); i++) {
		TypeInformation<?> type = typeInfo.getTypeAt(i);
		if (type instanceof CompositeType) {
			getContainedGenericTypes((CompositeType<?>) type, target);
		} else if (type instanceof GenericTypeInfo) {
			if (!target.contains(type)) {
				target.add((GenericTypeInfo<?>) type);
			}
		}
	}
}