Search in sources :

Example 21 with LongValue

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

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

the class LongValueAddOffsetTest method testTranslation.

@Test
public void testTranslation() throws Exception {
    LongValue reuse = new LongValue();
    assertEquals(new LongValue(0), new LongValueAddOffset(0).translate(new LongValue(0), reuse));
    assertEquals(new LongValue(3), new LongValueAddOffset(1).translate(new LongValue(2), reuse));
    assertEquals(new LongValue(1), new LongValueAddOffset(-1).translate(new LongValue(2), reuse));
    assertEquals(new LongValue(-1), new LongValueAddOffset(Long.MIN_VALUE).translate(new LongValue(Long.MAX_VALUE), reuse));
    assertEquals(new LongValue(-1), new LongValueAddOffset(Long.MAX_VALUE).translate(new LongValue(Long.MIN_VALUE), reuse));
    // underflow wraps to positive values
    assertEquals(new LongValue(Long.MAX_VALUE), new LongValueAddOffset(-1).translate(new LongValue(Long.MIN_VALUE), reuse));
    assertEquals(new LongValue(0), new LongValueAddOffset(Long.MIN_VALUE).translate(new LongValue(Long.MIN_VALUE), reuse));
    // overflow wraps to negative values
    assertEquals(new LongValue(Long.MIN_VALUE), new LongValueAddOffset(1).translate(new LongValue(Long.MAX_VALUE), reuse));
    assertEquals(new LongValue(-2), new LongValueAddOffset(Long.MAX_VALUE).translate(new LongValue(Long.MAX_VALUE), reuse));
}
Also used : LongValue(org.apache.flink.types.LongValue) Test(org.junit.Test)

Example 23 with LongValue

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

the class VertexMetricsTest method testWithEmptyGraph.

@Test
public void testWithEmptyGraph() throws Exception {
    Result expectedResult;
    expectedResult = new Result(0, 0, 0, 0, 0, 0, 0, 0);
    Result withoutZeroDegreeVertices = new VertexMetrics<LongValue, NullValue, NullValue>().setIncludeZeroDegreeVertices(false).run(emptyGraph).execute();
    assertEquals(expectedResult, withoutZeroDegreeVertices);
    assertEquals(Float.NaN, withoutZeroDegreeVertices.getAverageDegree(), ACCURACY);
    assertEquals(Float.NaN, withoutZeroDegreeVertices.getDensity(), ACCURACY);
    expectedResult = new Result(3, 0, 0, 0, 0, 0, 0, 0);
    Result withZeroDegreeVertices = new VertexMetrics<LongValue, NullValue, NullValue>().setIncludeZeroDegreeVertices(true).run(emptyGraph).execute();
    assertEquals(expectedResult, withZeroDegreeVertices);
    assertEquals(0.0f, withZeroDegreeVertices.getAverageDegree(), ACCURACY);
    assertEquals(0.0f, withZeroDegreeVertices.getDensity(), ACCURACY);
}
Also used : NullValue(org.apache.flink.types.NullValue) LongValue(org.apache.flink.types.LongValue) Result(org.apache.flink.graph.library.metric.directed.VertexMetrics.Result) Test(org.junit.Test)

Example 24 with LongValue

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

the class JaccardIndexTest method testRMatGraph.

@Test
public void testRMatGraph() throws Exception {
    long vertexCount = 1 << 8;
    long edgeCount = 8 * vertexCount;
    RandomGenerableFactory<JDKRandomGenerator> rnd = new JDKRandomGeneratorFactory();
    Graph<LongValue, NullValue, NullValue> graph = new RMatGraph<>(env, rnd, vertexCount, edgeCount).generate().run(new Simplify<LongValue, NullValue, NullValue>(false));
    DataSet<Result<LongValue>> ji = graph.run(new JaccardIndex<LongValue, NullValue, NullValue>().setGroupSize(4));
    Checksum checksum = new ChecksumHashCode<Result<LongValue>>().run(ji).execute();
    assertEquals(13954, checksum.getCount());
    assertEquals(0x00001b1a1f7a9d0bL, checksum.getChecksum());
}
Also used : JDKRandomGeneratorFactory(org.apache.flink.graph.generator.random.JDKRandomGeneratorFactory) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Result(org.apache.flink.graph.library.similarity.JaccardIndex.Result) RMatGraph(org.apache.flink.graph.generator.RMatGraph) NullValue(org.apache.flink.types.NullValue) Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) LongValue(org.apache.flink.types.LongValue) JDKRandomGenerator(org.apache.commons.math3.random.JDKRandomGenerator) Test(org.junit.Test)

Example 25 with LongValue

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

the class TriangleListingTest method testRMatGraph.

@Test
public void testRMatGraph() throws Exception {
    DataSet<Result<LongValue>> tl = directedRMatGraph.run(new TriangleListing<LongValue, NullValue, NullValue>().setSortTriangleVertices(true));
    Checksum checksum = new ChecksumHashCode<Result<LongValue>>().run(tl).execute();
    assertEquals(75049, checksum.getCount());
    assertEquals(0x00000033111f11baL, checksum.getChecksum());
}
Also used : Checksum(org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum) LongValue(org.apache.flink.types.LongValue) ChecksumHashCode(org.apache.flink.graph.asm.dataset.ChecksumHashCode) Result(org.apache.flink.graph.library.clustering.directed.TriangleListing.Result) 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