org.apache.flink.api.common.operators.Ordering Java Examples

The following examples show how to use org.apache.flink.api.common.operators.Ordering. 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: LocalPropertiesFilteringTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortingPreserved4() {
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[]{"2->7;5"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(2, IntValue.class, Order.ASCENDING);
	o.appendOrdering(0, StringValue.class, Order.DESCENDING);
	o.appendOrdering(5, LongValue.class, Order.DESCENDING);
	LocalProperties lProps = LocalProperties.forOrdering(o);

	LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
	FieldList gFields = filtered.getGroupedFields();
	Ordering order = filtered.getOrdering();

	assertNotNull(gFields);
	assertEquals(1, gFields.size());
	assertTrue(gFields.contains(7));
	assertNotNull(order);
	assertEquals(1, order.getNumberOfFields());
	assertEquals(7, order.getFieldNumber(0).intValue());
	assertEquals(Order.ASCENDING, order.getOrder(0));
	assertEquals(IntValue.class, order.getType(0));
	assertNull(filtered.getUniqueFields());
}
 
Example #2
Source File: GroupReduceProperties.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public GroupReduceProperties(FieldSet groupKeys, Ordering additionalOrderKeys, Partitioner<?> customPartitioner) {
	super(groupKeys);
	
	// if we have an additional ordering, construct the ordering to have primarily the grouping fields
	if (additionalOrderKeys != null) {
		this.ordering = new Ordering();
		for (Integer key : this.keyList) {
			this.ordering.appendOrdering(key, null, Order.ANY);
		}
	
		// and next the additional order fields
		for (int i = 0; i < additionalOrderKeys.getNumberOfFields(); i++) {
			Integer field = additionalOrderKeys.getFieldNumber(i);
			Order order = additionalOrderKeys.getOrder(i);
			this.ordering.appendOrdering(field, additionalOrderKeys.getType(i), order);
		}
	}
	else {
		this.ordering = null;
	}
	
	this.customPartitioner = customPartitioner;
}
 
Example #3
Source File: CoGroupRawDescriptor.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean areCoFulfilled(RequestedLocalProperties requested1, RequestedLocalProperties requested2,
		LocalProperties produced1, LocalProperties produced2) {
	int numRelevantFields = this.keys1.size();

	Ordering prod1 = produced1.getOrdering();
	Ordering prod2 = produced2.getOrdering();

	if (prod1 == null || prod2 == null || prod1.getNumberOfFields() < numRelevantFields
			|| prod2.getNumberOfFields() < numRelevantFields) {
		throw new CompilerException("The given properties do not meet this operators requirements.");
	}

	for (int i = 0; i < numRelevantFields; i++) {
		if (prod1.getOrder(i) != prod2.getOrder(i)) {
			return false;
		}
	}
	return true;
}
 
Example #4
Source File: GroupReduceProperties.java    From flink with Apache License 2.0 6 votes vote down vote up
public GroupReduceProperties(FieldSet groupKeys, Ordering additionalOrderKeys, Partitioner<?> customPartitioner) {
	super(groupKeys);
	
	// if we have an additional ordering, construct the ordering to have primarily the grouping fields
	if (additionalOrderKeys != null) {
		this.ordering = new Ordering();
		for (Integer key : this.keyList) {
			this.ordering.appendOrdering(key, null, Order.ANY);
		}
	
		// and next the additional order fields
		for (int i = 0; i < additionalOrderKeys.getNumberOfFields(); i++) {
			Integer field = additionalOrderKeys.getFieldNumber(i);
			Order order = additionalOrderKeys.getOrder(i);
			this.ordering.appendOrdering(field, additionalOrderKeys.getType(i), order);
		}
	}
	else {
		this.ordering = null;
	}
	
	this.customPartitioner = customPartitioner;
}
 
Example #5
Source File: RequestedGlobalPropertiesFilteringTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testRangePartitioningErased() {

	SingleInputSemanticProperties sProp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sProp, new String[]{"1;2"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(3, LongValue.class, Order.DESCENDING);
	o.appendOrdering(1, IntValue.class, Order.ASCENDING);
	o.appendOrdering(6, ByteValue.class, Order.DESCENDING);

	RequestedGlobalProperties rgProps = new RequestedGlobalProperties();
	rgProps.setRangePartitioned(o);

	RequestedGlobalProperties filtered = rgProps.filterBySemanticProperties(sProp, 0);

	assertNull(filtered);
}
 
Example #6
Source File: GroupReduceWithCombineProperties.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public GroupReduceWithCombineProperties(FieldSet groupKeys, Ordering additionalOrderKeys, Partitioner<?> customPartitioner) {
	super(groupKeys);
	
	// if we have an additional ordering, construct the ordering to have primarily the grouping fields
	if (additionalOrderKeys != null) {
		this.ordering = new Ordering();
		for (Integer key : this.keyList) {
			this.ordering.appendOrdering(key, null, Order.ANY);
		}
	
		// and next the additional order fields
		for (int i = 0; i < additionalOrderKeys.getNumberOfFields(); i++) {
			Integer field = additionalOrderKeys.getFieldNumber(i);
			Order order = additionalOrderKeys.getOrder(i);
			this.ordering.appendOrdering(field, additionalOrderKeys.getType(i), order);
		}
	} else {
		this.ordering = null;
	}
	
	this.customPartitioner = customPartitioner;
}
 
Example #7
Source File: CoGroupRawNode.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<OperatorDescriptorDual> initializeDataProperties() {
	Ordering groupOrder1 = null;
	Ordering groupOrder2 = null;

	CoGroupRawOperatorBase<?, ?, ?, ?> cgc = getOperator();
	groupOrder1 = cgc.getGroupOrderForInputOne();
	groupOrder2 = cgc.getGroupOrderForInputTwo();

	if (groupOrder1 != null && groupOrder1.getNumberOfFields() == 0) {
		groupOrder1 = null;
	}
	if (groupOrder2 != null && groupOrder2.getNumberOfFields() == 0) {
		groupOrder2 = null;
	}

	return Collections.<OperatorDescriptorDual>singletonList(new CoGroupRawDescriptor(this.keys1, this.keys2, groupOrder1, groupOrder2));
}
 
Example #8
Source File: LocalPropertiesFilteringTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortingErased() {
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[]{"0;5"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(2, IntValue.class, Order.ASCENDING);
	o.appendOrdering(0, StringValue.class, Order.DESCENDING);
	o.appendOrdering(5, LongValue.class, Order.DESCENDING);
	LocalProperties lProps = LocalProperties.forOrdering(o);

	LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
	FieldList gFields = filtered.getGroupedFields();
	Ordering order = filtered.getOrdering();

	assertNull(gFields);
	assertNull(order);
	assertNull(filtered.getUniqueFields());
}
 
Example #9
Source File: OperatorDescriptorDual.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
protected boolean checkSameOrdering(LocalProperties produced1, LocalProperties produced2, int numRelevantFields) {
	Ordering prod1 = produced1.getOrdering();
	Ordering prod2 = produced2.getOrdering();

	if (prod1 == null || prod2 == null) {
		throw new CompilerException("The given properties do not meet this operators requirements.");
	}

	// check that order of fields is equivalent
	if (!checkEquivalentFieldPositionsInKeyFields(
			prod1.getInvolvedIndexes(), prod2.getInvolvedIndexes(), numRelevantFields)) {
		return false;
	}

	// check that both inputs have the same directions of order
	for (int i = 0; i < numRelevantFields; i++) {
		if (prod1.getOrder(i) != prod2.getOrder(i)) {
			return false;
		}
	}
	return true;
}
 
Example #10
Source File: CoGroupRawNode.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<OperatorDescriptorDual> initializeDataProperties() {
	Ordering groupOrder1 = null;
	Ordering groupOrder2 = null;

	CoGroupRawOperatorBase<?, ?, ?, ?> cgc = getOperator();
	groupOrder1 = cgc.getGroupOrderForInputOne();
	groupOrder2 = cgc.getGroupOrderForInputTwo();

	if (groupOrder1 != null && groupOrder1.getNumberOfFields() == 0) {
		groupOrder1 = null;
	}
	if (groupOrder2 != null && groupOrder2.getNumberOfFields() == 0) {
		groupOrder2 = null;
	}

	return Collections.<OperatorDescriptorDual>singletonList(new CoGroupRawDescriptor(this.keys1, this.keys2, groupOrder1, groupOrder2));
}
 
Example #11
Source File: RequestedGlobalPropertiesFilteringTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRangePartitioningErased() {

	SingleInputSemanticProperties sProp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sProp, new String[]{"1;2"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(3, LongValue.class, Order.DESCENDING);
	o.appendOrdering(1, IntValue.class, Order.ASCENDING);
	o.appendOrdering(6, ByteValue.class, Order.DESCENDING);

	RequestedGlobalProperties rgProps = new RequestedGlobalProperties();
	rgProps.setRangePartitioned(o);

	RequestedGlobalProperties filtered = rgProps.filterBySemanticProperties(sProp, 0);

	assertNull(filtered);
}
 
Example #12
Source File: GroupCombineOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static <IN, OUT, K1, K2> PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> translateSelectorFunctionSortedReducer(
		SelectorFunctionKeys<IN, ?> rawGroupingKey,
		SelectorFunctionKeys<IN, ?> rawSortingKeys,
		Ordering groupOrder,
		GroupCombineFunction<IN, OUT> function,
		TypeInformation<OUT> outputType,
		String name,
		Operator<IN> input) {
	final SelectorFunctionKeys<IN, K1> groupingKey = (SelectorFunctionKeys<IN, K1>) rawGroupingKey;
	final SelectorFunctionKeys<IN, K2> sortingKey = (SelectorFunctionKeys<IN, K2>) rawSortingKeys;
	TypeInformation<Tuple3<K1, K2, IN>> typeInfoWithKey = KeyFunctions.createTypeWithKey(groupingKey, sortingKey);

	Operator<Tuple3<K1, K2, IN>> inputWithKey = KeyFunctions.appendKeyExtractor(input, groupingKey, sortingKey);

	PlanUnwrappingSortedGroupCombineOperator<IN, OUT, K1, K2> reducer =
		new PlanUnwrappingSortedGroupCombineOperator<>(function, groupingKey, sortingKey, name, outputType, typeInfoWithKey);
	reducer.setInput(inputWithKey);
	reducer.setGroupOrder(groupOrder);

	return reducer;
}
 
Example #13
Source File: DataSinkNode.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void computeInterestingPropertiesForInputs(CostEstimator estimator) {
	final InterestingProperties iProps = new InterestingProperties();

	{
		final RequestedGlobalProperties partitioningProps = new RequestedGlobalProperties();
		iProps.addGlobalProperties(partitioningProps);
	}

	{
		final Ordering localOrder = getOperator().getLocalOrder();
		final RequestedLocalProperties orderProps = new RequestedLocalProperties();
		if (localOrder != null) {
			orderProps.setOrdering(localOrder);
		}
		iProps.addLocalProperties(orderProps);
	}
	
	this.input.setInterestingProperties(iProps);
}
 
Example #14
Source File: GroupReduceWithCombineProperties.java    From flink with Apache License 2.0 6 votes vote down vote up
public GroupReduceWithCombineProperties(FieldSet groupKeys, Ordering additionalOrderKeys, Partitioner<?> customPartitioner) {
	super(groupKeys);
	
	// if we have an additional ordering, construct the ordering to have primarily the grouping fields
	if (additionalOrderKeys != null) {
		this.ordering = new Ordering();
		for (Integer key : this.keyList) {
			this.ordering.appendOrdering(key, null, Order.ANY);
		}
	
		// and next the additional order fields
		for (int i = 0; i < additionalOrderKeys.getNumberOfFields(); i++) {
			Integer field = additionalOrderKeys.getFieldNumber(i);
			Order order = additionalOrderKeys.getOrder(i);
			this.ordering.appendOrdering(field, additionalOrderKeys.getType(i), order);
		}
	} else {
		this.ordering = null;
	}
	
	this.customPartitioner = customPartitioner;
}
 
Example #15
Source File: CoGroupRawDescriptor.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean areCoFulfilled(RequestedLocalProperties requested1, RequestedLocalProperties requested2,
		LocalProperties produced1, LocalProperties produced2) {
	int numRelevantFields = this.keys1.size();

	Ordering prod1 = produced1.getOrdering();
	Ordering prod2 = produced2.getOrdering();

	if (prod1 == null || prod2 == null || prod1.getNumberOfFields() < numRelevantFields
			|| prod2.getNumberOfFields() < numRelevantFields) {
		throw new CompilerException("The given properties do not meet this operators requirements.");
	}

	for (int i = 0; i < numRelevantFields; i++) {
		if (prod1.getOrder(i) != prod2.getOrder(i)) {
			return false;
		}
	}
	return true;
}
 
Example #16
Source File: GroupReduceWithCombineProperties.java    From flink with Apache License 2.0 6 votes vote down vote up
public GroupReduceWithCombineProperties(FieldSet groupKeys, Ordering additionalOrderKeys, Partitioner<?> customPartitioner) {
	super(groupKeys);
	
	// if we have an additional ordering, construct the ordering to have primarily the grouping fields
	if (additionalOrderKeys != null) {
		this.ordering = new Ordering();
		for (Integer key : this.keyList) {
			this.ordering.appendOrdering(key, null, Order.ANY);
		}
	
		// and next the additional order fields
		for (int i = 0; i < additionalOrderKeys.getNumberOfFields(); i++) {
			Integer field = additionalOrderKeys.getFieldNumber(i);
			Order order = additionalOrderKeys.getOrder(i);
			this.ordering.appendOrdering(field, additionalOrderKeys.getType(i), order);
		}
	} else {
		this.ordering = null;
	}
	
	this.customPartitioner = customPartitioner;
}
 
Example #17
Source File: LocalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortingPreserved1() {
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[]{"0;2;5"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(2, IntValue.class, Order.ASCENDING);
	o.appendOrdering(0, StringValue.class, Order.DESCENDING);
	o.appendOrdering(5, LongValue.class, Order.DESCENDING);
	LocalProperties lProps = LocalProperties.forOrdering(o);

	LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
	FieldList gFields = filtered.getGroupedFields();
	Ordering order = filtered.getOrdering();

	assertNotNull(gFields);
	assertEquals(3, gFields.size());
	assertTrue(gFields.contains(0));
	assertTrue(gFields.contains(2));
	assertTrue(gFields.contains(5));
	assertNotNull(order);
	assertEquals(3, order.getNumberOfFields());
	assertEquals(2, order.getFieldNumber(0).intValue());
	assertEquals(0, order.getFieldNumber(1).intValue());
	assertEquals(5, order.getFieldNumber(2).intValue());
	assertEquals(Order.ASCENDING, order.getOrder(0));
	assertEquals(Order.DESCENDING, order.getOrder(1));
	assertEquals(Order.DESCENDING, order.getOrder(2));
	assertEquals(IntValue.class, order.getType(0));
	assertEquals(StringValue.class, order.getType(1));
	assertEquals(LongValue.class, order.getType(2));
	assertNull(filtered.getUniqueFields());
}
 
Example #18
Source File: LocalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortingPreserved1() {
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[]{"0;2;5"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(2, IntValue.class, Order.ASCENDING);
	o.appendOrdering(0, StringValue.class, Order.DESCENDING);
	o.appendOrdering(5, LongValue.class, Order.DESCENDING);
	LocalProperties lProps = LocalProperties.forOrdering(o);

	LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
	FieldList gFields = filtered.getGroupedFields();
	Ordering order = filtered.getOrdering();

	assertNotNull(gFields);
	assertEquals(3, gFields.size());
	assertTrue(gFields.contains(0));
	assertTrue(gFields.contains(2));
	assertTrue(gFields.contains(5));
	assertNotNull(order);
	assertEquals(3, order.getNumberOfFields());
	assertEquals(2, order.getFieldNumber(0).intValue());
	assertEquals(0, order.getFieldNumber(1).intValue());
	assertEquals(5, order.getFieldNumber(2).intValue());
	assertEquals(Order.ASCENDING, order.getOrder(0));
	assertEquals(Order.DESCENDING, order.getOrder(1));
	assertEquals(Order.DESCENDING, order.getOrder(2));
	assertEquals(IntValue.class, order.getType(0));
	assertEquals(StringValue.class, order.getType(1));
	assertEquals(LongValue.class, order.getType(2));
	assertNull(filtered.getUniqueFields());
}
 
Example #19
Source File: LocalPropertiesFilteringTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortingPreserved1() {
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[]{"0;2;5"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(2, IntValue.class, Order.ASCENDING);
	o.appendOrdering(0, StringValue.class, Order.DESCENDING);
	o.appendOrdering(5, LongValue.class, Order.DESCENDING);
	LocalProperties lProps = LocalProperties.forOrdering(o);

	LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
	FieldList gFields = filtered.getGroupedFields();
	Ordering order = filtered.getOrdering();

	assertNotNull(gFields);
	assertEquals(3, gFields.size());
	assertTrue(gFields.contains(0));
	assertTrue(gFields.contains(2));
	assertTrue(gFields.contains(5));
	assertNotNull(order);
	assertEquals(3, order.getNumberOfFields());
	assertEquals(2, order.getFieldNumber(0).intValue());
	assertEquals(0, order.getFieldNumber(1).intValue());
	assertEquals(5, order.getFieldNumber(2).intValue());
	assertEquals(Order.ASCENDING, order.getOrder(0));
	assertEquals(Order.DESCENDING, order.getOrder(1));
	assertEquals(Order.DESCENDING, order.getOrder(2));
	assertEquals(IntValue.class, order.getType(0));
	assertEquals(StringValue.class, order.getType(1));
	assertEquals(LongValue.class, order.getType(2));
	assertNull(filtered.getUniqueFields());
}
 
Example #20
Source File: CoGroupOperatorBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the order of the elements within a group for the given input.
 *
 * @param inputNum The number of the input (here either <i>0</i> or <i>1</i>).
 * @param order    The order for the elements in a group.
 */
public void setGroupOrder(int inputNum, Ordering order) {
	if (inputNum == 0) {
		this.groupOrder1 = order;
	}
	else if (inputNum == 1) {
		this.groupOrder2 = order;
	}
	else {
		throw new IndexOutOfBoundsException();
	}
}
 
Example #21
Source File: PartitionNode.java    From flink with Apache License 2.0 5 votes vote down vote up
public PartitionDescriptor(PartitionMethod pMethod, FieldSet pKeys, Ordering ordering, Partitioner<?>
		customPartitioner, DataDistribution distribution) {
	super(pKeys);

	Preconditions.checkArgument(pMethod != PartitionMethod.RANGE
			|| pKeys.equals(new FieldSet(ordering.getFieldPositions())),
			"Partition keys must match the given ordering.");

	this.pMethod = pMethod;
	this.customPartitioner = customPartitioner;
	this.distribution = distribution;
	this.ordering = ordering;
}
 
Example #22
Source File: CoGroupOperatorBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the order of the elements within a group for the given input.
 *
 * @param inputNum The number of the input (here either <i>0</i> or <i>1</i>).
 * @param order    The order for the elements in a group.
 */
public void setGroupOrder(int inputNum, Ordering order) {
	if (inputNum == 0) {
		this.groupOrder1 = order;
	}
	else if (inputNum == 1) {
		this.groupOrder2 = order;
	}
	else {
		throw new IndexOutOfBoundsException();
	}
}
 
Example #23
Source File: Utils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static Ordering createOrdering(FieldList fields, boolean[] directions) {
	final Ordering o = new Ordering();
	for (int i = 0; i < fields.size(); i++) {
		o.appendOrdering(fields.get(i), null, directions == null || directions[i] ? Order.ASCENDING : Order.DESCENDING);
	}
	return o;
}
 
Example #24
Source File: SplitDataProperties.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Defines that the data within an input split is sorted on the fields defined by the field expressions
 * in the specified orders. Multiple field expressions must be separated by the semicolon ';' character.
 * All records of an input split must be emitted by the input format in the defined order.
 *
 * <p><b>
 *     IMPORTANT: Providing wrong information with SplitDataProperties can cause wrong results!
 * </b>
 *
 * @param orderFields The field expressions of the grouping key.
 * @param orders The orders of the fields.
 * @return This SplitDataProperties object.
 */
public SplitDataProperties<T> splitsOrderedBy(String orderFields, Order[] orders) {

	if (orderFields == null || orders == null) {
		throw new InvalidProgramException("OrderFields or Orders may not be null.");
	}

	String[] orderKeysA = orderFields.split(";");
	if (orderKeysA.length == 0) {
		throw new InvalidProgramException("OrderFields may not be empty.");
	} else if (orders.length == 0) {
		throw new InvalidProgramException("Orders may not be empty");
	} else if (orderKeysA.length != orders.length) {
		throw new InvalidProgramException("Number of OrderFields and Orders must match.");
	}

	if (this.splitGroupKeys != null) {
		throw new InvalidProgramException("DataSource may either be grouped or sorted.");
	}

	this.splitOrdering = new Ordering();

	for (int i = 0; i < orderKeysA.length; i++) {
		String keyExp = orderKeysA[i];
		Keys.ExpressionKeys<T> ek = new Keys.ExpressionKeys<>(keyExp, this.type);
		int[] flatKeys = ek.computeLogicalKeyPositions();

		for (int key : flatKeys) {
			// check for duplicates
			for (int okey : splitOrdering.getFieldPositions()) {
				if (key == okey) {
					throw new InvalidProgramException("Duplicate field in field expression " + keyExp);
				}
			}
			// append key
			this.splitOrdering.appendOrdering(key, null, orders[i]);
		}
	}
	return this;
}
 
Example #25
Source File: LocalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortingPreserved2() {
	SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[]{"0->3;2->7;5->1"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(2, IntValue.class, Order.ASCENDING);
	o.appendOrdering(0, StringValue.class, Order.DESCENDING);
	o.appendOrdering(5, LongValue.class, Order.DESCENDING);
	LocalProperties lProps = LocalProperties.forOrdering(o);

	LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
	FieldList gFields = filtered.getGroupedFields();
	Ordering order = filtered.getOrdering();

	assertNotNull(gFields);
	assertEquals(3, gFields.size());
	assertTrue(gFields.contains(3));
	assertTrue(gFields.contains(7));
	assertTrue(gFields.contains(1));
	assertNotNull(order);
	assertEquals(3, order.getNumberOfFields());
	assertEquals(7, order.getFieldNumber(0).intValue());
	assertEquals(3, order.getFieldNumber(1).intValue());
	assertEquals(1, order.getFieldNumber(2).intValue());
	assertEquals(Order.ASCENDING, order.getOrder(0));
	assertEquals(Order.DESCENDING, order.getOrder(1));
	assertEquals(Order.DESCENDING, order.getOrder(2));
	assertEquals(IntValue.class, order.getType(0));
	assertEquals(StringValue.class, order.getType(1));
	assertEquals(LongValue.class, order.getType(2));
	assertNull(filtered.getUniqueFields());
}
 
Example #26
Source File: GroupReduceNode.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private List<OperatorDescriptorSingle> initPossibleProperties(Partitioner<?> customPartitioner) {
	// see if an internal hint dictates the strategy to use
	final Configuration conf = getOperator().getParameters();
	final String localStrategy = conf.getString(Optimizer.HINT_LOCAL_STRATEGY, null);

	final boolean useCombiner;
	if (localStrategy != null) {
		if (Optimizer.HINT_LOCAL_STRATEGY_SORT.equals(localStrategy)) {
			useCombiner = false;
		}
		else if (Optimizer.HINT_LOCAL_STRATEGY_COMBINING_SORT.equals(localStrategy)) {
			if (!isCombineable()) {
				Optimizer.LOG.warn("Strategy hint for GroupReduce '" + getOperator().getName() +
					"' requires combinable reduce, but user function is not marked combinable.");
			}
			useCombiner = true;
		} else {
			throw new CompilerException("Invalid local strategy hint for match contract: " + localStrategy);
		}
	} else {
		useCombiner = isCombineable();
	}
	
	// check if we can work with a grouping (simple reducer), or if we need ordering because of a group order
	Ordering groupOrder = null;
	if (getOperator() != null) {
		groupOrder = getOperator().getGroupOrder();
		if (groupOrder != null && groupOrder.getNumberOfFields() == 0) {
			groupOrder = null;
		}
	}
	
	OperatorDescriptorSingle props = useCombiner ?
		(this.keys == null ? new AllGroupWithPartialPreGroupProperties() : new GroupReduceWithCombineProperties(this.keys, groupOrder, customPartitioner)) :
		(this.keys == null ? new AllGroupReduceProperties() : new GroupReduceProperties(this.keys, groupOrder, customPartitioner));

	return Collections.singletonList(props);
}
 
Example #27
Source File: GlobalProperties.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Set the parameters for range partition.
 *
 * @param ordering Order of the partitioned fields
 */
public void setRangePartitioned(Ordering ordering) {
	if (ordering == null) {
		throw new NullPointerException();
	}

	this.partitioning = PartitioningProperty.RANGE_PARTITIONED;
	this.ordering = ordering;
	this.partitioningFields = ordering.getInvolvedIndexes();
}
 
Example #28
Source File: RequestedGlobalPropertiesFilteringTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRangePartitioningPreserved1() {

	SingleInputSemanticProperties sProp = new SingleInputSemanticProperties();
	SemanticPropUtil.getSemanticPropsSingleFromString(sProp, new String[]{"1;3;6"}, null, null, tupleInfo, tupleInfo);

	Ordering o = new Ordering();
	o.appendOrdering(3, LongValue.class, Order.DESCENDING);
	o.appendOrdering(1, IntValue.class, Order.ASCENDING);
	o.appendOrdering(6, ByteValue.class, Order.DESCENDING);

	RequestedGlobalProperties rgProps = new RequestedGlobalProperties();
	rgProps.setRangePartitioned(o);

	RequestedGlobalProperties filtered = rgProps.filterBySemanticProperties(sProp, 0);

	assertNotNull(filtered);
	assertEquals(PartitioningProperty.RANGE_PARTITIONED, filtered.getPartitioning());
	assertNotNull(filtered.getOrdering());
	assertEquals(3, filtered.getOrdering().getNumberOfFields());
	assertEquals(3, filtered.getOrdering().getFieldNumber(0).intValue());
	assertEquals(1, filtered.getOrdering().getFieldNumber(1).intValue());
	assertEquals(6, filtered.getOrdering().getFieldNumber(2).intValue());
	assertEquals(LongValue.class, filtered.getOrdering().getType(0));
	assertEquals(IntValue.class, filtered.getOrdering().getType(1));
	assertEquals(ByteValue.class, filtered.getOrdering().getType(2));
	assertEquals(Order.DESCENDING, filtered.getOrdering().getOrder(0));
	assertEquals(Order.ASCENDING, filtered.getOrdering().getOrder(1));
	assertEquals(Order.DESCENDING, filtered.getOrdering().getOrder(2));
	assertNull(filtered.getPartitionedFields());
	assertNull(filtered.getDataDistribution());
	assertNull(filtered.getCustomPartitioner());
}
 
Example #29
Source File: GroupCombineNode.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private List<OperatorDescriptorSingle> initPossibleProperties() {

		// check if we can work with a grouping (simple reducer), or if we need ordering because of a group order
		Ordering groupOrder = getOperator().getGroupOrder();
		if (groupOrder != null && groupOrder.getNumberOfFields() == 0) {
			groupOrder = null;
		}

		OperatorDescriptorSingle props = (this.keys == null ?
				new AllGroupCombineProperties() :
				new GroupCombineProperties(this.keys, groupOrder));

		return Collections.singletonList(props);
	}
 
Example #30
Source File: RequestedGlobalProperties.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public void setRangePartitioned(Ordering ordering, DataDistribution dataDistribution) {
	if (ordering == null) {
		throw new NullPointerException();
	}
	this.partitioning = PartitioningProperty.RANGE_PARTITIONED;
	this.ordering = ordering;
	this.partitioningFields = null;
	this.dataDistribution = dataDistribution;
}