private static int[] makeFields(int[] fields, TupleTypeInfo<?> type) { int inLength = type.getArity(); // null parameter means all fields are considered if (fields == null || fields.length == 0) { fields = new int[inLength]; for (int i = 0; i < inLength; i++) { fields[i] = i; } return fields; } else { return rangeCheckAndOrderFields(fields, inLength-1); } }
public Projection(DataSet<T> ds, int[] fieldIndexes) { if(!(ds.getType() instanceof TupleTypeInfo)) { throw new UnsupportedOperationException("project() can only be applied to DataSets of Tuples."); } if(fieldIndexes.length == 0) { throw new IllegalArgumentException("project() needs to select at least one (1) field."); } else if(fieldIndexes.length > 22) { throw new IllegalArgumentException("project() may select only up to twenty-two (22) fields."); } int maxFieldIndex = ((TupleTypeInfo<?>)ds.getType()).getArity(); for(int i=0; i<fieldIndexes.length; i++) { if(fieldIndexes[i] > maxFieldIndex - 1) { throw new IndexOutOfBoundsException("Provided field index is out of bounds of input tuple."); } } this.ds = ds; this.fieldIndexes = fieldIndexes; }
public AggregateOperator<IN> and(Aggregations function, int field) { Validate.notNull(function); TupleTypeInfo<?> inType = (TupleTypeInfo<?>) getType(); if (field < 0 || field >= inType.getArity()) { throw new IllegalArgumentException("Aggregation field position is out of range."); } AggregationFunctionFactory factory = function.getFactory(); AggregationFunction<?> aggFunct = factory.createAggregationFunction(inType.getTypeAt(field).getTypeClass()); this.aggregationFunctions.add(aggFunct); this.fields.add(field); return this; }
/** * 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) { Validate.notNull(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 CsvInputFormat<T>(path); Class<?>[] classes = new Class<?>[typeInfo.getArity()]; for (int i = 0; i < typeInfo.getArity(); i++) { classes[i] = typeInfo.getTypeAt(i).getTypeClass(); } configureInputFormat(inputFormat, classes); return new DataSource<T>(executionContext, inputFormat, typeInfo); }
@Override public TupleSerializer<T> createSerializer() { TypeSerializer<?>[] fieldSerializers = new TypeSerializer<?>[getArity()]; for (int i = 0; i < types.length; i++) { fieldSerializers[i] = types[i].createSerializer(); } Class<T> tupleClass = getTypeClass(); return new TupleSerializer<T>(tupleClass, fieldSerializers); }
/** * <p> * Non grouped aggregation */ public AggregateOperator(DataSet<IN> input, Aggregations function, int field) { super(Validate.notNull(input), input.getType()); Validate.notNull(function); if (!input.getType().isTupleType()) { throw new InvalidProgramException("Aggregating on field positions is only possible on tuple data types."); } TupleTypeInfo<?> inType = (TupleTypeInfo<?>) input.getType(); if (field < 0 || field >= inType.getArity()) { throw new IllegalArgumentException("Aggregation field position is out of range."); } AggregationFunctionFactory factory = function.getFactory(); AggregationFunction<?> aggFunct = factory.createAggregationFunction(inType.getTypeAt(field).getTypeClass()); // this is the first aggregation operator after a regular data set (non grouped aggregation) this.aggregationFunctions.add(aggFunct); this.fields.add(field); this.grouping = null; }
if (field < 0 || field >= inType.getArity()) { throw new IllegalArgumentException("Aggregation field position is out of range.");