use of org.apache.flink.api.common.operators.util.FieldSet in project flink by apache.
the class GlobalPropertiesMatchingTest method testMatchingAnyPartitioning.
@Test
public void testMatchingAnyPartitioning() {
try {
RequestedGlobalProperties req = new RequestedGlobalProperties();
req.setAnyPartitioning(new FieldSet(6, 2));
// match any partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setAnyPartitioning(new FieldList(2, 6));
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setAnyPartitioning(new FieldList(6, 2));
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setAnyPartitioning(new FieldList(6, 2, 4));
assertFalse(req.isMetBy(gp3));
GlobalProperties gp4 = new GlobalProperties();
gp4.setAnyPartitioning(new FieldList(6, 1));
assertFalse(req.isMetBy(gp4));
GlobalProperties gp5 = new GlobalProperties();
gp5.setAnyPartitioning(new FieldList(2));
assertTrue(req.isMetBy(gp5));
}
// match hash partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setHashPartitioned(new FieldList(2, 6));
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setHashPartitioned(new FieldList(6, 2));
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setHashPartitioned(new FieldList(6, 1));
assertFalse(req.isMetBy(gp3));
}
// match range partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setRangePartitioned(new Ordering(2, null, Order.DESCENDING).appendOrdering(6, null, Order.ASCENDING));
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setRangePartitioned(new Ordering(6, null, Order.DESCENDING).appendOrdering(2, null, Order.ASCENDING));
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setRangePartitioned(new Ordering(6, null, Order.DESCENDING).appendOrdering(1, null, Order.ASCENDING));
assertFalse(req.isMetBy(gp3));
GlobalProperties gp4 = new GlobalProperties();
gp4.setRangePartitioned(new Ordering(6, null, Order.DESCENDING));
assertTrue(req.isMetBy(gp4));
}
// match custom partitioning
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setCustomPartitioned(new FieldList(2, 6), new MockPartitioner());
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setCustomPartitioned(new FieldList(6, 2), new MockPartitioner());
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setCustomPartitioned(new FieldList(6, 1), new MockPartitioner());
assertFalse(req.isMetBy(gp3));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.common.operators.util.FieldSet in project flink by apache.
the class GlobalPropertiesMatchingTest method testMatchingCustomPartitioning.
@Test
public void testMatchingCustomPartitioning() {
try {
final Partitioner<Tuple2<Long, Integer>> partitioner = new MockPartitioner();
RequestedGlobalProperties req = new RequestedGlobalProperties();
req.setCustomPartitioned(new FieldSet(6, 2), partitioner);
// match custom partitionings
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setCustomPartitioned(new FieldList(2, 6), partitioner);
assertTrue(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setCustomPartitioned(new FieldList(6, 2), partitioner);
assertTrue(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setCustomPartitioned(new FieldList(6, 2), new MockPartitioner());
assertFalse(req.isMetBy(gp3));
}
// cannot match other types of partitionings
{
GlobalProperties gp1 = new GlobalProperties();
gp1.setAnyPartitioning(new FieldList(6, 2));
assertFalse(req.isMetBy(gp1));
GlobalProperties gp2 = new GlobalProperties();
gp2.setHashPartitioned(new FieldList(6, 2));
assertFalse(req.isMetBy(gp2));
GlobalProperties gp3 = new GlobalProperties();
gp3.setRangePartitioned(new Ordering(2, null, Order.DESCENDING).appendOrdering(6, null, Order.ASCENDING));
assertFalse(req.isMetBy(gp3));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.common.operators.util.FieldSet in project flink by apache.
the class GlobalPropertiesPushdownTest method testAnyPartitioningPushedDown.
@Test
public void testAnyPartitioningPushedDown() {
try {
RequestedGlobalProperties req = new RequestedGlobalProperties();
req.setAnyPartitioning(new FieldSet(3, 1));
RequestedGlobalProperties preserved = req.filterBySemanticProperties(getAllPreservingSemProps(), 0);
assertEquals(PartitioningProperty.ANY_PARTITIONING, preserved.getPartitioning());
assertTrue(preserved.getPartitionedFields().isValidSubset(new FieldSet(1, 3)));
RequestedGlobalProperties nonPreserved = req.filterBySemanticProperties(getNonePreservingSemProps(), 0);
assertTrue(nonPreserved == null || nonPreserved.isTrivial());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.common.operators.util.FieldSet in project flink by apache.
the class GlobalPropertiesPushdownTest method testHashPartitioningPushedDown.
@Test
public void testHashPartitioningPushedDown() {
try {
RequestedGlobalProperties req = new RequestedGlobalProperties();
req.setHashPartitioned(new FieldSet(3, 1));
RequestedGlobalProperties preserved = req.filterBySemanticProperties(getAllPreservingSemProps(), 0);
assertEquals(PartitioningProperty.HASH_PARTITIONED, preserved.getPartitioning());
assertTrue(preserved.getPartitionedFields().isValidSubset(new FieldSet(1, 3)));
RequestedGlobalProperties nonPreserved = req.filterBySemanticProperties(getNonePreservingSemProps(), 0);
assertTrue(nonPreserved == null || nonPreserved.isTrivial());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.common.operators.util.FieldSet in project flink by apache.
the class DualInputSemanticProperties method addForwardedField.
/**
* Adds, to the existing information, a field that is forwarded directly
* from the source record(s) in the first input to the destination
* record(s).
*
* @param input the input of the source field
* @param sourceField the position in the source record
* @param targetField the position in the destination record
*/
public void addForwardedField(int input, int sourceField, int targetField) {
Map<Integer, FieldSet> fieldMapping;
if (input != 0 && input != 1) {
throw new IndexOutOfBoundsException();
} else if (input == 0) {
fieldMapping = this.fieldMapping1;
} else {
fieldMapping = this.fieldMapping2;
}
if (isTargetFieldPresent(targetField, fieldMapping)) {
throw new InvalidSemanticAnnotationException("Target field " + targetField + " was added twice to input " + input);
}
FieldSet targetFields = fieldMapping.get(sourceField);
if (targetFields != null) {
fieldMapping.put(sourceField, targetFields.addField(targetField));
} else {
fieldMapping.put(sourceField, new FieldSet(targetField));
}
}
Aggregations