Search in sources :

Example 31 with FieldSet

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

the class SingleInputSemanticPropertiesTest method testGetReadFieldsInvalidIndex.

@Test(expected = IndexOutOfBoundsException.class)
public void testGetReadFieldsInvalidIndex() {
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    sp.addReadFields(new FieldSet(0, 1));
    sp.getReadFields(1);
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) Test(org.junit.Test)

Example 32 with FieldSet

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

the class SemanticPropUtil method addSourceFieldOffsets.

/**
 * Creates SemanticProperties by adding offsets to each input field index of the given
 * SemanticProperties.
 *
 * @param props The SemanticProperties to which the offset is added.
 * @param numInputFields1 The original number of fields of the first input.
 * @param numInputFields2 The original number of fields of the second input.
 * @param offset1 The offset that is added to each input field index of the first input.
 * @param offset2 The offset that is added to each input field index of the second input.
 * @return New SemanticProperties with added offsets.
 */
public static DualInputSemanticProperties addSourceFieldOffsets(DualInputSemanticProperties props, int numInputFields1, int numInputFields2, int offset1, int offset2) {
    DualInputSemanticProperties offsetProps = new DualInputSemanticProperties();
    // add offset to read fields on first input
    if (props.getReadFields(0) != null) {
        FieldSet offsetReadFields = new FieldSet();
        for (int r : props.getReadFields(0)) {
            offsetReadFields = offsetReadFields.addField(r + offset1);
        }
        offsetProps.addReadFields(0, offsetReadFields);
    }
    // add offset to read fields on second input
    if (props.getReadFields(1) != null) {
        FieldSet offsetReadFields = new FieldSet();
        for (int r : props.getReadFields(1)) {
            offsetReadFields = offsetReadFields.addField(r + offset2);
        }
        offsetProps.addReadFields(1, offsetReadFields);
    }
    // add offset to forward fields on first input
    for (int s = 0; s < numInputFields1; s++) {
        FieldSet targetFields = props.getForwardingTargetFields(0, s);
        for (int t : targetFields) {
            offsetProps.addForwardedField(0, s + offset1, t);
        }
    }
    // add offset to forward fields on second input
    for (int s = 0; s < numInputFields2; s++) {
        FieldSet targetFields = props.getForwardingTargetFields(1, s);
        for (int t : targetFields) {
            offsetProps.addForwardedField(1, s + offset2, t);
        }
    }
    return offsetProps;
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) DualInputSemanticProperties(org.apache.flink.api.common.operators.DualInputSemanticProperties)

Example 33 with FieldSet

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

the class SemanticPropUtil method addSourceFieldOffset.

/**
 * Creates SemanticProperties by adding an offset to each input field index of the given
 * SemanticProperties.
 *
 * @param props The SemanticProperties to which the offset is added.
 * @param numInputFields The original number of fields of the input.
 * @param offset The offset that is added to each input field index.
 * @return New SemanticProperties with added offset.
 */
public static SingleInputSemanticProperties addSourceFieldOffset(SingleInputSemanticProperties props, int numInputFields, int offset) {
    SingleInputSemanticProperties offsetProps = new SingleInputSemanticProperties();
    if (props.getReadFields(0) != null) {
        FieldSet offsetReadFields = new FieldSet();
        for (int r : props.getReadFields(0)) {
            offsetReadFields = offsetReadFields.addField(r + offset);
        }
        offsetProps.addReadFields(offsetReadFields);
    }
    for (int s = 0; s < numInputFields; s++) {
        FieldSet targetFields = props.getForwardingTargetFields(0, s);
        for (int t : targetFields) {
            offsetProps.addForwardedField(s + offset, t);
        }
    }
    return offsetProps;
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties)

Example 34 with FieldSet

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

the class SemanticPropUtilTest method testReadFieldsSpaces.

@Test
public void testReadFieldsSpaces() {
    String[] readFields = { "  f1  ; f2   " };
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);
    FieldSet fs = sp.getReadFields(0);
    assertTrue(fs.size() == 2);
    assertTrue(fs.contains(2));
    assertTrue(fs.contains(1));
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

Example 35 with FieldSet

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

the class SemanticPropUtilTest method testReadFieldsOneString.

@Test
public void testReadFieldsOneString() {
    String[] readFields = { "f1;f2" };
    SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);
    FieldSet fs = sp.getReadFields(0);
    assertTrue(fs.size() == 2);
    assertTrue(fs.contains(2));
    assertTrue(fs.contains(1));
    readFields[0] = "f1;f2;";
    sp = new SingleInputSemanticProperties();
    SemanticPropUtil.getSemanticPropsSingleFromString(sp, null, null, readFields, threeIntTupleType, threeIntTupleType);
    fs = sp.getReadFields(0);
    assertTrue(fs.size() == 2);
    assertTrue(fs.contains(2));
    assertTrue(fs.contains(1));
}
Also used : FieldSet(org.apache.flink.api.common.operators.util.FieldSet) SingleInputSemanticProperties(org.apache.flink.api.common.operators.SingleInputSemanticProperties) Test(org.junit.Test)

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