Java Code Examples for org.apache.flink.api.common.typeutils.CompositeType#getTypeAt()
The following examples show how to use
org.apache.flink.api.common.typeutils.CompositeType#getTypeAt() .
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: TableSchema.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Creates a table schema from a {@link TypeInformation} instance. If the type information is * a {@link CompositeType}, the field names and types for the composite type are used to * construct the {@link TableSchema} instance. Otherwise, a table schema with a single field * is created. The field name is "f0" and the field type the provided type. * * @param typeInfo The {@link TypeInformation} from which the table schema is generated. * @return The table schema that was generated from the given {@link TypeInformation}. */ public static TableSchema fromTypeInfo(TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { final CompositeType<?> compositeType = (CompositeType<?>) typeInfo; // get field names and types from composite type final String[] fieldNames = compositeType.getFieldNames(); final TypeInformation<?>[] fieldTypes = new TypeInformation[fieldNames.length]; for (int i = 0; i < fieldTypes.length; i++) { fieldTypes[i] = compositeType.getTypeAt(i); } return new TableSchema(fieldNames, fieldTypes); } else { // create table schema with a single field named "f0" of the given type. return new TableSchema( new String[]{ATOMIC_TYPE_FIELD_NAME}, new TypeInformation<?>[]{typeInfo}); } }
Example 2
Source File: Utils.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
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: TableSchema.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a table schema from a {@link TypeInformation} instance. If the type information is * a {@link CompositeType}, the field names and types for the composite type are used to * construct the {@link TableSchema} instance. Otherwise, a table schema with a single field * is created. The field name is "f0" and the field type the provided type. * * @param typeInfo The {@link TypeInformation} from which the table schema is generated. * @return The table schema that was generated from the given {@link TypeInformation}. * * @deprecated This method will be removed soon. Use {@link DataTypes} to declare types. */ @Deprecated public static TableSchema fromTypeInfo(TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { final CompositeType<?> compositeType = (CompositeType<?>) typeInfo; // get field names and types from composite type final String[] fieldNames = compositeType.getFieldNames(); final TypeInformation<?>[] fieldTypes = new TypeInformation[fieldNames.length]; for (int i = 0; i < fieldTypes.length; i++) { fieldTypes[i] = compositeType.getTypeAt(i); } return new TableSchema(fieldNames, fieldTypes); } else { // create table schema with a single field named "f0" of the given type. return new TableSchema( new String[]{ATOMIC_TYPE_FIELD_NAME}, new TypeInformation<?>[]{typeInfo}); } }
Example 4
Source File: Utils.java From flink with Apache License 2.0 | 6 votes |
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: TableSchema.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a table schema from a {@link TypeInformation} instance. If the type information is * a {@link CompositeType}, the field names and types for the composite type are used to * construct the {@link TableSchema} instance. Otherwise, a table schema with a single field * is created. The field name is "f0" and the field type the provided type. * * @param typeInfo The {@link TypeInformation} from which the table schema is generated. * @return The table schema that was generated from the given {@link TypeInformation}. * * @deprecated This method will be removed soon. Use {@link DataTypes} to declare types. */ @Deprecated public static TableSchema fromTypeInfo(TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { final CompositeType<?> compositeType = (CompositeType<?>) typeInfo; // get field names and types from composite type final String[] fieldNames = compositeType.getFieldNames(); final TypeInformation<?>[] fieldTypes = new TypeInformation[fieldNames.length]; for (int i = 0; i < fieldTypes.length; i++) { fieldTypes[i] = compositeType.getTypeAt(i); } return new TableSchema(fieldNames, fieldTypes); } else { // create table schema with a single field named "f0" of the given type. return new TableSchema( new String[]{ATOMIC_TYPE_FIELD_NAME}, new TypeInformation<?>[]{typeInfo}); } }
Example 6
Source File: Utils.java From flink with Apache License 2.0 | 6 votes |
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 |
/** * 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 |
/** * 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 |
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 |
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 |
/** * 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 12
Source File: Keys.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Create int-based (non-nested) field position keys on a tuple type. */ public ExpressionKeys(int[] keyPositions, TypeInformation<T> type, boolean allowEmpty) { if (!type.isTupleType() || !(type instanceof CompositeType)) { throw new InvalidProgramException("Specifying keys via field positions is only valid " + "for tuple data types. Type: " + type); } if (type.getArity() == 0) { throw new InvalidProgramException("Tuple size must be greater than 0. Size: " + type.getArity()); } if (!allowEmpty && (keyPositions == null || keyPositions.length == 0)) { throw new IllegalArgumentException("The grouping fields must not be empty."); } this.keyFields = new ArrayList<>(); if (keyPositions == null || keyPositions.length == 0) { // use all tuple fields as key fields keyPositions = createIncrIntArray(type.getArity()); } else { rangeCheckFields(keyPositions, type.getArity() - 1); } checkArgument(keyPositions.length > 0, "Grouping fields can not be empty at this point"); // extract key field types CompositeType<T> cType = (CompositeType<T>)type; this.keyFields = new ArrayList<>(type.getTotalFields()); // for each key position, find all (nested) field types String[] fieldNames = cType.getFieldNames(); this.originalKeyTypes = new TypeInformation<?>[keyPositions.length]; ArrayList<FlatFieldDescriptor> tmpList = new ArrayList<>(); for (int i = 0; i < keyPositions.length; i++) { int keyPos = keyPositions[i]; tmpList.clear(); // get all flat fields this.originalKeyTypes[i] = cType.getTypeAt(keyPos); cType.getFlatFields(fieldNames[keyPos], 0, tmpList); // check if fields are of key type for(FlatFieldDescriptor ffd : tmpList) { if(!ffd.getType().isKeyType()) { throw new InvalidProgramException("This type (" + ffd.getType() + ") cannot be used as key."); } } this.keyFields.addAll(tmpList); } }
Example 13
Source File: Keys.java From flink with Apache License 2.0 | 4 votes |
/** * Create int-based (non-nested) field position keys on a tuple type. */ public ExpressionKeys(int[] keyPositions, TypeInformation<T> type, boolean allowEmpty) { if (!type.isTupleType() || !(type instanceof CompositeType)) { throw new InvalidProgramException("Specifying keys via field positions is only valid " + "for tuple data types. Type: " + type); } if (type.getArity() == 0) { throw new InvalidProgramException("Tuple size must be greater than 0. Size: " + type.getArity()); } if (!allowEmpty && (keyPositions == null || keyPositions.length == 0)) { throw new IllegalArgumentException("The grouping fields must not be empty."); } this.keyFields = new ArrayList<>(); if (keyPositions == null || keyPositions.length == 0) { // use all tuple fields as key fields keyPositions = createIncrIntArray(type.getArity()); } else { rangeCheckFields(keyPositions, type.getArity() - 1); } checkArgument(keyPositions.length > 0, "Grouping fields can not be empty at this point"); // extract key field types CompositeType<T> cType = (CompositeType<T>)type; this.keyFields = new ArrayList<>(type.getTotalFields()); // for each key position, find all (nested) field types String[] fieldNames = cType.getFieldNames(); this.originalKeyTypes = new TypeInformation<?>[keyPositions.length]; ArrayList<FlatFieldDescriptor> tmpList = new ArrayList<>(); for (int i = 0; i < keyPositions.length; i++) { int keyPos = keyPositions[i]; tmpList.clear(); // get all flat fields this.originalKeyTypes[i] = cType.getTypeAt(keyPos); cType.getFlatFields(fieldNames[keyPos], 0, tmpList); // check if fields are of key type for(FlatFieldDescriptor ffd : tmpList) { if(!ffd.getType().isKeyType()) { throw new InvalidProgramException("This type (" + ffd.getType() + ") cannot be used as key."); } } this.keyFields.addAll(tmpList); } }
Example 14
Source File: Keys.java From flink with Apache License 2.0 | 4 votes |
/** * Create int-based (non-nested) field position keys on a tuple type. */ public ExpressionKeys(int[] keyPositions, TypeInformation<T> type, boolean allowEmpty) { if (!type.isTupleType() || !(type instanceof CompositeType)) { throw new InvalidProgramException("Specifying keys via field positions is only valid " + "for tuple data types. Type: " + type); } if (type.getArity() == 0) { throw new InvalidProgramException("Tuple size must be greater than 0. Size: " + type.getArity()); } if (!allowEmpty && (keyPositions == null || keyPositions.length == 0)) { throw new IllegalArgumentException("The grouping fields must not be empty."); } this.keyFields = new ArrayList<>(); if (keyPositions == null || keyPositions.length == 0) { // use all tuple fields as key fields keyPositions = createIncrIntArray(type.getArity()); } else { rangeCheckFields(keyPositions, type.getArity() - 1); } checkArgument(keyPositions.length > 0, "Grouping fields can not be empty at this point"); // extract key field types CompositeType<T> cType = (CompositeType<T>)type; this.keyFields = new ArrayList<>(type.getTotalFields()); // for each key position, find all (nested) field types String[] fieldNames = cType.getFieldNames(); this.originalKeyTypes = new TypeInformation<?>[keyPositions.length]; ArrayList<FlatFieldDescriptor> tmpList = new ArrayList<>(); for (int i = 0; i < keyPositions.length; i++) { int keyPos = keyPositions[i]; tmpList.clear(); // get all flat fields this.originalKeyTypes[i] = cType.getTypeAt(keyPos); cType.getFlatFields(fieldNames[keyPos], 0, tmpList); // check if fields are of key type for(FlatFieldDescriptor ffd : tmpList) { if(!ffd.getType().isKeyType()) { throw new InvalidProgramException("This type (" + ffd.getType() + ") cannot be used as key."); } } this.keyFields.addAll(tmpList); } }