Search in sources :

Example 6 with DoubleValue

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

the class HITS method runInternal.

@Override
public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input) throws Exception {
    DataSet<Tuple2<K, K>> edges = input.getEdges().map(new ExtractEdgeIDs<K, EV>()).setParallelism(parallelism).name("Extract edge IDs");
    // ID, hub, authority
    DataSet<Tuple3<K, DoubleValue, DoubleValue>> initialScores = edges.map(new InitializeScores<K>()).setParallelism(parallelism).name("Initial scores").groupBy(0).reduce(new SumScores<K>()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
    IterativeDataSet<Tuple3<K, DoubleValue, DoubleValue>> iterative = initialScores.iterate(maxIterations);
    // ID, hubbiness
    DataSet<Tuple2<K, DoubleValue>> hubbiness = iterative.coGroup(edges).where(0).equalTo(1).with(new Hubbiness<K>()).setParallelism(parallelism).name("Hub").groupBy(0).reduce(new SumScore<K>()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
    // sum-of-hubbiness-squared
    DataSet<DoubleValue> hubbinessSumSquared = hubbiness.map(new Square<K>()).setParallelism(parallelism).name("Square").reduce(new Sum()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
    // ID, new authority
    DataSet<Tuple2<K, DoubleValue>> authority = hubbiness.coGroup(edges).where(0).equalTo(0).with(new Authority<K>()).setParallelism(parallelism).name("Authority").groupBy(0).reduce(new SumScore<K>()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
    // sum-of-authority-squared
    DataSet<DoubleValue> authoritySumSquared = authority.map(new Square<K>()).setParallelism(parallelism).name("Square").reduce(new Sum()).setCombineHint(CombineHint.HASH).setParallelism(parallelism).name("Sum");
    // ID, normalized hubbiness, normalized authority
    DataSet<Tuple3<K, DoubleValue, DoubleValue>> scores = hubbiness.fullOuterJoin(authority, JoinHint.REPARTITION_SORT_MERGE).where(0).equalTo(0).with(new JoinAndNormalizeHubAndAuthority<K>()).withBroadcastSet(hubbinessSumSquared, HUBBINESS_SUM_SQUARED).withBroadcastSet(authoritySumSquared, AUTHORITY_SUM_SQUARED).setParallelism(parallelism).name("Join scores");
    DataSet<Tuple3<K, DoubleValue, DoubleValue>> passThrough;
    if (convergenceThreshold < Double.MAX_VALUE) {
        passThrough = iterative.fullOuterJoin(scores, JoinHint.REPARTITION_SORT_MERGE).where(0).equalTo(0).with(new ChangeInScores<K>()).setParallelism(parallelism).name("Change in scores");
        iterative.registerAggregationConvergenceCriterion(CHANGE_IN_SCORES, new DoubleSumAggregator(), new ScoreConvergence(convergenceThreshold));
    } else {
        passThrough = scores;
    }
    return iterative.closeWith(passThrough).map(new TranslateResult<K>()).setParallelism(parallelism).name("Map result");
}
Also used : DoubleValue(org.apache.flink.types.DoubleValue) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Tuple3(org.apache.flink.api.java.tuple.Tuple3) DoubleSumAggregator(org.apache.flink.api.common.aggregators.DoubleSumAggregator) SumScore(org.apache.flink.graph.library.link_analysis.Functions.SumScore)

Example 7 with DoubleValue

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

the class ToNullValueTest method testTranslation.

@Test
public void testTranslation() throws Exception {
    NullValue reuse = NullValue.getInstance();
    assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new DoubleValue(), reuse));
    assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new FloatValue(), reuse));
    assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new IntValue(), reuse));
    assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new LongValue(), reuse));
    assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new StringValue(), reuse));
}
Also used : NullValue(org.apache.flink.types.NullValue) DoubleValue(org.apache.flink.types.DoubleValue) LongValue(org.apache.flink.types.LongValue) FloatValue(org.apache.flink.types.FloatValue) StringValue(org.apache.flink.types.StringValue) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Example 8 with DoubleValue

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

the class OutputEmitterTest method testMultiKeys.

@Test
public void testMultiKeys() {
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> multiComp = new RecordComparatorFactory(new int[] { 0, 1, 3 }, new Class[] { IntValue.class, StringValue.class, DoubleValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> oe1 = new OutputEmitter<Record>(ShipStrategyType.PARTITION_HASH, multiComp);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<Record>(new RecordSerializerFactory().getSerializer());
    int numChannels = 100;
    int numRecords = 5000;
    int[] hit = new int[numChannels];
    for (int i = 0; i < numRecords; i++) {
        Record rec = new Record(4);
        rec.setField(0, new IntValue(i));
        rec.setField(1, new StringValue("AB" + i + "CD" + i));
        rec.setField(3, new DoubleValue(i * 3.141d));
        delegate.setInstance(rec);
        int[] chans = oe1.selectChannels(delegate, hit.length);
        for (int chan : chans) {
            hit[chan]++;
        }
    }
    int cnt = 0;
    for (int aHit : hit) {
        assertTrue(aHit > 0);
        cnt += aHit;
    }
    assertTrue(cnt == numRecords);
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) RecordSerializerFactory(org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) OutputEmitter(org.apache.flink.runtime.operators.shipping.OutputEmitter) DoubleValue(org.apache.flink.types.DoubleValue) Record(org.apache.flink.types.Record) StringValue(org.apache.flink.types.StringValue) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Aggregations

DoubleValue (org.apache.flink.types.DoubleValue)8 Test (org.junit.Test)4 Random (java.util.Random)2 IntValue (org.apache.flink.types.IntValue)2 StringValue (org.apache.flink.types.StringValue)2 ArrayList (java.util.ArrayList)1 DoubleSumAggregator (org.apache.flink.api.common.aggregators.DoubleSumAggregator)1 DoubleValueSerializer (org.apache.flink.api.common.typeutils.base.DoubleValueSerializer)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1 BooleanColumnSummary (org.apache.flink.api.java.summarize.BooleanColumnSummary)1 StringColumnSummary (org.apache.flink.api.java.summarize.StringColumnSummary)1 Tuple (org.apache.flink.api.java.tuple.Tuple)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)1 Tuple8 (org.apache.flink.api.java.tuple.Tuple8)1 SumScore (org.apache.flink.graph.library.link_analysis.Functions.SumScore)1 OutputEmitter (org.apache.flink.runtime.operators.shipping.OutputEmitter)1 SerializationDelegate (org.apache.flink.runtime.plugable.SerializationDelegate)1 RecordComparatorFactory (org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory)1 RecordSerializerFactory (org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory)1