/** * Constructor which is overwriting the default constructor. * @param type Types of tuple whether to check if given fields are key types. * @param fields Array of integers which are used as key for comparison. The order of indexes * is regarded in the reduce function. First index has highest priority and last index has * least priority. */ public SelectByMinFunction(TupleTypeInfo<T> type, int... fields) { this.fields = fields; // Check correctness of each position for (int field : fields) { // Is field inside array if (field < 0 || field >= type.getArity()) { throw new java.lang.IndexOutOfBoundsException( "MinReduceFunction field position " + field + " is out of range."); } // Check whether type is comparable if (!type.getTypeAt(field).isKeyType()) { throw new java.lang.IllegalArgumentException( "MinReduceFunction supports only key(Comparable) types."); } } }
/** * Constructor which is overwriting the default constructor. * @param type Types of tuple whether to check if given fields are key types. * @param fields Array of integers which are used as key for comparison. The order of indexes * is regarded in the reduce function. First index has highest priority and last index has * least priority. */ public SelectByMaxFunction(TupleTypeInfo<T> type, int... fields) { this.fields = fields; // Check correctness of each position for (int field : fields) { // Is field inside array if (field < 0 || field >= type.getArity()) { throw new IndexOutOfBoundsException( "MinReduceFunction field position " + field + " is out of range."); } // Check whether type is comparable if (!type.getTypeAt(field).isKeyType()) { throw new java.lang.IllegalArgumentException( "MinReduceFunction supports only key(Comparable) types."); } } }
SimpleTupleFieldAccessor(int pos, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.fieldType = ((TupleTypeInfo) typeInfo).getTypeAt(pos); }
RecursiveTupleFieldAccessor(int pos, FieldAccessor<R, F> innerAccessor, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); checkNotNull(innerAccessor, "innerAccessor must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.innerAccessor = innerAccessor; this.fieldType = innerAccessor.fieldType; }
/** * Configures the reader to read the CSV data and parse it to the given type. The type must be a subclass of * {@link Tuple}. The type information for the fields is obtained from the type class. The type * consequently needs to specify all generic field types of the tuple. * * @param targetType The class of the target type, needs to be a subclass of Tuple. * @return The DataSet representing the parsed CSV data. */ public <T extends Tuple> DataSource<T> tupleType(Class<T> targetType) { Preconditions.checkNotNull(targetType, "The target type class must not be null."); if (!Tuple.class.isAssignableFrom(targetType)) { throw new IllegalArgumentException("The target type must be a subclass of " + Tuple.class.getName()); } @SuppressWarnings("unchecked") TupleTypeInfo<T> typeInfo = (TupleTypeInfo<T>) TypeExtractor.createTypeInfo(targetType); CsvInputFormat<T> inputFormat = new TupleCsvInputFormat<T>(path, this.lineDelimiter, this.fieldDelimiter, typeInfo, this.includedMask); Class<?>[] classes = new Class<?>[typeInfo.getArity()]; for (int i = 0; i < typeInfo.getArity(); i++) { classes[i] = typeInfo.getTypeAt(i).getTypeClass(); } configureInputFormat(inputFormat); return new DataSource<T>(executionContext, inputFormat, typeInfo, Utils.getCallLocationName()); }
/** * @deprecated Deprecated method only kept for compatibility. */ @SuppressWarnings("unchecked") @Deprecated @PublicEvolving public <R extends Tuple> ProjectOperator<IN, R> types(Class<?>... types) { TupleTypeInfo<R> typeInfo = (TupleTypeInfo<R>) this.getResultType(); if (types.length != typeInfo.getArity()) { throw new InvalidProgramException("Provided types do not match projection."); } for (int i = 0; i < types.length; i++) { Class<?> typeClass = types[i]; if (!typeClass.equals(typeInfo.getTypeAt(i).getTypeClass())) { throw new InvalidProgramException("Provided type " + typeClass.getSimpleName() + " at position " + i + " does not match projection"); } } return (ProjectOperator<IN, R>) this; }
/** * @deprecated Deprecated method only kept for compatibility. * * @param types */ @SuppressWarnings({ "unchecked", "hiding" }) @Deprecated @PublicEvolving public <OUT extends Tuple> JoinOperator<I1, I2, OUT> types(Class<?>... types) { TupleTypeInfo<OUT> typeInfo = (TupleTypeInfo<OUT>) this.getResultType(); if (types.length != typeInfo.getArity()) { throw new InvalidProgramException("Provided types do not match projection."); } for (int i = 0; i < types.length; i++) { Class<?> typeClass = types[i]; if (!typeClass.equals(typeInfo.getTypeAt(i).getTypeClass())) { throw new InvalidProgramException("Provided type " + typeClass.getSimpleName() + " at position " + i + " does not match projection"); } } return (JoinOperator<I1, I2, OUT>) this; }
/** * @deprecated Deprecated method only kept for compatibility. */ @SuppressWarnings({ "hiding", "unchecked" }) @Deprecated @PublicEvolving public <OUT extends Tuple> CrossOperator<I1, I2, OUT> types(Class<?>... types) { TupleTypeInfo<OUT> typeInfo = (TupleTypeInfo<OUT>) this.getResultType(); if (types.length != typeInfo.getArity()) { throw new InvalidProgramException("Provided types do not match projection."); } for (int i = 0; i < types.length; i++) { Class<?> typeClass = types[i]; if (!typeClass.equals(typeInfo.getTypeAt(i).getTypeClass())) { throw new InvalidProgramException("Provided type " + typeClass.getSimpleName() + " at position " + i + " does not match projection"); } } return (CrossOperator<I1, I2, OUT>) this; }
@SuppressWarnings("unchecked") @Override @PublicEvolving public TupleSerializer<T> createSerializer(ExecutionConfig executionConfig) { if (getTypeClass() == Tuple0.class) { return (TupleSerializer<T>) Tuple0Serializer.INSTANCE; } TypeSerializer<?>[] fieldSerializers = new TypeSerializer<?>[getArity()]; for (int i = 0; i < types.length; i++) { fieldSerializers[i] = types[i].createSerializer(executionConfig); } Class<T> tupleClass = getTypeClass(); return new TupleSerializer<T>(tupleClass, fieldSerializers); }
@Test public void testMultiLevelDerivedInputFormatType() { try { // composite type { InputFormat<?, ?> format = new FinalRelativeInputFormat(); TypeInformation<?> typeInfo = TypeExtractor.getInputFormatTypes(format); assertTrue(typeInfo.isTupleType()); assertTrue(typeInfo instanceof TupleTypeInfo); @SuppressWarnings("unchecked") TupleTypeInfo<Tuple3<String, Integer, Double>> tupleInfo = (TupleTypeInfo<Tuple3<String, Integer, Double>>) typeInfo; assertEquals(3, tupleInfo.getArity()); assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tupleInfo.getTypeAt(0)); assertEquals(BasicTypeInfo.INT_TYPE_INFO, tupleInfo.getTypeAt(1)); assertEquals(BasicTypeInfo.DOUBLE_TYPE_INFO, tupleInfo.getTypeAt(2)); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
TupleTypeInfo<Tuple3<String, Short, Double>> tupleInfo = (TupleTypeInfo<Tuple3<String, Short, Double>>) typeInfo; assertEquals(3, tupleInfo.getArity()); assertEquals(BasicTypeInfo.STRING_TYPE_INFO, tupleInfo.getTypeAt(0)); assertEquals(BasicTypeInfo.SHORT_TYPE_INFO, tupleInfo.getTypeAt(1));
SimpleTupleFieldAccessor(int pos, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.fieldType = ((TupleTypeInfo) typeInfo).getTypeAt(pos); }
SimpleTupleFieldAccessor(int pos, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.fieldType = ((TupleTypeInfo) typeInfo).getTypeAt(pos); }
RecursiveTupleFieldAccessor(int pos, FieldAccessor<R, F> innerAccessor, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); checkNotNull(innerAccessor, "innerAccessor must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.innerAccessor = innerAccessor; this.fieldType = innerAccessor.fieldType; }
RecursiveTupleFieldAccessor(int pos, FieldAccessor<R, F> innerAccessor, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); checkNotNull(innerAccessor, "innerAccessor must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.innerAccessor = innerAccessor; this.fieldType = innerAccessor.fieldType; }
SimpleTupleFieldAccessor(int pos, TypeInformation<T> typeInfo) { checkNotNull(typeInfo, "typeInfo must not be null."); int arity = ((TupleTypeInfo) 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."); } this.pos = pos; this.fieldType = ((TupleTypeInfo) typeInfo).getTypeAt(pos); }
@SuppressWarnings("unchecked") @Override @PublicEvolving public TupleSerializer<T> createSerializer(ExecutionConfig executionConfig) { if (getTypeClass() == Tuple0.class) { return (TupleSerializer<T>) Tuple0Serializer.INSTANCE; } TypeSerializer<?>[] fieldSerializers = new TypeSerializer<?>[getArity()]; for (int i = 0; i < types.length; i++) { fieldSerializers[i] = types[i].createSerializer(executionConfig); } Class<T> tupleClass = getTypeClass(); return new TupleSerializer<T>(tupleClass, fieldSerializers); }
@SuppressWarnings("unchecked") @Override @PublicEvolving public TupleSerializer<T> createSerializer(ExecutionConfig executionConfig) { if (getTypeClass() == Tuple0.class) { return (TupleSerializer<T>) Tuple0Serializer.INSTANCE; } TypeSerializer<?>[] fieldSerializers = new TypeSerializer<?>[getArity()]; for (int i = 0; i < types.length; i++) { fieldSerializers[i] = types[i].createSerializer(executionConfig); } Class<T> tupleClass = getTypeClass(); return new TupleSerializer<T>(tupleClass, fieldSerializers); }