Java Code Examples for org.apache.flink.api.common.typeutils.CompositeType#getArity()

The following examples show how to use org.apache.flink.api.common.typeutils.CompositeType#getArity() . 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: SemanticPropUtil.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static SingleInputSemanticProperties createProjectionPropertiesSingle(int[] fields, CompositeType<?> inType) {

		Character.isJavaIdentifierStart(1);

		SingleInputSemanticProperties ssp = new SingleInputSemanticProperties();

		int[] sourceOffsets = new int[inType.getArity()];
		sourceOffsets[0] = 0;
		for (int i = 1; i < inType.getArity(); i++) {
			sourceOffsets[i] = inType.getTypeAt(i - 1).getTotalFields() + sourceOffsets[i - 1];
		}

		int targetOffset = 0;
		for (int i = 0; i < fields.length; i++) {
			int sourceOffset = sourceOffsets[fields[i]];
			int numFieldsToCopy = inType.getTypeAt(fields[i]).getTotalFields();

			for (int j = 0; j < numFieldsToCopy; j++) {
				ssp.addForwardedField(sourceOffset + j, targetOffset + j);
			}
			targetOffset += numFieldsToCopy;
		}

		return ssp;
	}
 
Example 2
Source File: Utils.java    From Flink-CEPplus with 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 3
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public static SingleInputSemanticProperties createProjectionPropertiesSingle(int[] fields, CompositeType<?> inType) {

		Character.isJavaIdentifierStart(1);

		SingleInputSemanticProperties ssp = new SingleInputSemanticProperties();

		int[] sourceOffsets = new int[inType.getArity()];
		sourceOffsets[0] = 0;
		for (int i = 1; i < inType.getArity(); i++) {
			sourceOffsets[i] = inType.getTypeAt(i - 1).getTotalFields() + sourceOffsets[i - 1];
		}

		int targetOffset = 0;
		for (int i = 0; i < fields.length; i++) {
			int sourceOffset = sourceOffsets[fields[i]];
			int numFieldsToCopy = inType.getTypeAt(fields[i]).getTotalFields();

			for (int j = 0; j < numFieldsToCopy; j++) {
				ssp.addForwardedField(sourceOffset + j, targetOffset + j);
			}
			targetOffset += numFieldsToCopy;
		}

		return ssp;
	}
 
Example 4
Source File: Utils.java    From flink with 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 5
Source File: SemanticPropUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public static SingleInputSemanticProperties createProjectionPropertiesSingle(int[] fields, CompositeType<?> inType) {

		Character.isJavaIdentifierStart(1);

		SingleInputSemanticProperties ssp = new SingleInputSemanticProperties();

		int[] sourceOffsets = new int[inType.getArity()];
		sourceOffsets[0] = 0;
		for (int i = 1; i < inType.getArity(); i++) {
			sourceOffsets[i] = inType.getTypeAt(i - 1).getTotalFields() + sourceOffsets[i - 1];
		}

		int targetOffset = 0;
		for (int i = 0; i < fields.length; i++) {
			int sourceOffset = sourceOffsets[fields[i]];
			int numFieldsToCopy = inType.getTypeAt(fields[i]).getTotalFields();

			for (int j = 0; j < numFieldsToCopy; j++) {
				ssp.addForwardedField(sourceOffset + j, targetOffset + j);
			}
			targetOffset += numFieldsToCopy;
		}

		return ssp;
	}
 
Example 6
Source File: Utils.java    From flink with 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 7
Source File: Serializers.java    From Flink-CEPplus with 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);
			}
		}
	}
}
 
Example 8
Source File: Serializers.java    From flink with 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);
			}
		}
	}
}
 
Example 9
Source File: StreamSchema.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
private <E> TypeInformation[] getFieldTypes(TypeInformation<E> typeInfo, int[] fieldIndexes, String[] fieldNames) {
    TypeInformation[] fieldTypes;
    if (isCompositeType()) {
        CompositeType cType = (CompositeType) typeInfo;
        if (fieldNames.length != cType.getArity()) {
            // throw new IllegalArgumentException("Arity of type (" + cType.getFieldNames().length+ ") " +
            // "not equal to number of field names " + fieldNames.length + ".");
            LOGGER.warn("Arity of type (" + cType.getFieldNames().length + ") " +
                "not equal to number of field names " + fieldNames.length + ".");
        }
        fieldTypes = new TypeInformation[fieldIndexes.length];
        for (int i = 0; i < fieldIndexes.length; i++) {
            fieldTypes[i] = cType.getTypeAt(fieldIndexes[i]);
        }
    } else if (isAtomicType()) {
        if (fieldIndexes.length != 1 || fieldIndexes[0] != 0) {
            throw new IllegalArgumentException(
                "Non-composite input type may have only a single field and its index must be 0.");
        }
        fieldTypes = new TypeInformation[]{typeInfo};
    } else {
        throw new IllegalArgumentException(
            "Illegal input type info"
        );
    }
    return fieldTypes;
}
 
Example 10
Source File: StreamSchema.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
private <E> TypeInformation[] getFieldTypes(TypeInformation<E> typeInfo, int[] fieldIndexes, String[] fieldNames) {
    TypeInformation[] fieldTypes;
    if (isCompositeType()) {
        CompositeType cType = (CompositeType) typeInfo;
        if (fieldNames.length != cType.getArity()) {
            // throw new IllegalArgumentException("Arity of type (" + cType.getFieldNames().length+ ") " +
            // "not equal to number of field names " + fieldNames.length + ".");
            LOGGER.warn("Arity of type (" + cType.getFieldNames().length + ") " +
                "not equal to number of field names " + fieldNames.length + ".");
        }
        fieldTypes = new TypeInformation[fieldIndexes.length];
        for (int i = 0; i < fieldIndexes.length; i++) {
            fieldTypes[i] = cType.getTypeAt(fieldIndexes[i]);
        }
    } else if (isAtomicType()) {
        if (fieldIndexes.length != 1 || fieldIndexes[0] != 0) {
            throw new IllegalArgumentException(
                "Non-composite input type may have only a single field and its index must be 0.");
        }
        fieldTypes = new TypeInformation[]{typeInfo};
    } else {
        throw new IllegalArgumentException(
            "Illegal input type info"
        );
    }
    return fieldTypes;
}
 
Example 11
Source File: Serializers.java    From flink with 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);
			}
		}
	}
}