Java Code Examples for org.apache.flink.api.common.typeinfo.TypeInformation#getTypeClass()

The following examples show how to use org.apache.flink.api.common.typeinfo.TypeInformation#getTypeClass() . 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   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 2
Source Project: flink   File: SequenceFileWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setInputType(TypeInformation<?> type, ExecutionConfig executionConfig) {
	if (!type.isTupleType()) {
		throw new IllegalArgumentException("Input TypeInformation is not a tuple type.");
	}

	TupleTypeInfoBase<?> tupleType = (TupleTypeInfoBase<?>) type;

	if (tupleType.getArity() != 2) {
		throw new IllegalArgumentException("Input TypeInformation must be a Tuple2 type.");
	}

	TypeInformation<K> keyType = tupleType.getTypeAt(0);
	TypeInformation<V> valueType = tupleType.getTypeAt(1);

	this.keyClass = keyType.getTypeClass();
	this.valueClass = valueType.getTypeClass();
}
 
Example 3
Source Project: flink   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 4
private DeserializationRuntimeConverter assembleArrayConverter(
	TypeInformation<?> elementType,
	DeserializationRuntimeConverter elementConverter) {

	final Class<?> elementClass = elementType.getTypeClass();

	return (mapper, jsonNode) -> {
		final ArrayNode node = (ArrayNode) jsonNode;
		final Object[] array = (Object[]) Array.newInstance(elementClass, node.size());
		for (int i = 0; i < node.size(); i++) {
			final JsonNode innerNode = node.get(i);
			array[i] = elementConverter.convert(mapper, innerNode);
		}

		return array;
	};
}
 
Example 5
Source Project: flink   File: SequenceFileWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setInputType(TypeInformation<?> type, ExecutionConfig executionConfig) {
	if (!type.isTupleType()) {
		throw new IllegalArgumentException("Input TypeInformation is not a tuple type.");
	}

	TupleTypeInfoBase<?> tupleType = (TupleTypeInfoBase<?>) type;

	if (tupleType.getArity() != 2) {
		throw new IllegalArgumentException("Input TypeInformation must be a Tuple2 type.");
	}

	TypeInformation<K> keyType = tupleType.getTypeAt(0);
	TypeInformation<V> valueType = tupleType.getTypeAt(1);

	this.keyClass = keyType.getTypeClass();
	this.valueClass = valueType.getTypeClass();
}
 
Example 6
private static RuntimeConverter createObjectArrayRuntimeConverter(
		TypeInformation<?> elementType,
		boolean ignoreParseErrors) {
	final Class<?> elementClass = elementType.getTypeClass();
	final RuntimeConverter elementConverter = createNullableRuntimeConverter(elementType, ignoreParseErrors);

	return (node) -> {
		final int nodeSize = node.size();
		final Object[] array = (Object[]) Array.newInstance(elementClass, nodeSize);
		for (int i = 0; i < nodeSize; i++) {
			array[i] = elementConverter.convert(node.get(i));
		}
		return array;
	};
}
 
Example 7
Source Project: Flink-CEPplus   File: TypeExtractor.java    License: Apache License 2.0 5 votes vote down vote up
static void validateIfWritable(TypeInformation<?> typeInfo, Type type) {
	try {
		// try to load the writable type info

		Class<?> writableTypeInfoClass = Class
				.forName(HADOOP_WRITABLE_TYPEINFO_CLASS, false, typeInfo.getClass().getClassLoader());

		if (writableTypeInfoClass.isAssignableFrom(typeInfo.getClass())) {
			// this is actually a writable type info
			// check if the type is a writable
			if (!(type instanceof Class && isHadoopWritable((Class<?>) type))) {
				throw new InvalidTypesException(HADOOP_WRITABLE_CLASS + " type expected.");
			}

			// check writable type contents
			Class<?> clazz = (Class<?>) type;
			if (typeInfo.getTypeClass() != clazz) {
				throw new InvalidTypesException("Writable type '"
						+ typeInfo.getTypeClass().getCanonicalName() + "' expected but was '"
						+ clazz.getCanonicalName() + "'.");
			}
		}
	}
	catch (ClassNotFoundException e) {
		// class not present at all, so cannot be that type info
		// ignore
	}
}
 
Example 8
Source Project: flink   File: TypeExtractor.java    License: Apache License 2.0 5 votes vote down vote up
static void validateIfWritable(TypeInformation<?> typeInfo, Type type) {
	try {
		// try to load the writable type info

		Class<?> writableTypeInfoClass = Class
				.forName(HADOOP_WRITABLE_TYPEINFO_CLASS, false, typeInfo.getClass().getClassLoader());

		if (writableTypeInfoClass.isAssignableFrom(typeInfo.getClass())) {
			// this is actually a writable type info
			// check if the type is a writable
			if (!(type instanceof Class && isHadoopWritable((Class<?>) type))) {
				throw new InvalidTypesException(HADOOP_WRITABLE_CLASS + " type expected.");
			}

			// check writable type contents
			Class<?> clazz = (Class<?>) type;
			if (typeInfo.getTypeClass() != clazz) {
				throw new InvalidTypesException("Writable type '"
						+ typeInfo.getTypeClass().getCanonicalName() + "' expected but was '"
						+ clazz.getCanonicalName() + "'.");
			}
		}
	}
	catch (ClassNotFoundException e) {
		// class not present at all, so cannot be that type info
		// ignore
	}
}
 
Example 9
Source Project: flink   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 10
private static RuntimeConverter createObjectArrayRuntimeConverter(
		TypeInformation<?> elementType,
		boolean ignoreParseErrors) {
	final Class<?> elementClass = elementType.getTypeClass();
	final RuntimeConverter elementConverter = createNullableRuntimeConverter(elementType, ignoreParseErrors);

	return (node) -> {
		final int nodeSize = node.size();
		final Object[] array = (Object[]) Array.newInstance(elementClass, nodeSize);
		for (int i = 0; i < nodeSize; i++) {
			array[i] = elementConverter.convert(node.get(i));
		}
		return array;
	};
}
 
Example 11
private static RuntimeConverter createObjectArrayRuntimeConverter(
		TypeInformation<?> elementType,
		boolean ignoreParseErrors) {
	final Class<?> elementClass = elementType.getTypeClass();
	final RuntimeConverter elementConverter = createNullableRuntimeConverter(elementType, ignoreParseErrors);

	return (node) -> {
		final int nodeSize = node.size();
		final Object[] array = (Object[]) Array.newInstance(elementClass, nodeSize);
		for (int i = 0; i < nodeSize; i++) {
			array[i] = elementConverter.convert(node.get(i));
		}
		return array;
	};
}
 
Example 12
Source Project: flink   File: TypeExtractor.java    License: Apache License 2.0 5 votes vote down vote up
static void validateIfWritable(TypeInformation<?> typeInfo, Type type) {
	try {
		// try to load the writable type info

		Class<?> writableTypeInfoClass = Class
				.forName(HADOOP_WRITABLE_TYPEINFO_CLASS, false, typeInfo.getClass().getClassLoader());

		if (writableTypeInfoClass.isAssignableFrom(typeInfo.getClass())) {
			// this is actually a writable type info
			// check if the type is a writable
			if (!(type instanceof Class && isHadoopWritable((Class<?>) type))) {
				throw new InvalidTypesException(HADOOP_WRITABLE_CLASS + " type expected.");
			}

			// check writable type contents
			Class<?> clazz = (Class<?>) type;
			if (typeInfo.getTypeClass() != clazz) {
				throw new InvalidTypesException("Writable type '"
						+ typeInfo.getTypeClass().getCanonicalName() + "' expected but was '"
						+ clazz.getCanonicalName() + "'.");
			}
		}
	}
	catch (ClassNotFoundException e) {
		// class not present at all, so cannot be that type info
		// ignore
	}
}
 
Example 13
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private static boolean isOfGenericType(Parameter parameter, Class<?> baseType, TypeInformation<?> type) {
    if (!(parameter.getParameterizedType() instanceof ParameterizedType)) {
        return false;
    }
    ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType();
    if (parameterizedType.getRawType() != baseType) {
        return false;
    }
    Type t = parameterizedType.getActualTypeArguments()[0];
    return t == type.getTypeClass();
}
 
Example 14
Source Project: flink   File: FieldInfoUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate if class represented by the typeInfo is static and globally accessible.
 *
 * @param typeInfo type to check
 * @throws ValidationException if type does not meet these criteria
 */
public static <A> void validateInputTypeInfo(TypeInformation<A> typeInfo) {
	Class<A> clazz = typeInfo.getTypeClass();
	if ((clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) ||
		!Modifier.isPublic(clazz.getModifiers()) ||
		clazz.getCanonicalName() == null) {
		throw new ValidationException(format(
			"Class '%s' described in type information '%s' must be " +
			"static and globally accessible.", clazz, typeInfo));
	}
}
 
Example 15
public ValueArrayTypeInfo(TypeInformation<T> valueType) {
	this.valueType = valueType;
	this.type = valueType == null ? null : valueType.getTypeClass();
}
 
Example 16
Source Project: Flink-CEPplus   File: JavaApiPostPass.java    License: Apache License 2.0 4 votes vote down vote up
private <T> TypeSerializerFactory<?> createSerializer(TypeInformation<T> typeInfo) {
	TypeSerializer<T> serializer = typeInfo.createSerializer(executionConfig);

	return new RuntimeSerializerFactory<T>(serializer, typeInfo.getTypeClass());
}
 
Example 17
Source Project: flink   File: ValueArrayTypeInfo.java    License: Apache License 2.0 4 votes vote down vote up
public ValueArrayTypeInfo(TypeInformation<T> valueType) {
	this.valueType = valueType;
	this.type = valueType == null ? null : valueType.getTypeClass();
}
 
Example 18
Source Project: flink   File: JavaApiPostPass.java    License: Apache License 2.0 4 votes vote down vote up
private <T> TypeSerializerFactory<?> createSerializer(TypeInformation<T> typeInfo) {
	TypeSerializer<T> serializer = typeInfo.createSerializer(executionConfig);

	return new RuntimeSerializerFactory<T>(serializer, typeInfo.getTypeClass());
}
 
Example 19
private static boolean isOfSimpleType(Parameter parameter, TypeInformation<?> type) {
    return parameter.getType() == type.getTypeClass();
}
 
Example 20
Source Project: flink   File: JavaApiPostPass.java    License: Apache License 2.0 4 votes vote down vote up
private <T> TypeSerializerFactory<?> createSerializer(TypeInformation<T> typeInfo) {
	TypeSerializer<T> serializer = typeInfo.createSerializer(executionConfig);

	return new RuntimeSerializerFactory<T>(serializer, typeInfo.getTypeClass());
}