Search in sources :

Example 66 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class ReduceTranslationTests method translateGroupedReduceNoMapper.

@Test
public void translateGroupedReduceNoMapper() {
    try {
        final int parallelism = 8;
        ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism);
        DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env);
        initialData.groupBy(2).reduce(new RichReduceFunction<Tuple3<Double, StringValue, LongValue>>() {

            public Tuple3<Double, StringValue, LongValue> reduce(Tuple3<Double, StringValue, LongValue> value1, Tuple3<Double, StringValue, LongValue> value2) {
                return value1;
            }
        }).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>());
        Plan p = env.createProgramPlan();
        GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next();
        ReduceOperatorBase<?, ?> reducer = (ReduceOperatorBase<?, ?>) sink.getInput();
        // check types
        assertEquals(initialData.getType(), reducer.getOperatorInfo().getInputType());
        assertEquals(initialData.getType(), reducer.getOperatorInfo().getOutputType());
        // parallelism was not configured on the operator
        assertTrue(reducer.getParallelism() == parallelism || reducer.getParallelism() == ExecutionConfig.PARALLELISM_DEFAULT);
        // check keys
        assertArrayEquals(new int[] { 2 }, reducer.getKeyColumns(0));
        assertTrue(reducer.getInput() instanceof GenericDataSourceBase<?, ?>);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        fail("Test caused an error: " + e.getMessage());
    }
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ReduceOperatorBase(org.apache.flink.api.common.operators.base.ReduceOperatorBase) Plan(org.apache.flink.api.common.Plan) RichReduceFunction(org.apache.flink.api.common.functions.RichReduceFunction) Tuple3(org.apache.flink.api.java.tuple.Tuple3) LongValue(org.apache.flink.types.LongValue) StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 67 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class StringValueArray method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder("[");
    String separator = "";
    for (StringValue sv : this) {
        sb.append(sv.getValue()).append(separator);
        separator = ",";
    }
    sb.append("]");
    return sb.toString();
}
Also used : StringValue(org.apache.flink.types.StringValue)

Example 68 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class StringValueArrayComparatorTest method getSortedTestData.

@Override
protected StringValueArray[] getSortedTestData() {
    StringValueArray sva0 = new StringValueArray();
    StringValueArray sva1 = new StringValueArray();
    sva1.add(new StringValue("abc"));
    StringValueArray sva2 = new StringValueArray();
    sva2.add(new StringValue("qrs"));
    sva2.add(new StringValue("xyz"));
    return new StringValueArray[] { sva0, sva1, sva2 };
}
Also used : StringValue(org.apache.flink.types.StringValue)

Example 69 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class StringValueArrayTest method testBoundedArray.

@Test
public void testBoundedArray() {
    // one byte for length and one byte for character
    int count = StringValueArray.DEFAULT_CAPACITY_IN_BYTES / 2;
    ValueArray<StringValue> sva = new StringValueArray(StringValueArray.DEFAULT_CAPACITY_IN_BYTES);
    // fill the array
    for (int i = 0; i < count; i++) {
        assertFalse(sva.isFull());
        assertEquals(i, sva.size());
        assertTrue(sva.add(new StringValue(Character.toString((char) (i & 0x7F)))));
        assertEquals(i + 1, sva.size());
    }
    // array is now full
    assertTrue(sva.isFull());
    assertEquals(count, sva.size());
    // verify the array values
    int idx = 0;
    for (StringValue sv : sva) {
        assertEquals((idx++) & 0x7F, sv.getValue().charAt(0));
    }
    // add element past end of array
    assertFalse(sva.add(new StringValue(String.valueOf((char) count))));
    assertFalse(sva.addAll(sva));
    // test copy
    assertEquals(sva, sva.copy());
    // test copyTo
    StringValueArray svaTo = new StringValueArray();
    sva.copyTo(svaTo);
    assertEquals(sva, svaTo);
    // test clear
    sva.clear();
    assertEquals(0, sva.size());
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 70 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class EitherSerializerTest method testStringValueDoubleValueEither.

@Test
public void testStringValueDoubleValueEither() {
    @SuppressWarnings("unchecked") Either<StringValue, DoubleValue>[] testData = new Either[] { Left(new StringValue("banana")), Left.of(new StringValue("apple")), new Left(new StringValue("")), Right(new DoubleValue(32.0)), Right.of(new DoubleValue(Double.MIN_VALUE)), new Right(new DoubleValue(Double.MAX_VALUE)) };
    EitherTypeInfo<StringValue, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>(ValueTypeInfo.STRING_VALUE_TYPE_INFO, ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO);
    EitherSerializer<StringValue, DoubleValue> eitherSerializer = (EitherSerializer<StringValue, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig());
    SerializerTestInstance<Either<StringValue, DoubleValue>> testInstance = new EitherSerializerTestInstance<>(eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
    testInstance.testAll();
}
Also used : Left(org.apache.flink.types.Either.Left) Right(org.apache.flink.types.Either.Right) EitherTypeInfo(org.apache.flink.api.java.typeutils.EitherTypeInfo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) DoubleValue(org.apache.flink.types.DoubleValue) Either(org.apache.flink.types.Either) StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Aggregations

StringValue (org.apache.flink.types.StringValue)88 Test (org.junit.Test)61 IntValue (org.apache.flink.types.IntValue)35 LongValue (org.apache.flink.types.LongValue)21 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)15 Record (org.apache.flink.types.Record)13 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)12 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)11 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)11 DoubleValue (org.apache.flink.types.DoubleValue)11 Value (org.apache.flink.types.Value)10 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)9 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)7 Plan (org.apache.flink.api.common.Plan)7 Configuration (org.apache.flink.configuration.Configuration)7 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)7 NoSuchElementException (java.util.NoSuchElementException)6 File (java.io.File)5 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)5