Search in sources :

Example 81 with SingleInputSemanticProperties

use of org.apache.flink.api.common.operators.SingleInputSemanticProperties in project flink by apache.

the class MapPartitionNodeTest method testGetSemanticProperties.

@Test
public void testGetSemanticProperties() {
    SingleInputSemanticProperties origProps = new SingleInputSemanticProperties();
    origProps.addForwardedField(0, 1);
    origProps.addForwardedField(2, 2);
    origProps.addReadFields(new FieldSet(0, 2, 4, 7));
    MapPartitionOperatorBase<?, ?, ?> op = mock(MapPartitionOperatorBase.class);
    when(op.getSemanticProperties()).thenReturn(origProps);
    when(op.getKeyColumns(0)).thenReturn(new int[] {});
    MapPartitionNode node = new MapPartitionNode(op);
    SemanticProperties filteredProps = node.getSemanticPropertiesForLocalPropertyFiltering();
    assertTrue(filteredProps.getForwardingTargetFields(0, 0).size() == 0);
    assertTrue(filteredProps.getForwardingTargetFields(0, 2).size() == 0);
    assertTrue(filteredProps.getForwardingSourceField(0, 1) < 0);
    assertTrue(filteredProps.getForwardingSourceField(0, 2) < 0);
    assertTrue(filteredProps.getReadFields(0).size() == 4);
    assertTrue(filteredProps.getReadFields(0).contains(0));
    assertTrue(filteredProps.getReadFields(0).contains(2));
    assertTrue(filteredProps.getReadFields(0).contains(4));
    assertTrue(filteredProps.getReadFields(0).contains(7));
}
Also used : SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) SemanticProperties(org.apache.flink.api.common.operators.SemanticProperties) FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Example 82 with SingleInputSemanticProperties

use of org.apache.flink.api.common.operators.SingleInputSemanticProperties in project flink by apache.

the class LocalPropertiesFilteringTest method testSortingPreserved1.

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

Example 83 with SingleInputSemanticProperties

use of org.apache.flink.api.common.operators.SingleInputSemanticProperties in project flink by apache.

the class LocalPropertiesFilteringTest method testUniqueFieldsErased.

@Test
public void testUniqueFieldsErased() {
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[] { "0;1;4" }, null, null, tupleInfo, tupleInfo);
    LocalProperties lProps = new LocalProperties();
    lProps = lProps.addUniqueFields(new FieldSet(0, 1, 2));
    lProps = lProps.addUniqueFields(new FieldSet(3, 4));
    lProps = lProps.addUniqueFields(new FieldSet(4, 5, 6));
    LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
    assertNull(filtered.getGroupedFields());
    assertNull(filtered.getOrdering());
    assertNull(filtered.getUniqueFields());
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Example 84 with SingleInputSemanticProperties

use of org.apache.flink.api.common.operators.SingleInputSemanticProperties in project flink by apache.

the class LocalPropertiesFilteringTest method testAllErased1.

@Test
public void testAllErased1() {
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, null, tupleInfo, tupleInfo);
    LocalProperties lProps = LocalProperties.forGrouping(new FieldList(0, 1, 2));
    lProps = lProps.addUniqueFields(new FieldSet(3, 4));
    lProps = lProps.addUniqueFields(new FieldSet(5, 6));
    LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
    assertNull(filtered.getGroupedFields());
    assertNull(filtered.getOrdering());
    assertNull(filtered.getUniqueFields());
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) FieldList(org.apache.flink.api.common.operators.util.FieldList) Test(org.junit.Test)

Example 85 with SingleInputSemanticProperties

use of org.apache.flink.api.common.operators.SingleInputSemanticProperties in project flink by apache.

the class LocalPropertiesFilteringTest method testUniqueFieldsPreserved3.

@Test
public void testUniqueFieldsPreserved3() {
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, new String[] { "0->7;1->6;2->5;3->4;4->3" }, null, null, tupleInfo, tupleInfo);
    LocalProperties lProps = new LocalProperties();
    lProps = lProps.addUniqueFields(new FieldSet(0, 1, 2));
    lProps = lProps.addUniqueFields(new FieldSet(3, 4));
    lProps = lProps.addUniqueFields(new FieldSet(4, 5, 6));
    LocalProperties filtered = lProps.filterBySemanticProperties(sp, 0);
    FieldSet expected1 = new FieldSet(5, 6, 7);
    FieldSet expected2 = new FieldSet(3, 4);
    assertNull(filtered.getGroupedFields());
    assertNull(filtered.getOrdering());
    assertNotNull(filtered.getUniqueFields());
    assertEquals(2, filtered.getUniqueFields().size());
    assertTrue(filtered.getUniqueFields().contains(expected1));
    assertTrue(filtered.getUniqueFields().contains(expected2));
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Aggregations

SingleInputSemanticProperties (org.apache.flink.api.common.operators.SingleInputSemanticProperties)149 Test (org.junit.Test)131 FieldSet (org.apache.flink.api.common.operators.util.FieldSet)57 FieldList (org.apache.flink.api.common.operators.util.FieldList)26 Ordering (org.apache.flink.api.common.operators.Ordering)15 Plan (org.apache.flink.api.common.Plan)14 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)14 MapOperatorBase (org.apache.flink.api.common.operators.base.MapOperatorBase)12 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)12 DualInputSemanticProperties (org.apache.flink.api.common.operators.DualInputSemanticProperties)5 SemanticProperties (org.apache.flink.api.common.operators.SemanticProperties)5 Internal (org.apache.flink.annotation.Internal)4 SelectorFunctionKeys (org.apache.flink.api.common.operators.Keys.SelectorFunctionKeys)4 InvalidSemanticAnnotationException (org.apache.flink.api.common.operators.SemanticProperties.InvalidSemanticAnnotationException)4 Matcher (java.util.regex.Matcher)3 UnaryOperatorInformation (org.apache.flink.api.common.operators.UnaryOperatorInformation)3 FlatFieldDescriptor (org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor)3 InvalidFieldReferenceException (org.apache.flink.api.common.typeutils.CompositeType.InvalidFieldReferenceException)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 Annotation (java.lang.annotation.Annotation)2