Search in sources :

Example 91 with FieldSet

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());
    }
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) Ordering(org.apache.flink.api.common.operators.Ordering) FieldList(org.apache.flink.api.common.operators.util.FieldList) Test(org.junit.Test)

Example 92 with FieldSet

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());
    }
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Ordering(org.apache.flink.api.common.operators.Ordering) FieldList(org.apache.flink.api.common.operators.util.FieldList) Test(org.junit.Test)

Example 93 with FieldSet

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());
    }
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) Test(org.junit.Test)

Example 94 with FieldSet

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());
    }
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) Test(org.junit.Test)

Example 95 with FieldSet

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));
    }
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet)

Aggregations

FieldSet (org.apache.flink.api.common.operators.util.FieldSet)111 Test (org.junit.Test)97 SingleInputSemanticProperties (org.apache.flink.api.common.operators.SingleInputSemanticProperties)57 Plan (org.apache.flink.api.common.Plan)37 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)37 GlobalProperties (org.apache.flink.optimizer.dataproperties.GlobalProperties)28 LocalProperties (org.apache.flink.optimizer.dataproperties.LocalProperties)28 SourcePlanNode (org.apache.flink.optimizer.plan.SourcePlanNode)27 OptimizedPlan (org.apache.flink.optimizer.plan.OptimizedPlan)25 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)24 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)24 FieldList (org.apache.flink.api.common.operators.util.FieldList)14 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)14 MapOperatorBase (org.apache.flink.api.common.operators.base.MapOperatorBase)13 DualInputSemanticProperties (org.apache.flink.api.common.operators.DualInputSemanticProperties)9 Ordering (org.apache.flink.api.common.operators.Ordering)9 SemanticProperties (org.apache.flink.api.common.operators.SemanticProperties)5 Channel (org.apache.flink.optimizer.plan.Channel)4 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)4 Configuration (org.apache.flink.configuration.Configuration)3