Java Code Examples for org.apache.flink.api.common.operators.Keys.ExpressionKeys#computeLogicalKeyPositions()

The following examples show how to use org.apache.flink.api.common.operators.Keys.ExpressionKeys#computeLogicalKeyPositions() . 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: SortedGrouping.java    From flink with Apache License 2.0 5 votes vote down vote up
public SortedGrouping(DataSet<T> set, Keys<T> keys, String field, Order order) {
	super(set, keys);

	if (!Keys.ExpressionKeys.isSortKey(field, inputDataSet.getType())) {
		throw new InvalidProgramException("Selected sort key is not a sortable type");
	}

	// resolve String-field to int using the expression keys
	ExpressionKeys<T> ek = new ExpressionKeys<>(field, inputDataSet.getType());

	this.groupSortKeyPositions = ek.computeLogicalKeyPositions();
	this.groupSortOrders = new Order[groupSortKeyPositions.length];
	Arrays.fill(this.groupSortOrders, order); // if field == "*"
}
 
Example 2
Source File: SortedGrouping.java    From flink with Apache License 2.0 5 votes vote down vote up
public SortedGrouping(DataSet<T> set, Keys<T> keys, int field, Order order) {
	super(set, keys);

	if (!Keys.ExpressionKeys.isSortKey(field, inputDataSet.getType())) {
		throw new InvalidProgramException("Selected sort key is not a sortable type");
	}

	// use int-based expression key to properly resolve nested tuples for grouping
	ExpressionKeys<T> ek = new ExpressionKeys<>(field, inputDataSet.getType());

	this.groupSortKeyPositions = ek.computeLogicalKeyPositions();
	this.groupSortOrders = new Order[groupSortKeyPositions.length];
	Arrays.fill(this.groupSortOrders, order);
}
 
Example 3
Source File: SortedGrouping.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public SortedGrouping(DataSet<T> set, Keys<T> keys, int field, Order order) {
	super(set, keys);

	if (!Keys.ExpressionKeys.isSortKey(field, inputDataSet.getType())) {
		throw new InvalidProgramException("Selected sort key is not a sortable type");
	}

	// use int-based expression key to properly resolve nested tuples for grouping
	ExpressionKeys<T> ek = new ExpressionKeys<>(field, inputDataSet.getType());

	this.groupSortKeyPositions = ek.computeLogicalKeyPositions();
	this.groupSortOrders = new Order[groupSortKeyPositions.length];
	Arrays.fill(this.groupSortOrders, order);
}
 
Example 4
Source File: SortedGrouping.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public SortedGrouping(DataSet<T> set, Keys<T> keys, String field, Order order) {
	super(set, keys);

	if (!Keys.ExpressionKeys.isSortKey(field, inputDataSet.getType())) {
		throw new InvalidProgramException("Selected sort key is not a sortable type");
	}

	// resolve String-field to int using the expression keys
	ExpressionKeys<T> ek = new ExpressionKeys<>(field, inputDataSet.getType());

	this.groupSortKeyPositions = ek.computeLogicalKeyPositions();
	this.groupSortOrders = new Order[groupSortKeyPositions.length];
	Arrays.fill(this.groupSortOrders, order); // if field == "*"
}
 
Example 5
Source File: SortedGrouping.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void addSortGroupInternal(ExpressionKeys<T> ek, Order order) {
	Preconditions.checkArgument(order != null, "Order can not be null");
	int[] additionalKeyPositions = ek.computeLogicalKeyPositions();

	int newLength = this.groupSortKeyPositions.length + additionalKeyPositions.length;
	this.groupSortKeyPositions = Arrays.copyOf(this.groupSortKeyPositions, newLength);
	this.groupSortOrders = Arrays.copyOf(this.groupSortOrders, newLength);
	int pos = newLength - additionalKeyPositions.length;
	int off = newLength - additionalKeyPositions.length;
	for (; pos < newLength; pos++) {
		this.groupSortKeyPositions[pos] = additionalKeyPositions[pos - off];
		this.groupSortOrders[pos] = order; // use the same order
	}
}
 
Example 6
Source File: SortedGrouping.java    From flink with Apache License 2.0 5 votes vote down vote up
private void addSortGroupInternal(ExpressionKeys<T> ek, Order order) {
	Preconditions.checkArgument(order != null, "Order can not be null");
	int[] additionalKeyPositions = ek.computeLogicalKeyPositions();

	int newLength = this.groupSortKeyPositions.length + additionalKeyPositions.length;
	this.groupSortKeyPositions = Arrays.copyOf(this.groupSortKeyPositions, newLength);
	this.groupSortOrders = Arrays.copyOf(this.groupSortOrders, newLength);
	int pos = newLength - additionalKeyPositions.length;
	int off = newLength - additionalKeyPositions.length;
	for (; pos < newLength; pos++) {
		this.groupSortKeyPositions[pos] = additionalKeyPositions[pos - off];
		this.groupSortOrders[pos] = order; // use the same order
	}
}
 
Example 7
Source File: SortedGrouping.java    From flink with Apache License 2.0 5 votes vote down vote up
private void addSortGroupInternal(ExpressionKeys<T> ek, Order order) {
	Preconditions.checkArgument(order != null, "Order can not be null");
	int[] additionalKeyPositions = ek.computeLogicalKeyPositions();

	int newLength = this.groupSortKeyPositions.length + additionalKeyPositions.length;
	this.groupSortKeyPositions = Arrays.copyOf(this.groupSortKeyPositions, newLength);
	this.groupSortOrders = Arrays.copyOf(this.groupSortOrders, newLength);
	int pos = newLength - additionalKeyPositions.length;
	int off = newLength - additionalKeyPositions.length;
	for (; pos < newLength; pos++) {
		this.groupSortKeyPositions[pos] = additionalKeyPositions[pos - off];
		this.groupSortOrders[pos] = order; // use the same order
	}
}
 
Example 8
Source File: SortedGrouping.java    From flink with Apache License 2.0 5 votes vote down vote up
public SortedGrouping(DataSet<T> set, Keys<T> keys, int field, Order order) {
	super(set, keys);

	if (!Keys.ExpressionKeys.isSortKey(field, inputDataSet.getType())) {
		throw new InvalidProgramException("Selected sort key is not a sortable type");
	}

	// use int-based expression key to properly resolve nested tuples for grouping
	ExpressionKeys<T> ek = new ExpressionKeys<>(field, inputDataSet.getType());

	this.groupSortKeyPositions = ek.computeLogicalKeyPositions();
	this.groupSortOrders = new Order[groupSortKeyPositions.length];
	Arrays.fill(this.groupSortOrders, order);
}
 
Example 9
Source File: SortedGrouping.java    From flink with Apache License 2.0 5 votes vote down vote up
public SortedGrouping(DataSet<T> set, Keys<T> keys, String field, Order order) {
	super(set, keys);

	if (!Keys.ExpressionKeys.isSortKey(field, inputDataSet.getType())) {
		throw new InvalidProgramException("Selected sort key is not a sortable type");
	}

	// resolve String-field to int using the expression keys
	ExpressionKeys<T> ek = new ExpressionKeys<>(field, inputDataSet.getType());

	this.groupSortKeyPositions = ek.computeLogicalKeyPositions();
	this.groupSortOrders = new Order[groupSortKeyPositions.length];
	Arrays.fill(this.groupSortOrders, order); // if field == "*"
}
 
Example 10
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts Pojo or {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the second input on the
 * specified field in the specified {@link Order}.
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortSecondGroup(String, Order)} calls.
 *
 * @param fieldExpression The expression to the field on which the group is to be sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortSecondGroup(String fieldExpression, Order order) {

	ExpressionKeys<I2> ek = new ExpressionKeys<>(fieldExpression, input2.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderSecond.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 11
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts Pojo or {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the second input on the
 * specified field in the specified {@link Order}.
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortSecondGroup(String, Order)} calls.
 *
 * @param fieldExpression The expression to the field on which the group is to be sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortSecondGroup(String fieldExpression, Order order) {

	ExpressionKeys<I2> ek = new ExpressionKeys<>(fieldExpression, input2.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderSecond.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 12
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the second input on the
 * specified field in the specified {@link Order}.
 *
 * <p><b>Note: Only groups of Tuple elements and Pojos can be sorted.</b>
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortSecondGroup(int, Order)} calls.
 *
 * @param field The Tuple field on which the group is sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see org.apache.flink.api.java.tuple.Tuple
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortSecondGroup(int field, Order order) {

	ExpressionKeys<I2> ek = new ExpressionKeys<>(field, input2.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderSecond.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 13
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the first input on the
 * specified field in the specified {@link Order}.
 *
 * <p><b>Note: Only groups of Tuple elements and Pojos can be sorted.</b>
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortFirstGroup(int, Order)} calls.
 *
 * @param field The Tuple field on which the group is sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see org.apache.flink.api.java.tuple.Tuple
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortFirstGroup(int field, Order order) {

	ExpressionKeys<I1> ek = new ExpressionKeys<>(field, input1.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderFirst.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 14
Source File: CoGroupOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the first input on the
 * specified field in the specified {@link Order}.
 *
 * <p><b>Note: Only groups of Tuple elements and Pojos can be sorted.</b>
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortFirstGroup(int, Order)} calls.
 *
 * @param field The Tuple field on which the group is sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see org.apache.flink.api.java.tuple.Tuple
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortFirstGroup(int field, Order order) {

	ExpressionKeys<I1> ek = new ExpressionKeys<>(field, input1.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderFirst.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 15
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts Pojo or {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the first input on the
 * specified field in the specified {@link Order}.
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortFirstGroup(String, Order)} calls.
 *
 * @param fieldExpression The expression to the field on which the group is to be sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortFirstGroup(String fieldExpression, Order order) {

	ExpressionKeys<I1> ek = new ExpressionKeys<>(fieldExpression, input1.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderFirst.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 16
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the second input on the
 * specified field in the specified {@link Order}.
 *
 * <p><b>Note: Only groups of Tuple elements and Pojos can be sorted.</b>
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortSecondGroup(int, Order)} calls.
 *
 * @param field The Tuple field on which the group is sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see org.apache.flink.api.java.tuple.Tuple
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortSecondGroup(int field, Order order) {

	ExpressionKeys<I2> ek = new ExpressionKeys<>(field, input2.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderSecond.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 17
Source File: CoGroupOperator.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the first input on the
 * specified field in the specified {@link Order}.
 *
 * <p><b>Note: Only groups of Tuple elements and Pojos can be sorted.</b>
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortFirstGroup(int, Order)} calls.
 *
 * @param field The Tuple field on which the group is sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see org.apache.flink.api.java.tuple.Tuple
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortFirstGroup(int field, Order order) {

	ExpressionKeys<I1> ek = new ExpressionKeys<>(field, input1.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderFirst.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 18
Source File: CoGroupOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts Pojo or {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the second input on the
 * specified field in the specified {@link Order}.
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortSecondGroup(String, Order)} calls.
 *
 * @param fieldExpression The expression to the field on which the group is to be sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortSecondGroup(String fieldExpression, Order order) {

	ExpressionKeys<I2> ek = new ExpressionKeys<>(fieldExpression, input2.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderSecond.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 19
Source File: CoGroupOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts Pojo or {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the first input on the
 * specified field in the specified {@link Order}.
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortFirstGroup(String, Order)} calls.
 *
 * @param fieldExpression The expression to the field on which the group is to be sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortFirstGroup(String fieldExpression, Order order) {

	ExpressionKeys<I1> ek = new ExpressionKeys<>(fieldExpression, input1.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderFirst.add(new ImmutablePair<>(key, order));
	}

	return this;
}
 
Example 20
Source File: CoGroupOperator.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Sorts {@link org.apache.flink.api.java.tuple.Tuple} elements within a group in the second input on the
 * specified field in the specified {@link Order}.
 *
 * <p><b>Note: Only groups of Tuple elements and Pojos can be sorted.</b>
 *
 * <p>Groups can be sorted by multiple fields by chaining {@link #sortSecondGroup(int, Order)} calls.
 *
 * @param field The Tuple field on which the group is sorted.
 * @param order The Order in which the specified Tuple field is sorted.
 * @return A SortedGrouping with specified order of group element.
 *
 * @see org.apache.flink.api.java.tuple.Tuple
 * @see Order
 */
public CoGroupOperatorWithoutFunction sortSecondGroup(int field, Order order) {

	ExpressionKeys<I2> ek = new ExpressionKeys<>(field, input2.getType());
	int[] groupOrderKeys = ek.computeLogicalKeyPositions();

	for (int key : groupOrderKeys) {
		this.groupSortKeyOrderSecond.add(new ImmutablePair<>(key, order));
	}

	return this;
}