Java Code Examples for org.apache.flink.api.java.typeutils.PojoTypeInfo#getTypeClass()

The following examples show how to use org.apache.flink.api.java.typeutils.PojoTypeInfo#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: PojoCsvInputFormat.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void configure(String lineDelimiter, String fieldDelimiter, PojoTypeInfo<OUT> pojoTypeInfo, String[] fieldNames, boolean[] includedFieldsMask) {

		if (includedFieldsMask == null) {
			includedFieldsMask = createDefaultMask(fieldNames.length);
		}

		for (String name : fieldNames) {
			if (name == null) {
				throw new NullPointerException("Field name must not be null.");
			}
			if (pojoTypeInfo.getFieldIndex(name) < 0) {
				throw new IllegalArgumentException("Field \"" + name + "\" not part of POJO type " + pojoTypeInfo.getTypeClass().getCanonicalName());
			}
		}

		setDelimiter(lineDelimiter);
		setFieldDelimiter(fieldDelimiter);

		Class<?>[] classes = new Class<?>[fieldNames.length];

		for (int i = 0; i < fieldNames.length; i++) {
			try {
				classes[i] = pojoTypeInfo.getTypeAt(pojoTypeInfo.getFieldIndex(fieldNames[i])).getTypeClass();
			} catch (IndexOutOfBoundsException e) {
				throw new IllegalArgumentException("Invalid field name: " + fieldNames[i]);
			}
		}

		this.pojoTypeClass = pojoTypeInfo.getTypeClass();
		this.pojoTypeInfo = pojoTypeInfo;
		setFieldsGeneric(includedFieldsMask, classes);
		setOrderOfPOJOFields(fieldNames);
	}
 
Example 2
Source File: MinWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInformation<MinWithRetractAccumulator<T>> getAccumulatorType() {
	PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MinWithRetractAccumulator.class);
	List<PojoField> pojoFields = new ArrayList<>();
	for (int i = 0; i < pojoType.getTotalFields(); i++) {
		PojoField field = pojoType.getPojoFieldAt(i);
		if (field.getField().getName().equals("min")) {
			pojoFields.add(new PojoField(field.getField(), getValueTypeInfo()));
		} else {
			pojoFields.add(field);
		}
	}
	//noinspection unchecked
	return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields);
}
 
Example 3
Source File: MaxWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInformation<MaxWithRetractAccumulator<T>> getAccumulatorType() {
	PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MaxWithRetractAccumulator.class);
	List<PojoField> pojoFields = new ArrayList<>();
	for (int i = 0; i < pojoType.getTotalFields(); i++) {
		PojoField field = pojoType.getPojoFieldAt(i);
		if (field.getField().getName().equals("max")) {
			pojoFields.add(new PojoField(field.getField(), getValueTypeInfo()));
		} else {
			pojoFields.add(field);
		}
	}
	//noinspection unchecked
	return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields);
}
 
Example 4
Source File: ParquetPojoInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
public ParquetPojoInputFormat(Path filePath, MessageType messageType, PojoTypeInfo<E> pojoTypeInfo) {
	super(filePath, messageType);
	this.pojoTypeClass = pojoTypeInfo.getTypeClass();
	this.typeSerializer = pojoTypeInfo.createSerializer(new ExecutionConfig());
	final Map<String, Field> fieldMap = new HashMap<>();
	findAllFields(pojoTypeClass, fieldMap);
	selectFields(fieldMap.keySet().toArray(new String[0]));
}
 
Example 5
Source File: PojoCsvInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
private void configure(String lineDelimiter, String fieldDelimiter, PojoTypeInfo<OUT> pojoTypeInfo, String[] fieldNames, boolean[] includedFieldsMask) {

		if (includedFieldsMask == null) {
			includedFieldsMask = createDefaultMask(fieldNames.length);
		}

		for (String name : fieldNames) {
			if (name == null) {
				throw new NullPointerException("Field name must not be null.");
			}
			if (pojoTypeInfo.getFieldIndex(name) < 0) {
				throw new IllegalArgumentException("Field \"" + name + "\" not part of POJO type " + pojoTypeInfo.getTypeClass().getCanonicalName());
			}
		}

		setDelimiter(lineDelimiter);
		setFieldDelimiter(fieldDelimiter);

		Class<?>[] classes = new Class<?>[fieldNames.length];

		for (int i = 0; i < fieldNames.length; i++) {
			try {
				classes[i] = pojoTypeInfo.getTypeAt(pojoTypeInfo.getFieldIndex(fieldNames[i])).getTypeClass();
			} catch (IndexOutOfBoundsException e) {
				throw new IllegalArgumentException("Invalid field name: " + fieldNames[i]);
			}
		}

		this.pojoTypeClass = pojoTypeInfo.getTypeClass();
		this.pojoTypeInfo = pojoTypeInfo;
		setFieldsGeneric(includedFieldsMask, classes);
		setOrderOfPOJOFields(fieldNames);
	}
 
Example 6
Source File: MinWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInformation<MinWithRetractAccumulator<T>> getAccumulatorType() {
	PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MinWithRetractAccumulator.class);
	List<PojoField> pojoFields = new ArrayList<>();
	for (int i = 0; i < pojoType.getTotalFields(); i++) {
		PojoField field = pojoType.getPojoFieldAt(i);
		if (field.getField().getName().equals("min")) {
			pojoFields.add(new PojoField(field.getField(), getValueTypeInfo()));
		} else {
			pojoFields.add(field);
		}
	}
	//noinspection unchecked
	return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields);
}
 
Example 7
Source File: MaxWithRetractAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TypeInformation<MaxWithRetractAccumulator<T>> getAccumulatorType() {
	PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MaxWithRetractAccumulator.class);
	List<PojoField> pojoFields = new ArrayList<>();
	for (int i = 0; i < pojoType.getTotalFields(); i++) {
		PojoField field = pojoType.getPojoFieldAt(i);
		if (field.getField().getName().equals("max")) {
			pojoFields.add(new PojoField(field.getField(), getValueTypeInfo()));
		} else {
			pojoFields.add(field);
		}
	}
	//noinspection unchecked
	return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields);
}
 
Example 8
Source File: ParquetPojoInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
public ParquetPojoInputFormat(Path filePath, MessageType messageType, PojoTypeInfo<E> pojoTypeInfo) {
	super(filePath, messageType);
	this.pojoTypeClass = pojoTypeInfo.getTypeClass();
	this.typeSerializer = pojoTypeInfo.createSerializer(new ExecutionConfig());
	final Map<String, Field> fieldMap = new HashMap<>();
	findAllFields(pojoTypeClass, fieldMap);
	selectFields(fieldMap.keySet().toArray(new String[0]));
}
 
Example 9
Source File: PojoCsvInputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
private void configure(String lineDelimiter, String fieldDelimiter, PojoTypeInfo<OUT> pojoTypeInfo, String[] fieldNames, boolean[] includedFieldsMask) {

		if (includedFieldsMask == null) {
			includedFieldsMask = createDefaultMask(fieldNames.length);
		}

		for (String name : fieldNames) {
			if (name == null) {
				throw new NullPointerException("Field name must not be null.");
			}
			if (pojoTypeInfo.getFieldIndex(name) < 0) {
				throw new IllegalArgumentException("Field \"" + name + "\" not part of POJO type " + pojoTypeInfo.getTypeClass().getCanonicalName());
			}
		}

		setDelimiter(lineDelimiter);
		setFieldDelimiter(fieldDelimiter);

		Class<?>[] classes = new Class<?>[fieldNames.length];

		for (int i = 0; i < fieldNames.length; i++) {
			try {
				classes[i] = pojoTypeInfo.getTypeAt(pojoTypeInfo.getFieldIndex(fieldNames[i])).getTypeClass();
			} catch (IndexOutOfBoundsException e) {
				throw new IllegalArgumentException("Invalid field name: " + fieldNames[i]);
			}
		}

		this.pojoTypeClass = pojoTypeInfo.getTypeClass();
		this.pojoTypeInfo = pojoTypeInfo;
		setFieldsGeneric(includedFieldsMask, classes);
		setOrderOfPOJOFields(fieldNames);
	}