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

The following examples show how to use org.apache.flink.api.java.typeutils.PojoTypeInfo#getFieldIndex() . 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: ParquetPojoInputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the {@link TypeInformation}s  from {@link PojoTypeInfo} according to the given field name.
 */
private static <E> TypeInformation<?>[] extractTypeInfos(PojoTypeInfo<E> pojoTypeInfo, String[] fieldNames) {
	Preconditions.checkNotNull(pojoTypeInfo);
	Preconditions.checkNotNull(fieldNames);
	Preconditions.checkArgument(pojoTypeInfo.getArity() >= fieldNames.length);
	TypeInformation<?>[] fieldTypes = new TypeInformation<?>[fieldNames.length];
	for (int i = 0; i < fieldNames.length; ++i) {
		String fieldName = fieldNames[i];
		Preconditions.checkNotNull(fieldName, "The field can't be null");
		int fieldPos = pojoTypeInfo.getFieldIndex(fieldName);
		Preconditions.checkArgument(fieldPos >= 0,
			String.format("Field %s is not a member of POJO type %s",
				fieldName, pojoTypeInfo.getTypeClass().getName()));
		fieldTypes[i] = pojoTypeInfo.getTypeAt(fieldPos);
	}

	return fieldTypes;
}
 
Example 2
Source File: ParquetPojoInputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the {@link TypeInformation}s  from {@link PojoTypeInfo} according to the given field name.
 */
private static <E> TypeInformation<?>[] extractTypeInfos(PojoTypeInfo<E> pojoTypeInfo, String[] fieldNames) {
	Preconditions.checkNotNull(pojoTypeInfo);
	Preconditions.checkNotNull(fieldNames);
	Preconditions.checkArgument(pojoTypeInfo.getArity() >= fieldNames.length);
	TypeInformation<?>[] fieldTypes = new TypeInformation<?>[fieldNames.length];
	for (int i = 0; i < fieldNames.length; ++i) {
		String fieldName = fieldNames[i];
		Preconditions.checkNotNull(fieldName, "The field can't be null");
		int fieldPos = pojoTypeInfo.getFieldIndex(fieldName);
		Preconditions.checkArgument(fieldPos >= 0,
			String.format("Field %s is not a member of POJO type %s",
				fieldName, pojoTypeInfo.getTypeClass().getName()));
		fieldTypes[i] = pojoTypeInfo.getTypeAt(fieldPos);
	}

	return fieldTypes;
}
 
Example 3
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 4
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 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);
	}