Search in sources :

Example 26 with LongValue

use of org.apache.flink.types.LongValue 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 27 with LongValue

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

the class ReduceTranslationTests method translateGroupedReduceWithkeyExtractor.

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

            public StringValue getKey(Tuple3<Double, StringValue, LongValue> value) {
                return value.f1;
            }
        }).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;
            }
        }).setParallelism(4).output(new DiscardingOutputFormat<Tuple3<Double, StringValue, LongValue>>());
        Plan p = env.createProgramPlan();
        GenericDataSinkBase<?> sink = p.getDataSinks().iterator().next();
        MapOperatorBase<?, ?, ?> keyProjector = (MapOperatorBase<?, ?, ?>) sink.getInput();
        PlanUnwrappingReduceOperator<?, ?> reducer = (PlanUnwrappingReduceOperator<?, ?>) keyProjector.getInput();
        MapOperatorBase<?, ?, ?> keyExtractor = (MapOperatorBase<?, ?, ?>) reducer.getInput();
        // check the parallelisms
        assertEquals(1, keyExtractor.getParallelism());
        assertEquals(4, reducer.getParallelism());
        assertEquals(4, keyProjector.getParallelism());
        // check types
        TypeInformation<?> keyValueInfo = new TupleTypeInfo<Tuple2<StringValue, Tuple3<Double, StringValue, LongValue>>>(new ValueTypeInfo<StringValue>(StringValue.class), initialData.getType());
        assertEquals(initialData.getType(), keyExtractor.getOperatorInfo().getInputType());
        assertEquals(keyValueInfo, keyExtractor.getOperatorInfo().getOutputType());
        assertEquals(keyValueInfo, reducer.getOperatorInfo().getInputType());
        assertEquals(keyValueInfo, reducer.getOperatorInfo().getOutputType());
        assertEquals(keyValueInfo, keyProjector.getOperatorInfo().getInputType());
        assertEquals(initialData.getType(), keyProjector.getOperatorInfo().getOutputType());
        // check keys
        assertEquals(KeyExtractingMapper.class, keyExtractor.getUserCodeWrapper().getUserCodeClass());
        assertTrue(keyExtractor.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) KeySelector(org.apache.flink.api.java.functions.KeySelector) Plan(org.apache.flink.api.common.Plan) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo) MapOperatorBase(org.apache.flink.api.common.operators.base.MapOperatorBase) 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 28 with LongValue

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

the class LongValueComparatorTest method getSortedTestData.

@Override
protected LongValue[] getSortedTestData() {
    Random rnd = new Random(874597969123412338L);
    long rndLong = rnd.nextLong();
    if (rndLong < 0) {
        rndLong = -rndLong;
    }
    if (rndLong == Long.MAX_VALUE) {
        rndLong -= 3;
    }
    if (rndLong <= 2) {
        rndLong += 3;
    }
    return new LongValue[] { new LongValue(Long.MIN_VALUE), new LongValue(-rndLong), new LongValue(-1L), new LongValue(0L), new LongValue(1L), new LongValue(2L), new LongValue(rndLong), new LongValue(Long.MAX_VALUE) };
}
Also used : Random(java.util.Random) LongValue(org.apache.flink.types.LongValue)

Example 29 with LongValue

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

the class LongValueComparator method compareToReference.

@Override
public int compareToReference(TypeComparator<LongValue> referencedComparator) {
    LongValue otherRef = ((LongValueComparator) referencedComparator).reference;
    int comp = otherRef.compareTo(reference);
    return ascendingComparison ? comp : -comp;
}
Also used : LongValue(org.apache.flink.types.LongValue)

Example 30 with LongValue

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

the class GenericCsvInputFormatTest method testLongLongLong.

@Test
public void testLongLongLong() {
    try {
        final String fileContent = "1,2,3\n3,2,1";
        final FileInputSplit split = createTempFile(fileContent);
        final Configuration parameters = new Configuration();
        format.setFieldDelimiter(",");
        format.setFieldTypesGeneric(LongValue.class, LongValue.class, LongValue.class);
        format.configure(parameters);
        format.open(split);
        Value[] values = createLongValues(3);
        values = format.nextRecord(values);
        assertNotNull(values);
        assertEquals(1L, ((LongValue) values[0]).getValue());
        assertEquals(2L, ((LongValue) values[1]).getValue());
        assertEquals(3L, ((LongValue) values[2]).getValue());
        values = format.nextRecord(values);
        assertNotNull(values);
        assertEquals(3L, ((LongValue) values[0]).getValue());
        assertEquals(2L, ((LongValue) values[1]).getValue());
        assertEquals(1L, ((LongValue) values[2]).getValue());
        assertNull(format.nextRecord(values));
        assertTrue(format.reachedEnd());
    } catch (Exception ex) {
        System.err.println(ex.getMessage());
        ex.printStackTrace();
        fail("Test erroneous");
    }
}
Also used : FileInputSplit(org.apache.flink.core.fs.FileInputSplit) Configuration(org.apache.flink.configuration.Configuration) IntValue(org.apache.flink.types.IntValue) DoubleValue(org.apache.flink.types.DoubleValue) LongValue(org.apache.flink.types.LongValue) Value(org.apache.flink.types.Value) StringValue(org.apache.flink.types.StringValue) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

LongValue (org.apache.flink.types.LongValue)50 Test (org.junit.Test)33 NullValue (org.apache.flink.types.NullValue)23 Checksum (org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum)17 ChecksumHashCode (org.apache.flink.graph.asm.dataset.ChecksumHashCode)15 Edge (org.apache.flink.graph.Edge)13 StringValue (org.apache.flink.types.StringValue)13 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)12 Vertex (org.apache.flink.graph.Vertex)11 IntValue (org.apache.flink.types.IntValue)9 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 JDKRandomGeneratorFactory (org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory)7 NumberFormat (java.text.NumberFormat)6 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)6 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)6 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)6 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)6 RMatGraph (org.apache.flink.graph.generator.RMatGraph)6 Graph (org.apache.flink.graph.Graph)5 GraphCsvReader (org.apache.flink.graph.GraphCsvReader)5