Search in sources :

Example 11 with StringValue

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

the class ReduceTranslationTests method translateNonGroupedReduce.

@Test
public void translateNonGroupedReduce() {
    try {
        final int parallelism = 8;
        ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(parallelism);
        DataSet<Tuple3<Double, StringValue, LongValue>> initialData = getSourceDataSet(env);
        initialData.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());
        // check keys
        assertTrue(reducer.getKeyColumns(0) == null || reducer.getKeyColumns(0).length == 0);
        // parallelism was not configured on the operator
        assertTrue(reducer.getParallelism() == 1 || reducer.getParallelism() == ExecutionConfig.PARALLELISM_DEFAULT);
        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 12 with StringValue

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

the class LongValueToStringValueTest method testTranslation.

@Test
public void testTranslation() throws Exception {
    StringValue reuse = new StringValue();
    assertEquals(new StringValue("-9223372036854775808"), translator.translate(new LongValue(Long.MIN_VALUE), reuse));
    assertEquals(new StringValue("0"), translator.translate(new LongValue(0), reuse));
    assertEquals(new StringValue("9223372036854775807"), translator.translate(new LongValue(Long.MAX_VALUE), reuse));
}
Also used : LongValue(org.apache.flink.types.LongValue) StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 13 with StringValue

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

the class TranslateTest method testTranslateGraphIds.

@Test
public void testTranslateGraphIds() throws Exception {
    Graph<StringValue, LongValue, LongValue> stringIdGraph = graph.translateGraphIds(new LongValueToStringValue());
    for (Vertex<StringValue, LongValue> vertex : stringIdGraph.getVertices().collect()) {
        assertEquals(StringValue.class, vertex.f0.getClass());
        assertEquals(LongValue.class, vertex.f1.getClass());
    }
    for (Edge<StringValue, LongValue> edge : stringIdGraph.getEdges().collect()) {
        assertEquals(StringValue.class, edge.f0.getClass());
        assertEquals(StringValue.class, edge.f1.getClass());
        assertEquals(LongValue.class, edge.f2.getClass());
    }
    TestBaseUtils.compareResultAsText(stringIdGraph.getVertices().collect(), expectedVertexResult);
    TestBaseUtils.compareResultAsText(stringIdGraph.getEdges().collect(), expectedEdgeResult);
}
Also used : LongValue(org.apache.flink.types.LongValue) LongValueToStringValue(org.apache.flink.graph.asm.translate.translators.LongValueToStringValue) StringValue(org.apache.flink.types.StringValue) LongValueToStringValue(org.apache.flink.graph.asm.translate.translators.LongValueToStringValue) Test(org.junit.Test)

Example 14 with StringValue

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

the class StringValueUtilsTest method testReplaceNonWordChars.

@Test
public void testReplaceNonWordChars() {
    StringValue testString = new StringValue("TEST123_@");
    StringValueUtils.replaceNonWordChars(testString, '!');
    assertEquals(new StringValue("TEST123_!"), testString);
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 15 with StringValue

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

the class StringValueUtilsTest method testTokenizerOnStringWithNexToken.

@Test
public void testTokenizerOnStringWithNexToken() {
    StringValue testString = new StringValue("test test");
    StringValueUtils.WhitespaceTokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setStringToTokenize(testString);
    assertTrue(tokenizer.next(testString));
}
Also used : WhitespaceTokenizer(org.apache.flink.util.StringValueUtils.WhitespaceTokenizer) StringValue(org.apache.flink.types.StringValue) WhitespaceTokenizer(org.apache.flink.util.StringValueUtils.WhitespaceTokenizer) 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