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 File: FieldInfoUtils.java    From flink with 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 File: SequenceFileWriter.java    From flink with 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 File: SequenceFileWriter.java    From flink with 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 4
Source File: JsonRowDeserializationSchema.java    From flink with Apache License 2.0 6 votes vote down vote up
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 File: FieldInfoUtils.java    From flink with 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 6
Source File: CsvRowDeserializationSchema.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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 File: FieldInfoUtils.java    From flink with 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 8
Source File: StreamingLedgerSpecFactory.java    From da-streamingledger with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: TypeExtractor.java    From flink with 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 10
Source File: CsvRowDeserializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
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
Source File: CsvRowDeserializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
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 File: FieldInfoUtils.java    From flink with 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 13
Source File: TypeExtractor.java    From flink with 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 14
Source File: TypeExtractor.java    From Flink-CEPplus with 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 15
Source File: ValueArrayTypeInfo.java    From flink with 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 16
Source File: JavaApiPostPass.java    From flink with 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 File: StreamingLedgerSpecFactory.java    From da-streamingledger with Apache License 2.0 4 votes vote down vote up
private static boolean isOfSimpleType(Parameter parameter, TypeInformation<?> type) {
    return parameter.getType() == type.getTypeClass();
}
 
Example 18
Source File: JavaApiPostPass.java    From Flink-CEPplus with 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
Source File: ValueArrayTypeInfo.java    From Flink-CEPplus with 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 20
Source File: JavaApiPostPass.java    From flink with 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());
}