Search in sources :

Example 1 with LongValueToStringValue

use of org.apache.flink.graph.asm.translate.translators.LongValueToStringValue 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 2 with LongValueToStringValue

use of org.apache.flink.graph.asm.translate.translators.LongValueToStringValue in project flink by apache.

the class GraphKeyTypeTransform method transformInput.

@Override
public Graph<?, VV, EV> transformInput(Graph<LongValue, VV, EV> input) throws Exception {
    // Long.MAX_VALUE is much larger than the number of atoms in the Earth
    // and considered sufficient though representing 63 instead of 64 bits
    long maxVertexCount = Long.MAX_VALUE;
    TranslateFunction<LongValue, ?> translator = null;
    switch(type.getValue()) {
        case BYTE:
            maxVertexCount = LongValueToUnsignedByteValue.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedByteValue();
            break;
        case NATIVE_BYTE:
            maxVertexCount = LongValueToUnsignedByte.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedByte();
            break;
        case SHORT:
            maxVertexCount = LongValueToUnsignedShortValue.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedShortValue();
            break;
        case NATIVE_SHORT:
            maxVertexCount = LongValueToUnsignedShort.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedShort();
            break;
        case CHAR:
            maxVertexCount = LongValueToCharValue.MAX_VERTEX_COUNT;
            translator = new LongValueToCharValue();
            break;
        case NATIVE_CHAR:
            maxVertexCount = LongValueToChar.MAX_VERTEX_COUNT;
            translator = new LongValueToChar();
            break;
        case INTEGER:
            maxVertexCount = LongValueToUnsignedIntValue.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedIntValue();
            break;
        case NATIVE_INTEGER:
            maxVertexCount = LongValueToUnsignedInt.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedInt();
            break;
        case LONG:
            break;
        case NATIVE_LONG:
            translator = new LongValueToLong();
            break;
        case FLOAT:
            maxVertexCount = LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedFloatValue();
            break;
        case NATIVE_FLOAT:
            maxVertexCount = LongValueToUnsignedFloat.MAX_VERTEX_COUNT;
            translator = new LongValueToUnsignedFloat();
            break;
        case DOUBLE:
            translator = new LongValueToDoubleValue();
            break;
        case NATIVE_DOUBLE:
            translator = new LongValueToDouble();
            break;
        case STRING:
            translator = new LongValueToStringValue();
            break;
        case NATIVE_STRING:
            translator = new LongValueToString();
            break;
        default:
            throw new ProgramParametrizationException("Unknown type '" + type.getValue() + "'");
    }
    if (vertexCount > maxVertexCount) {
        throw new ProgramParametrizationException("Vertex count '" + vertexCount + "' must be no greater than " + maxVertexCount + " for type '" + type.getValue() + "'.");
    }
    if (translator == null) {
        return input;
    } else {
        return (Graph<?, VV, EV>) input.run(new TranslateGraphIds(translator));
    }
}
Also used : LongValueToUnsignedIntValue(org.apache.flink.graph.asm.translate.translators.LongValueToUnsignedIntValue) TranslateGraphIds(org.apache.flink.graph.asm.translate.TranslateGraphIds) Graph(org.apache.flink.graph.Graph) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) LongValue(org.apache.flink.types.LongValue) LongValueToStringValue(org.apache.flink.graph.asm.translate.translators.LongValueToStringValue)

Aggregations

LongValueToStringValue (org.apache.flink.graph.asm.translate.translators.LongValueToStringValue)2 LongValue (org.apache.flink.types.LongValue)2 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)1 Graph (org.apache.flink.graph.Graph)1 TranslateGraphIds (org.apache.flink.graph.asm.translate.TranslateGraphIds)1 LongValueToUnsignedIntValue (org.apache.flink.graph.asm.translate.translators.LongValueToUnsignedIntValue)1 StringValue (org.apache.flink.types.StringValue)1 Test (org.junit.Test)1