Java Code Examples for org.apache.flink.util.Preconditions#checkElementIndex()

The following examples show how to use org.apache.flink.util.Preconditions#checkElementIndex() . 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: ProjectOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
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 > Tuple.MAX_ARITY - 1) {
				throw new IllegalArgumentException(
					"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
			}

			int maxFieldIndex = ds.getType().getArity();
			for (int fieldIndexe : fieldIndexes) {
				Preconditions.checkElementIndex(fieldIndexe, maxFieldIndex);
			}

			this.ds = ds;
			this.fieldIndexes = fieldIndexes;
		}
 
Example 2
Source File: StreamProjection.java    From flink with Apache License 2.0 6 votes vote down vote up
protected StreamProjection(DataStream<IN> dataStream, int[] fieldIndexes) {
	if (!dataStream.getType().isTupleType()) {
		throw new RuntimeException("Only Tuple DataStreams can be projected");
	}
	if (fieldIndexes.length == 0) {
		throw new IllegalArgumentException("project() needs to select at least one (1) field.");
	} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
		throw new IllegalArgumentException(
				"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
	}

	int maxFieldIndex = (dataStream.getType()).getArity();
	for (int i = 0; i < fieldIndexes.length; i++) {
		Preconditions.checkElementIndex(fieldIndexes[i], maxFieldIndex);
	}

	this.dataStream = dataStream;
	this.fieldIndexes = fieldIndexes;
}
 
Example 3
Source File: StreamProjection.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
protected StreamProjection(DataStream<IN> dataStream, int[] fieldIndexes) {
	if (!dataStream.getType().isTupleType()) {
		throw new RuntimeException("Only Tuple DataStreams can be projected");
	}
	if (fieldIndexes.length == 0) {
		throw new IllegalArgumentException("project() needs to select at least one (1) field.");
	} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
		throw new IllegalArgumentException(
				"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
	}

	int maxFieldIndex = (dataStream.getType()).getArity();
	for (int i = 0; i < fieldIndexes.length; i++) {
		Preconditions.checkElementIndex(fieldIndexes[i], maxFieldIndex);
	}

	this.dataStream = dataStream;
	this.fieldIndexes = fieldIndexes;
}
 
Example 4
Source File: StreamProjection.java    From flink with Apache License 2.0 6 votes vote down vote up
protected StreamProjection(DataStream<IN> dataStream, int[] fieldIndexes) {
	if (!dataStream.getType().isTupleType()) {
		throw new RuntimeException("Only Tuple DataStreams can be projected");
	}
	if (fieldIndexes.length == 0) {
		throw new IllegalArgumentException("project() needs to select at least one (1) field.");
	} else if (fieldIndexes.length > Tuple.MAX_ARITY - 1) {
		throw new IllegalArgumentException(
				"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
	}

	int maxFieldIndex = (dataStream.getType()).getArity();
	for (int i = 0; i < fieldIndexes.length; i++) {
		Preconditions.checkElementIndex(fieldIndexes[i], maxFieldIndex);
	}

	this.dataStream = dataStream;
	this.fieldIndexes = fieldIndexes;
}
 
Example 5
Source File: ProjectOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
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 > Tuple.MAX_ARITY - 1) {
				throw new IllegalArgumentException(
					"project() may select only up to (" + (Tuple.MAX_ARITY - 1) + ") fields.");
			}

			int maxFieldIndex = ds.getType().getArity();
			for (int fieldIndexe : fieldIndexes) {
				Preconditions.checkElementIndex(fieldIndexe, maxFieldIndex);
			}

			this.ds = ds;
			this.fieldIndexes = fieldIndexes;
		}
 
Example 6
Source File: SourceUtils.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Arguments check.
 *
 * @param sourceName    the source name
 * @param consumerCount the consumer count
 * @param consumerIndex the consumer index
 */
protected static void argumentsCheck(
		String sourceName,
		int consumerCount,
		int consumerIndex) {
	Preconditions.checkArgument(consumerCount > 0,
			"Source: [" + sourceName + "], Consumer count: " + consumerCount + " must be more than 0.");
	Preconditions.checkElementIndex(consumerIndex, consumerCount,
			"Source: [" + sourceName + "], Consumer index: " + consumerIndex + " is out of range of consumer count: " + consumerCount);
}
 
Example 7
Source File: JoinOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectJoin transformation and adds fields of the first join input.
 *
 * <p>If the first join input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the first join input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectSecond(int...)}.
 *
 * @param firstFieldIndexes If the first input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended JoinProjection.
 *
 * @see Tuple
 * @see DataSet
 */
protected JoinProjection<I1, I2> projectFirst(int... firstFieldIndexes) {

	boolean isFirstTuple;

	isFirstTuple = ds1.getType() instanceof TupleTypeInfo && firstFieldIndexes.length > 0;

	if (!isFirstTuple && firstFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() without arguments to include it.");
	} else if (firstFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isFirstTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + firstFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + firstFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs1;
		for (int i = 0; i < firstFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(firstFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = true;
			this.fieldIndexes[offset + i] = firstFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = true;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 8
Source File: JoinOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
public JoinProjection(DataSet<I1> ds1, DataSet<I2> ds2, Keys<I1> keys1, Keys<I2> keys2, JoinHint hint, int[] firstFieldIndexes, int[] secondFieldIndexes) {
	this.ds1 = ds1;
	this.ds2 = ds2;
	this.keys1 = keys1;
	this.keys2 = keys2;
	this.hint = hint;

	boolean isFirstTuple;
	boolean isSecondTuple;

	if (ds1.getType() instanceof TupleTypeInfo) {
		numFieldsDs1 = ds1.getType().getArity();
		isFirstTuple = true;
	} else {
		numFieldsDs1 = 1;
		isFirstTuple = false;
	}
	if (ds2.getType() instanceof TupleTypeInfo) {
		numFieldsDs2 = ds2.getType().getArity();
		isSecondTuple = true;
	} else {
		numFieldsDs2 = 1;
		isSecondTuple = false;
	}

	boolean isTuple;
	boolean firstInput;

	if (firstFieldIndexes != null && secondFieldIndexes == null) {
		// index array for first input is provided
		firstInput = true;
		isTuple = isFirstTuple;
		this.fieldIndexes = firstFieldIndexes;

		if (this.fieldIndexes.length == 0) {
			// no indexes provided, treat tuple as regular object
			isTuple = false;
		}
	} else if (firstFieldIndexes == null && secondFieldIndexes != null) {
		// index array for second input is provided
		firstInput = false;
		isTuple = isSecondTuple;
		this.fieldIndexes = secondFieldIndexes;

		if (this.fieldIndexes.length == 0) {
			// no indexes provided, treat tuple as regular object
			isTuple = false;
		}
	} else if (firstFieldIndexes == null && secondFieldIndexes == null) {
		throw new IllegalArgumentException("You must provide at least one field index array.");
	} else {
		throw new IllegalArgumentException("You must provide at most one field index array.");
	}

	if (!isTuple && this.fieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() (or projectSecond()) without arguments to include it.");
	} else if (this.fieldIndexes.length > 22) {
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields.");
	}

	if (isTuple) {
		this.isFieldInFirst = new boolean[this.fieldIndexes.length];

		// check field indexes and adapt to position in tuple
		int maxFieldIndex = firstInput ? numFieldsDs1 : numFieldsDs2;
		for (int i = 0; i < this.fieldIndexes.length; i++) {
			Preconditions.checkElementIndex(this.fieldIndexes[i], maxFieldIndex);

			if (firstInput) {
				this.isFieldInFirst[i] = true;
			} else {
				this.isFieldInFirst[i] = false;
			}
		}
	} else {
		this.isFieldInFirst = new boolean[]{firstInput};
		this.fieldIndexes = new int[]{-1};
	}

}
 
Example 9
Source File: CheckpointsTest.java    From flink-statefun with Apache License 2.0 4 votes vote down vote up
LoggerState state(int loggerIndex) {
  Preconditions.checkElementIndex(loggerIndex, loggers.size());
  FakeLogger logger = loggers.get(loggerIndex);
  return logger.state;
}
 
Example 10
Source File: CrossOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
public CrossProjection(DataSet<I1> ds1, DataSet<I2> ds2, int[] firstFieldIndexes, int[] secondFieldIndexes, CrossHint hint) {

			this.ds1 = ds1;
			this.ds2 = ds2;
			this.hint = hint;

			boolean isFirstTuple;
			boolean isSecondTuple;

			if (ds1.getType() instanceof TupleTypeInfo) {
				numFieldsDs1 = ((TupleTypeInfo<?>) ds1.getType()).getArity();
				isFirstTuple = true;
			} else {
				numFieldsDs1 = 1;
				isFirstTuple = false;
			}
			if (ds2.getType() instanceof TupleTypeInfo) {
				numFieldsDs2 = ((TupleTypeInfo<?>) ds2.getType()).getArity();
				isSecondTuple = true;
			} else {
				numFieldsDs2 = 1;
				isSecondTuple = false;
			}

			boolean isTuple;
			boolean firstInput;

			if (firstFieldIndexes != null && secondFieldIndexes == null) {
				// index array for first input is provided
				firstInput = true;
				isTuple = isFirstTuple;
				this.fieldIndexes = firstFieldIndexes;

				if (this.fieldIndexes.length == 0) {
					// no indexes provided, treat tuple as regular object
					isTuple = false;
				}
			} else if (firstFieldIndexes == null && secondFieldIndexes != null) {
				// index array for second input is provided
				firstInput = false;
				isTuple = isSecondTuple;
				this.fieldIndexes = secondFieldIndexes;

				if (this.fieldIndexes.length == 0) {
					// no indexes provided, treat tuple as regular object
					isTuple = false;
				}
			} else if (firstFieldIndexes == null && secondFieldIndexes == null) {
				throw new IllegalArgumentException("You must provide at least one field index array.");
			} else {
				throw new IllegalArgumentException("You must provide at most one field index array.");
			}

			if (!isTuple && this.fieldIndexes.length != 0) {
				// field index provided for non-Tuple input
				throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() (or projectSecond()) without arguments to include it.");
			} else if (this.fieldIndexes.length > 22) {
				throw new IllegalArgumentException("You may select only up to twenty-two (22) fields.");
			}

			if (isTuple) {
				this.isFieldInFirst = new boolean[this.fieldIndexes.length];

				// check field indexes and adapt to position in tuple
				int maxFieldIndex = firstInput ? numFieldsDs1 : numFieldsDs2;
				for (int i = 0; i < this.fieldIndexes.length; i++) {
					Preconditions.checkElementIndex(this.fieldIndexes[i], maxFieldIndex);

					if (firstInput) {
						this.isFieldInFirst[i] = true;
					} else {
						this.isFieldInFirst[i] = false;
					}
				}
			} else {
				this.isFieldInFirst = new boolean[]{firstInput};
				this.fieldIndexes = new int[]{-1};
			}

		}
 
Example 11
Source File: CrossOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectCross transformation and adds fields of the second cross input.
 *
 * <p>If the second cross input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the second cross input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectSecond(int...)}.
 *
 * @param secondFieldIndexes If the second input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended CrossProjection.
 *
 * @see Tuple
 * @see DataSet
 * @see org.apache.flink.api.java.operators.CrossOperator.CrossProjection
 * @see org.apache.flink.api.java.operators.CrossOperator.ProjectCross
 */
protected CrossProjection<I1, I2> projectSecond(int... secondFieldIndexes) {

	boolean isSecondTuple;

	if (ds2.getType() instanceof TupleTypeInfo && secondFieldIndexes.length > 0) {
		isSecondTuple = true;
	} else {
		isSecondTuple = false;
	}

	if (!isSecondTuple && secondFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectSecond() without arguments to include it.");
	} else if (secondFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isSecondTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + secondFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + secondFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs2;
		for (int i = 0; i < secondFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(secondFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = false;
			this.fieldIndexes[offset + i] = secondFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = false;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 12
Source File: CrossOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectCross transformation and adds fields of the second cross input.
 *
 * <p>If the second cross input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the second cross input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectSecond(int...)}.
 *
 * @param secondFieldIndexes If the second input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended CrossProjection.
 *
 * @see Tuple
 * @see DataSet
 * @see org.apache.flink.api.java.operators.CrossOperator.CrossProjection
 * @see org.apache.flink.api.java.operators.CrossOperator.ProjectCross
 */
protected CrossProjection<I1, I2> projectSecond(int... secondFieldIndexes) {

	boolean isSecondTuple;

	if (ds2.getType() instanceof TupleTypeInfo && secondFieldIndexes.length > 0) {
		isSecondTuple = true;
	} else {
		isSecondTuple = false;
	}

	if (!isSecondTuple && secondFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectSecond() without arguments to include it.");
	} else if (secondFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isSecondTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + secondFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + secondFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs2;
		for (int i = 0; i < secondFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(secondFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = false;
			this.fieldIndexes[offset + i] = secondFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = false;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 13
Source File: CrossOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
public CrossProjection(DataSet<I1> ds1, DataSet<I2> ds2, int[] firstFieldIndexes, int[] secondFieldIndexes, CrossHint hint) {

			this.ds1 = ds1;
			this.ds2 = ds2;
			this.hint = hint;

			boolean isFirstTuple;
			boolean isSecondTuple;

			if (ds1.getType() instanceof TupleTypeInfo) {
				numFieldsDs1 = ((TupleTypeInfo<?>) ds1.getType()).getArity();
				isFirstTuple = true;
			} else {
				numFieldsDs1 = 1;
				isFirstTuple = false;
			}
			if (ds2.getType() instanceof TupleTypeInfo) {
				numFieldsDs2 = ((TupleTypeInfo<?>) ds2.getType()).getArity();
				isSecondTuple = true;
			} else {
				numFieldsDs2 = 1;
				isSecondTuple = false;
			}

			boolean isTuple;
			boolean firstInput;

			if (firstFieldIndexes != null && secondFieldIndexes == null) {
				// index array for first input is provided
				firstInput = true;
				isTuple = isFirstTuple;
				this.fieldIndexes = firstFieldIndexes;

				if (this.fieldIndexes.length == 0) {
					// no indexes provided, treat tuple as regular object
					isTuple = false;
				}
			} else if (firstFieldIndexes == null && secondFieldIndexes != null) {
				// index array for second input is provided
				firstInput = false;
				isTuple = isSecondTuple;
				this.fieldIndexes = secondFieldIndexes;

				if (this.fieldIndexes.length == 0) {
					// no indexes provided, treat tuple as regular object
					isTuple = false;
				}
			} else if (firstFieldIndexes == null && secondFieldIndexes == null) {
				throw new IllegalArgumentException("You must provide at least one field index array.");
			} else {
				throw new IllegalArgumentException("You must provide at most one field index array.");
			}

			if (!isTuple && this.fieldIndexes.length != 0) {
				// field index provided for non-Tuple input
				throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() (or projectSecond()) without arguments to include it.");
			} else if (this.fieldIndexes.length > 22) {
				throw new IllegalArgumentException("You may select only up to twenty-two (22) fields.");
			}

			if (isTuple) {
				this.isFieldInFirst = new boolean[this.fieldIndexes.length];

				// check field indexes and adapt to position in tuple
				int maxFieldIndex = firstInput ? numFieldsDs1 : numFieldsDs2;
				for (int i = 0; i < this.fieldIndexes.length; i++) {
					Preconditions.checkElementIndex(this.fieldIndexes[i], maxFieldIndex);

					if (firstInput) {
						this.isFieldInFirst[i] = true;
					} else {
						this.isFieldInFirst[i] = false;
					}
				}
			} else {
				this.isFieldInFirst = new boolean[]{firstInput};
				this.fieldIndexes = new int[]{-1};
			}

		}
 
Example 14
Source File: JoinOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectJoin transformation and adds fields of the second join input.
 *
 * <p>If the second join input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the second join input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectSecond(int...)}.
 *
 * @param secondFieldIndexes If the second input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended JoinProjection.
 *
 * @see Tuple
 * @see DataSet
 */
protected JoinProjection<I1, I2> projectSecond(int... secondFieldIndexes) {

	boolean isSecondTuple;

	isSecondTuple = ds2.getType() instanceof TupleTypeInfo && secondFieldIndexes.length > 0;

	if (!isSecondTuple && secondFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectSecond() without arguments to include it.");
	} else if (secondFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isSecondTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + secondFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + secondFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs2;
		for (int i = 0; i < secondFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(secondFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = false;
			this.fieldIndexes[offset + i] = secondFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = false;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 15
Source File: CrossOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectCross transformation and adds fields of the second cross input.
 *
 * <p>If the second cross input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the second cross input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectSecond(int...)}.
 *
 * @param secondFieldIndexes If the second input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended CrossProjection.
 *
 * @see Tuple
 * @see DataSet
 * @see org.apache.flink.api.java.operators.CrossOperator.CrossProjection
 * @see org.apache.flink.api.java.operators.CrossOperator.ProjectCross
 */
protected CrossProjection<I1, I2> projectSecond(int... secondFieldIndexes) {

	boolean isSecondTuple;

	if (ds2.getType() instanceof TupleTypeInfo && secondFieldIndexes.length > 0) {
		isSecondTuple = true;
	} else {
		isSecondTuple = false;
	}

	if (!isSecondTuple && secondFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectSecond() without arguments to include it.");
	} else if (secondFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isSecondTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + secondFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + secondFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs2;
		for (int i = 0; i < secondFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(secondFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = false;
			this.fieldIndexes[offset + i] = secondFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = false;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 16
Source File: CrossOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectCross transformation and adds fields of the first cross input.
 *
 * <p>If the first cross input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the first cross input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.CrossOperator.CrossProjection#projectSecond(int...)}.
 *
 * @param firstFieldIndexes If the first input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended CrossProjection.
 *
 * @see Tuple
 * @see DataSet
 * @see org.apache.flink.api.java.operators.CrossOperator.CrossProjection
 * @see org.apache.flink.api.java.operators.CrossOperator.ProjectCross
 */
protected CrossProjection<I1, I2> projectFirst(int... firstFieldIndexes) {

	boolean isFirstTuple;

	if (ds1.getType() instanceof TupleTypeInfo && firstFieldIndexes.length > 0) {
		isFirstTuple = true;
	} else {
		isFirstTuple = false;
	}

	if (!isFirstTuple && firstFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() without arguments to include it.");
	} else if (firstFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isFirstTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + firstFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + firstFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs1;
		for (int i = 0; i < firstFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(firstFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = true;
			this.fieldIndexes[offset + i] = firstFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = true;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 17
Source File: JoinOperator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectJoin transformation and adds fields of the first join input.
 *
 * <p>If the first join input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the first join input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectSecond(int...)}.
 *
 * @param firstFieldIndexes If the first input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended JoinProjection.
 *
 * @see Tuple
 * @see DataSet
 */
protected JoinProjection<I1, I2> projectFirst(int... firstFieldIndexes) {

	boolean isFirstTuple;

	isFirstTuple = ds1.getType() instanceof TupleTypeInfo && firstFieldIndexes.length > 0;

	if (!isFirstTuple && firstFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() without arguments to include it.");
	} else if (firstFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isFirstTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + firstFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + firstFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs1;
		for (int i = 0; i < firstFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(firstFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = true;
			this.fieldIndexes[offset + i] = firstFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = true;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 18
Source File: JoinOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectJoin transformation and adds fields of the second join input.
 *
 * <p>If the second join input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the second join input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectSecond(int...)}.
 *
 * @param secondFieldIndexes If the second input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended JoinProjection.
 *
 * @see Tuple
 * @see DataSet
 */
protected JoinProjection<I1, I2> projectSecond(int... secondFieldIndexes) {

	boolean isSecondTuple;

	isSecondTuple = ds2.getType() instanceof TupleTypeInfo && secondFieldIndexes.length > 0;

	if (!isSecondTuple && secondFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectSecond() without arguments to include it.");
	} else if (secondFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isSecondTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + secondFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + secondFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs2;
		for (int i = 0; i < secondFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(secondFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = false;
			this.fieldIndexes[offset + i] = secondFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = false;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 19
Source File: JoinOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Continues a ProjectJoin transformation and adds fields of the first join input.
 *
 * <p>If the first join input is a {@link Tuple} {@link DataSet}, fields can be selected by their index.
 * If the first join input is not a Tuple DataSet, no parameters should be passed.
 *
 * <p>Fields of the first and second input can be added by chaining the method calls of
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectFirst(int...)} and
 * {@link org.apache.flink.api.java.operators.JoinOperator.JoinProjection#projectSecond(int...)}.
 *
 * @param firstFieldIndexes If the first input is a Tuple DataSet, the indexes of the selected fields.
 * 					   For a non-Tuple DataSet, do not provide parameters.
 * 					   The order of fields in the output tuple is defined by to the order of field indexes.
 * @return An extended JoinProjection.
 *
 * @see Tuple
 * @see DataSet
 */
protected JoinProjection<I1, I2> projectFirst(int... firstFieldIndexes) {

	boolean isFirstTuple;

	isFirstTuple = ds1.getType() instanceof TupleTypeInfo && firstFieldIndexes.length > 0;

	if (!isFirstTuple && firstFieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() without arguments to include it.");
	} else if (firstFieldIndexes.length > (22 - this.fieldIndexes.length)) {
		// to many field indexes provided
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields in total.");
	}

	int offset = this.fieldIndexes.length;

	if (isFirstTuple) {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + firstFieldIndexes.length);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + firstFieldIndexes.length);

		// copy field indexes
		int maxFieldIndex = numFieldsDs1;
		for (int i = 0; i < firstFieldIndexes.length; i++) {
			// check if indexes in range
			Preconditions.checkElementIndex(firstFieldIndexes[i], maxFieldIndex);

			this.isFieldInFirst[offset + i] = true;
			this.fieldIndexes[offset + i] = firstFieldIndexes[i];
		}
	} else {
		// extend index and flag arrays
		this.fieldIndexes = Arrays.copyOf(this.fieldIndexes, this.fieldIndexes.length + 1);
		this.isFieldInFirst = Arrays.copyOf(this.isFieldInFirst, this.isFieldInFirst.length + 1);

		// add input object to output tuple
		this.isFieldInFirst[offset] = true;
		this.fieldIndexes[offset] = -1;
	}

	return this;
}
 
Example 20
Source File: JoinOperator.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public JoinProjection(DataSet<I1> ds1, DataSet<I2> ds2, Keys<I1> keys1, Keys<I2> keys2, JoinHint hint, int[] firstFieldIndexes, int[] secondFieldIndexes) {
	this.ds1 = ds1;
	this.ds2 = ds2;
	this.keys1 = keys1;
	this.keys2 = keys2;
	this.hint = hint;

	boolean isFirstTuple;
	boolean isSecondTuple;

	if (ds1.getType() instanceof TupleTypeInfo) {
		numFieldsDs1 = ds1.getType().getArity();
		isFirstTuple = true;
	} else {
		numFieldsDs1 = 1;
		isFirstTuple = false;
	}
	if (ds2.getType() instanceof TupleTypeInfo) {
		numFieldsDs2 = ds2.getType().getArity();
		isSecondTuple = true;
	} else {
		numFieldsDs2 = 1;
		isSecondTuple = false;
	}

	boolean isTuple;
	boolean firstInput;

	if (firstFieldIndexes != null && secondFieldIndexes == null) {
		// index array for first input is provided
		firstInput = true;
		isTuple = isFirstTuple;
		this.fieldIndexes = firstFieldIndexes;

		if (this.fieldIndexes.length == 0) {
			// no indexes provided, treat tuple as regular object
			isTuple = false;
		}
	} else if (firstFieldIndexes == null && secondFieldIndexes != null) {
		// index array for second input is provided
		firstInput = false;
		isTuple = isSecondTuple;
		this.fieldIndexes = secondFieldIndexes;

		if (this.fieldIndexes.length == 0) {
			// no indexes provided, treat tuple as regular object
			isTuple = false;
		}
	} else if (firstFieldIndexes == null && secondFieldIndexes == null) {
		throw new IllegalArgumentException("You must provide at least one field index array.");
	} else {
		throw new IllegalArgumentException("You must provide at most one field index array.");
	}

	if (!isTuple && this.fieldIndexes.length != 0) {
		// field index provided for non-Tuple input
		throw new IllegalArgumentException("Input is not a Tuple. Call projectFirst() (or projectSecond()) without arguments to include it.");
	} else if (this.fieldIndexes.length > 22) {
		throw new IllegalArgumentException("You may select only up to twenty-two (22) fields.");
	}

	if (isTuple) {
		this.isFieldInFirst = new boolean[this.fieldIndexes.length];

		// check field indexes and adapt to position in tuple
		int maxFieldIndex = firstInput ? numFieldsDs1 : numFieldsDs2;
		for (int i = 0; i < this.fieldIndexes.length; i++) {
			Preconditions.checkElementIndex(this.fieldIndexes[i], maxFieldIndex);

			if (firstInput) {
				this.isFieldInFirst[i] = true;
			} else {
				this.isFieldInFirst[i] = false;
			}
		}
	} else {
		this.isFieldInFirst = new boolean[]{firstInput};
		this.fieldIndexes = new int[]{-1};
	}

}