Search in sources :

Example 11 with Tuple

use of org.apache.flink.api.java.tuple.Tuple in project flink by apache.

the class StormTupleTest method testBooleanTuple.

@Test
public void testBooleanTuple() {
    final Boolean data = this.r.nextBoolean();
    final int index = this.r.nextInt(5);
    final Tuple flinkTuple = new Tuple5<Object, Object, Object, Object, Object>();
    flinkTuple.setField(data, index);
    final StormTuple<Tuple> tuple = new StormTuple<Tuple>(flinkTuple, null, -1, null, null, null);
    Assert.assertEquals(flinkTuple.getField(index), tuple.getBoolean(index));
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest)

Example 12 with Tuple

use of org.apache.flink.api.java.tuple.Tuple in project flink by apache.

the class StormTupleTest method testSelect.

@Test
public void testSelect() throws Exception {
    Tuple tuple = Tuple.getTupleClass(arity).newInstance();
    Values values = new Values();
    ArrayList<String> attributeNames = new ArrayList<String>(arity);
    ArrayList<String> filterNames = new ArrayList<String>(arity);
    for (int i = 0; i < arity; ++i) {
        tuple.setField(i, i);
        attributeNames.add("a" + i);
        if (r.nextBoolean()) {
            filterNames.add("a" + i);
            values.add(i);
        }
    }
    Fields schema = new Fields(attributeNames);
    Fields selector = new Fields(filterNames);
    Assert.assertEquals(values, new StormTuple<>(tuple, schema, -1, null, null, null).select(selector));
}
Also used : Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) ArrayList(java.util.ArrayList) Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest)

Example 13 with Tuple

use of org.apache.flink.api.java.tuple.Tuple in project flink by apache.

the class StormTupleTest method testIntegerTuple.

@Test
public void testIntegerTuple() {
    final Integer data = this.r.nextInt();
    final int index = this.r.nextInt(5);
    final Tuple flinkTuple = new Tuple5<Object, Object, Object, Object, Object>();
    flinkTuple.setField(data, index);
    final StormTuple<Tuple> tuple = new StormTuple<Tuple>(flinkTuple, null, -1, null, null, null);
    Assert.assertEquals(flinkTuple.getField(index), tuple.getInteger(index));
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest)

Example 14 with Tuple

use of org.apache.flink.api.java.tuple.Tuple in project flink by apache.

the class StormTupleTest method tupleTestWithTaskId.

@Test
public void tupleTestWithTaskId() throws InstantiationException, IllegalAccessException {
    for (int numberOfAttributes = 1; numberOfAttributes < 26; ++numberOfAttributes) {
        final Object[] data = new Object[numberOfAttributes];
        final Tuple flinkTuple = Tuple.getTupleClass(numberOfAttributes).newInstance();
        for (int i = 0; i < numberOfAttributes - 1; ++i) {
            data[i] = this.r.nextInt();
            flinkTuple.setField(data[i], i);
        }
        final StormTuple<Tuple> tuple = new StormTuple<Tuple>(flinkTuple, null, 0, null, null, null);
        final List<Object> values = tuple.getValues();
        Assert.assertEquals(numberOfAttributes - 1, values.size());
        for (int i = 0; i < numberOfAttributes - 1; ++i) {
            Assert.assertEquals(flinkTuple.getField(i), values.get(i));
        }
        Assert.assertEquals(numberOfAttributes - 1, tuple.size());
    }
}
Also used : Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest)

Example 15 with Tuple

use of org.apache.flink.api.java.tuple.Tuple in project flink by apache.

the class ReplicatingDataSourceITCase method testReplicatedSourceToJoin.

@Test
public void testReplicatedSourceToJoin() throws Exception {
    /*
		 * Test replicated source going into join
		 */
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple1<Long>> source1 = env.createInput(new ReplicatingInputFormat<Long, GenericInputSplit>(new ParallelIteratorInputFormat<Long>(new NumberSequenceIterator(0l, 1000l))), BasicTypeInfo.LONG_TYPE_INFO).map(new ToTuple());
    DataSet<Tuple1<Long>> source2 = env.generateSequence(0l, 1000l).map(new ToTuple());
    DataSet<Tuple> pairs = source1.join(source2).where(0).equalTo(0).projectFirst(0).sum(0);
    List<Tuple> result = pairs.collect();
    String expectedResult = "(500500)";
    compareResultAsText(result, expectedResult);
}
Also used : ReplicatingInputFormat(org.apache.flink.api.common.io.ReplicatingInputFormat) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Tuple1(org.apache.flink.api.java.tuple.Tuple1) Tuple(org.apache.flink.api.java.tuple.Tuple) NumberSequenceIterator(org.apache.flink.util.NumberSequenceIterator) Test(org.junit.Test)

Aggregations

Tuple (org.apache.flink.api.java.tuple.Tuple)59 Test (org.junit.Test)38 AbstractTest (org.apache.flink.storm.util.AbstractTest)17 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)14 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)14 TimeWindow (org.apache.flink.streaming.api.windowing.windows.TimeWindow)13 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)10 ArrayList (java.util.ArrayList)9 Configuration (org.apache.flink.configuration.Configuration)8 SuccessException (org.apache.flink.test.util.SuccessException)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)6 Fields (org.apache.storm.tuple.Fields)6 Tuple4 (org.apache.flink.api.java.tuple.Tuple4)5 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)5 Keys (org.apache.flink.api.common.operators.Keys)4 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)4 ComparableAggregator (org.apache.flink.streaming.api.functions.aggregation.ComparableAggregator)4 Values (org.apache.storm.tuple.Values)4