org.apache.flink.api.common.typeutils.CompositeType Java Examples
The following examples show how to use
org.apache.flink.api.common.typeutils.CompositeType.
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: JavaApiPostPass.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T> TypeComparatorFactory<?> createComparator(TypeInformation<T> typeInfo, FieldList keys, boolean[] sortOrder) { TypeComparator<T> comparator; if (typeInfo instanceof CompositeType) { comparator = ((CompositeType<T>) typeInfo).createComparator(keys.toArray(), sortOrder, 0, executionConfig); } else if (typeInfo instanceof AtomicType) { // handle grouping of atomic types comparator = ((AtomicType<T>) typeInfo).createComparator(sortOrder[0], executionConfig); } else { throw new RuntimeException("Unrecognized type: " + typeInfo); } return new RuntimeComparatorFactory<T>(comparator); }
Example #2
Source File: FieldAccessor.java From flink with Apache License 2.0 | 6 votes |
RecursiveProductFieldAccessor(int pos, TypeInformation<T> typeInfo, FieldAccessor<R, F> innerAccessor, ExecutionConfig config) { int arity = ((TupleTypeInfoBase) typeInfo).getArity(); if (pos < 0 || pos >= arity) { throw new CompositeType.InvalidFieldReferenceException( "Tried to select " + ((Integer) pos).toString() + ". field on \"" + typeInfo.toString() + "\", which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); checkNotNull(innerAccessor, "innerAccessor must not be null."); this.pos = pos; this.fieldType = ((TupleTypeInfoBase<T>) typeInfo).getTypeAt(pos); this.serializer = (TupleSerializerBase<T>) typeInfo.createSerializer(config); this.length = this.serializer.getArity(); this.fields = new Object[this.length]; this.innerAccessor = innerAccessor; }
Example #3
Source File: FieldAccessorFactory.java From flink with Apache License 2.0 | 6 votes |
private static FieldExpression decomposeFieldExpression(String fieldExpression) { Matcher matcher = PATTERN_NESTED_FIELDS_WILDCARD.matcher(fieldExpression); if (!matcher.matches()) { throw new CompositeType.InvalidFieldReferenceException("Invalid field expression \"" + fieldExpression + "\"."); } String head = matcher.group(0); if (head.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR) || head.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR_SCALA)) { throw new CompositeType.InvalidFieldReferenceException("No wildcards are allowed here."); } else { head = matcher.group(1); } String tail = matcher.group(3); return new FieldExpression(head, tail); }
Example #4
Source File: Serializers.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) { if (typeInfo instanceof GenericTypeInfo) { GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo; Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen); } else if (typeInfo instanceof CompositeType) { List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>(); getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite); for (GenericTypeInfo<?> gt : genericTypesInComposite) { Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen); } } else if (typeInfo instanceof ObjectArrayTypeInfo) { ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo; recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen); } }
Example #5
Source File: Utils.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static <T> TypeComparatorFactory<?> createComparator(TypeInformation<T> typeInfo, FieldList keys, boolean[] sortOrder, ExecutionConfig executionConfig) { TypeComparator<T> comparator; if (typeInfo instanceof CompositeType) { comparator = ((CompositeType<T>) typeInfo).createComparator(keys.toArray(), sortOrder, 0, executionConfig); } else if (typeInfo instanceof AtomicType) { // handle grouping of atomic types comparator = ((AtomicType<T>) typeInfo).createComparator(sortOrder[0], executionConfig); } else { throw new RuntimeException("Unrecognized type: " + typeInfo); } return new RuntimeComparatorFactory<>(comparator); }
Example #6
Source File: Keys.java From flink with Apache License 2.0 | 6 votes |
public static boolean isSortKey(int fieldPos, TypeInformation<?> type) { 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(fieldPos < 0 || fieldPos >= type.getArity()) { throw new IndexOutOfBoundsException("Tuple position is out of range: " + fieldPos); } TypeInformation<?> sortKeyType = ((CompositeType<?>)type).getTypeAt(fieldPos); return sortKeyType.isSortKeyType(); }
Example #7
Source File: FieldInfoUtils.java From flink with Apache License 2.0 | 6 votes |
/** * Returns field names for a given {@link TypeInformation}. If the input {@link TypeInformation} * is not a composite type, the result field name should not exist in the existingNames. * * @param inputType The TypeInformation extract the field names. * @param existingNames The existing field names for non-composite types that can not be used. * @param <A> The type of the TypeInformation. * @return An array holding the field names */ public static <A> String[] getFieldNames(TypeInformation<A> inputType, List<String> existingNames) { validateInputTypeInfo(inputType); String[] fieldNames; if (inputType instanceof CompositeType) { fieldNames = ((CompositeType<A>) inputType).getFieldNames(); } else { int i = 0; String fieldName = ATOMIC_FIELD_NAME; while ((null != existingNames) && existingNames.contains(fieldName)) { fieldName = ATOMIC_FIELD_NAME + "_" + i++; } fieldNames = new String[]{fieldName}; } if (Arrays.asList(fieldNames).contains("*")) { throw new TableException("Field name can not be '*'."); } return fieldNames; }
Example #8
Source File: JavaApiPostPass.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T> TypeComparatorFactory<?> createComparator(TypeInformation<T> typeInfo, FieldList keys, boolean[] sortOrder) { TypeComparator<T> comparator; if (typeInfo instanceof CompositeType) { comparator = ((CompositeType<T>) typeInfo).createComparator(keys.toArray(), sortOrder, 0, executionConfig); } else if (typeInfo instanceof AtomicType) { // handle grouping of atomic types comparator = ((AtomicType<T>) typeInfo).createComparator(sortOrder[0], executionConfig); } else { throw new RuntimeException("Unrecognized type: " + typeInfo); } return new RuntimeComparatorFactory<T>(comparator); }
Example #9
Source File: Keys.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static boolean isSortKey(String fieldExpr, TypeInformation<?> type) { TypeInformation<?> sortKeyType; fieldExpr = fieldExpr.trim(); if (SELECT_ALL_CHAR.equals(fieldExpr) || SELECT_ALL_CHAR_SCALA.equals(fieldExpr)) { sortKeyType = type; } else { if (type instanceof CompositeType) { sortKeyType = ((CompositeType<?>) type).getTypeAt(fieldExpr); } else { throw new InvalidProgramException( "Field expression must be equal to '" + SELECT_ALL_CHAR + "' or '" + SELECT_ALL_CHAR_SCALA + "' for atomic types."); } } return sortKeyType.isSortKeyType(); }
Example #10
Source File: OuterJoinOperatorBase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T> TypeComparator<T> buildComparatorFor(int input, ExecutionConfig executionConfig, TypeInformation<T> typeInformation) { TypeComparator<T> comparator; if (typeInformation instanceof AtomicType) { comparator = ((AtomicType<T>) typeInformation).createComparator(true, executionConfig); } else if (typeInformation instanceof CompositeType) { int[] keyPositions = getKeyColumns(input); boolean[] orders = new boolean[keyPositions.length]; Arrays.fill(orders, true); comparator = ((CompositeType<T>) typeInformation).createComparator(keyPositions, orders, 0, executionConfig); } else { throw new RuntimeException("Type information for input of type " + typeInformation.getClass() .getCanonicalName() + " is not supported. Could not generate a comparator."); } return comparator; }
Example #11
Source File: SortPartitionOperatorBase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override protected List<IN> executeOnCollections(List<IN> inputData, RuntimeContext runtimeContext, ExecutionConfig executionConfig) { TypeInformation<IN> inputType = getInput().getOperatorInfo().getOutputType(); int[] sortColumns = this.partitionOrdering.getFieldPositions(); boolean[] sortOrderings = this.partitionOrdering.getFieldSortDirections(); final TypeComparator<IN> sortComparator; if (inputType instanceof CompositeType) { sortComparator = ((CompositeType<IN>) inputType).createComparator(sortColumns, sortOrderings, 0, executionConfig); } else if (inputType instanceof AtomicType) { sortComparator = ((AtomicType) inputType).createComparator(sortOrderings[0], executionConfig); } else { throw new UnsupportedOperationException("Partition sorting does not support type "+inputType+" yet."); } Collections.sort(inputData, new Comparator<IN>() { @Override public int compare(IN o1, IN o2) { return sortComparator.compare(o1, o2); } }); return inputData; }
Example #12
Source File: Keys.java From flink with Apache License 2.0 | 6 votes |
public static boolean isSortKey(int fieldPos, TypeInformation<?> type) { 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(fieldPos < 0 || fieldPos >= type.getArity()) { throw new IndexOutOfBoundsException("Tuple position is out of range: " + fieldPos); } TypeInformation<?> sortKeyType = ((CompositeType<?>)type).getTypeAt(fieldPos); return sortKeyType.isSortKeyType(); }
Example #13
Source File: JavaApiPostPass.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private <T> TypeComparatorFactory<?> createComparator(TypeInformation<T> typeInfo, FieldList keys, boolean[] sortOrder) { TypeComparator<T> comparator; if (typeInfo instanceof CompositeType) { comparator = ((CompositeType<T>) typeInfo).createComparator(keys.toArray(), sortOrder, 0, executionConfig); } else if (typeInfo instanceof AtomicType) { // handle grouping of atomic types comparator = ((AtomicType<T>) typeInfo).createComparator(sortOrder[0], executionConfig); } else { throw new RuntimeException("Unrecognized type: " + typeInfo); } return new RuntimeComparatorFactory<T>(comparator); }
Example #14
Source File: FieldAccessor.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
RecursiveProductFieldAccessor(int pos, TypeInformation<T> typeInfo, FieldAccessor<R, F> innerAccessor, ExecutionConfig config) { int arity = ((TupleTypeInfoBase) typeInfo).getArity(); if (pos < 0 || pos >= arity) { throw new CompositeType.InvalidFieldReferenceException( "Tried to select " + ((Integer) pos).toString() + ". field on \"" + typeInfo.toString() + "\", which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); checkNotNull(innerAccessor, "innerAccessor must not be null."); this.pos = pos; this.fieldType = ((TupleTypeInfoBase<T>) typeInfo).getTypeAt(pos); this.serializer = (TupleSerializerBase<T>) typeInfo.createSerializer(config); this.length = this.serializer.getArity(); this.fields = new Object[this.length]; this.innerAccessor = innerAccessor; }
Example #15
Source File: Serializers.java From flink with Apache License 2.0 | 6 votes |
public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) { if (typeInfo instanceof GenericTypeInfo) { GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo; Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen); } else if (typeInfo instanceof CompositeType) { List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>(); getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite); for (GenericTypeInfo<?> gt : genericTypesInComposite) { Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen); } } else if (typeInfo instanceof ObjectArrayTypeInfo) { ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo; recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen); } }
Example #16
Source File: Keys.java From flink with Apache License 2.0 | 6 votes |
public SelectorFunctionKeys(KeySelector<T, K> keyExtractor, TypeInformation<T> inputType, TypeInformation<K> keyType) { if (keyExtractor == null) { throw new NullPointerException("Key extractor must not be null."); } if (keyType == null) { throw new NullPointerException("Key type must not be null."); } if (!keyType.isKeyType()) { throw new InvalidProgramException("Return type "+keyType+" of KeySelector "+keyExtractor.getClass()+" is not a valid key type"); } this.keyExtractor = keyExtractor; this.inputType = inputType; this.keyType = keyType; this.originalKeyTypes = new TypeInformation[] {keyType}; if (keyType instanceof CompositeType) { this.keyFields = ((CompositeType<T>)keyType).getFlatFields(ExpressionKeys.SELECT_ALL_CHAR); } else { this.keyFields = new ArrayList<>(1); this.keyFields.add(new FlatFieldDescriptor(0, keyType)); } }
Example #17
Source File: Serializers.java From flink with Apache License 2.0 | 6 votes |
public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) { if (typeInfo instanceof GenericTypeInfo) { GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo; Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen); } else if (typeInfo instanceof CompositeType) { List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>(); getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite); for (GenericTypeInfo<?> gt : genericTypesInComposite) { Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen); } } else if (typeInfo instanceof ObjectArrayTypeInfo) { ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo; recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen); } }
Example #18
Source File: FieldAccessorFactory.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static FieldExpression decomposeFieldExpression(String fieldExpression) { Matcher matcher = PATTERN_NESTED_FIELDS_WILDCARD.matcher(fieldExpression); if (!matcher.matches()) { throw new CompositeType.InvalidFieldReferenceException("Invalid field expression \"" + fieldExpression + "\"."); } String head = matcher.group(0); if (head.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR) || head.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR_SCALA)) { throw new CompositeType.InvalidFieldReferenceException("No wildcards are allowed here."); } else { head = matcher.group(1); } String tail = matcher.group(3); return new FieldExpression(head, tail); }
Example #19
Source File: SemanticPropUtil.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static TypeInformation<?> getExpressionTypeInformation(String fieldStr, TypeInformation<?> typeInfo) { Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr); if (wildcardMatcher.matches()) { return typeInfo; } else { Matcher expMatcher = PATTERN_FIELD.matcher(fieldStr); if (!expMatcher.matches()) { throw new InvalidFieldReferenceException("Invalid field expression \"" + fieldStr + "\"."); } if (typeInfo instanceof CompositeType<?>) { return ((CompositeType<?>) typeInfo).getTypeAt(expMatcher.group(1)); } else { throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ")."); } } }
Example #20
Source File: Keys.java From flink with Apache License 2.0 | 6 votes |
public SelectorFunctionKeys(KeySelector<T, K> keyExtractor, TypeInformation<T> inputType, TypeInformation<K> keyType) { if (keyExtractor == null) { throw new NullPointerException("Key extractor must not be null."); } if (keyType == null) { throw new NullPointerException("Key type must not be null."); } if (!keyType.isKeyType()) { throw new InvalidProgramException("Return type "+keyType+" of KeySelector "+keyExtractor.getClass()+" is not a valid key type"); } this.keyExtractor = keyExtractor; this.inputType = inputType; this.keyType = keyType; this.originalKeyTypes = new TypeInformation[] {keyType}; if (keyType instanceof CompositeType) { this.keyFields = ((CompositeType<T>)keyType).getFlatFields(ExpressionKeys.SELECT_ALL_CHAR); } else { this.keyFields = new ArrayList<>(1); this.keyFields.add(new FlatFieldDescriptor(0, keyType)); } }
Example #21
Source File: FieldAccessorFactory.java From flink with Apache License 2.0 | 6 votes |
private static FieldExpression decomposeFieldExpression(String fieldExpression) { Matcher matcher = PATTERN_NESTED_FIELDS_WILDCARD.matcher(fieldExpression); if (!matcher.matches()) { throw new CompositeType.InvalidFieldReferenceException("Invalid field expression \"" + fieldExpression + "\"."); } String head = matcher.group(0); if (head.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR) || head.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR_SCALA)) { throw new CompositeType.InvalidFieldReferenceException("No wildcards are allowed here."); } else { head = matcher.group(1); } String tail = matcher.group(3); return new FieldExpression(head, tail); }
Example #22
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 #23
Source File: ProjectOperator.java From flink with Apache License 2.0 | 5 votes |
@Override protected org.apache.flink.api.common.operators.base.MapOperatorBase<IN, OUT, MapFunction<IN, OUT>> translateToDataFlow(Operator<IN> input) { String name = getName() != null ? getName() : "Projection " + Arrays.toString(fields); // create operator PlanProjectOperator<IN, OUT> ppo = new PlanProjectOperator<IN, OUT>(fields, name, getInputType(), getResultType(), context.getConfig()); // set input ppo.setInput(input); // set parallelism ppo.setParallelism(this.getParallelism()); ppo.setSemanticProperties(SemanticPropUtil.createProjectionPropertiesSingle(fields, (CompositeType<?>) getInputType())); return ppo; }
Example #24
Source File: SemanticPropUtil.java From flink with Apache License 2.0 | 5 votes |
private static List<FlatFieldDescriptor> getFlatFields(String fieldStr, TypeInformation<?> typeInfo) { if (typeInfo instanceof CompositeType<?>) { return ((CompositeType<?>) typeInfo).getFlatFields(fieldStr); } else { Matcher wildcardMatcher = PATTERN_WILDCARD.matcher(fieldStr); if (wildcardMatcher.matches()) { return Collections.singletonList(new FlatFieldDescriptor(0, typeInfo)); } else { throw new InvalidFieldReferenceException("Nested field expression \"" + fieldStr + "\" not possible on atomic type (" + typeInfo + ")."); } } }
Example #25
Source File: JoinOperatorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testJoinKeyNestedTuplesWithCustom() { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<Tuple5<CustomType, Long, String, Long, Integer>> ds1 = env.fromCollection(emptyNestedCustomTupleData, nestedCustomTupleTypeInfo); DataSet<Tuple5<Integer, Long, String, Long, Integer>> ds2 = env.fromCollection(emptyTupleData, tupleTypeInfo); try { TypeInformation<?> t = ds1.join(ds2).where("f0.myInt").equalTo(4).getType(); assertTrue("not a composite type", t instanceof CompositeType); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
Example #26
Source File: BaseRowTypeInfo.java From flink with Apache License 2.0 | 5 votes |
@Override public <X> TypeInformation<X> getTypeAt(String fieldExpression) { Matcher matcher = PATTERN_NESTED_FIELDS.matcher(fieldExpression); if (!matcher.matches()) { if (fieldExpression.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR) || fieldExpression.equals(Keys.ExpressionKeys.SELECT_ALL_CHAR_SCALA)) { throw new InvalidFieldReferenceException("Wildcard expressions are not allowed here."); } else { throw new InvalidFieldReferenceException( "Invalid format of Row field expression \"" + fieldExpression + "\"."); } } String field = matcher.group(1); Matcher intFieldMatcher = PATTERN_INT_FIELD.matcher(field); int fieldIndex; if (intFieldMatcher.matches()) { // field expression is an integer fieldIndex = Integer.valueOf(field); } else { fieldIndex = this.getFieldIndex(field); } // fetch the field type will throw exception if the index is illegal TypeInformation<X> fieldType = this.getTypeAt(fieldIndex); String tail = matcher.group(3); if (tail == null) { // found the type return fieldType; } else { if (fieldType instanceof CompositeType) { return ((CompositeType<?>) fieldType).getTypeAt(tail); } else { throw new InvalidFieldReferenceException( "Nested field expression \"" + tail + "\" not possible on atomic type " + fieldType + "."); } } }
Example #27
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 #28
Source File: FieldAccessorTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test(expected = CompositeType.InvalidFieldReferenceException.class) public void testIllegalFlatTuple() { Tuple2<String, Integer> t = Tuple2.of("aa", 5); TupleTypeInfo<Tuple2<String, Integer>> tpeInfo = (TupleTypeInfo<Tuple2<String, Integer>>) TypeExtractor.getForObject(t); FieldAccessorFactory.getAccessor(tpeInfo, "illegal", null); }
Example #29
Source File: CoGroupOperatorBase.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private <T> TypeComparator<T> getTypeComparator(ExecutionConfig executionConfig, TypeInformation<T> inputType, int[] inputKeys, boolean[] inputSortDirections) { if (inputType instanceof CompositeType) { return ((CompositeType<T>) inputType).createComparator(inputKeys, inputSortDirections, 0, executionConfig); } else if (inputType instanceof AtomicType) { return ((AtomicType<T>) inputType).createComparator(inputSortDirections[0], executionConfig); } throw new InvalidProgramException("Input type of coGroup must be one of composite types or atomic types."); }
Example #30
Source File: FieldAccessor.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public ArrayFieldAccessor(int pos, TypeInformation typeInfo) { if (pos < 0) { throw new CompositeType.InvalidFieldReferenceException("The " + ((Integer) pos).toString() + ". field selected on" + " an array, which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); this.pos = pos; this.fieldType = BasicTypeInfo.getInfoFor(typeInfo.getTypeClass().getComponentType()); }