Search in sources :

Example 1 with Shuffle

use of org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.Shuffle in project flink by apache.

the class ShuffleJsonDeserializer method deserialize.

@Override
public Shuffle deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
    Shuffle.Type type = Shuffle.Type.valueOf(jsonNode.get("type").asText().toUpperCase());
    switch(type) {
        case ANY:
            return ExecEdge.ANY_SHUFFLE;
        case SINGLETON:
            return ExecEdge.SINGLETON_SHUFFLE;
        case BROADCAST:
            return ExecEdge.BROADCAST_SHUFFLE;
        case FORWARD:
            return ExecEdge.FORWARD_SHUFFLE;
        case HASH:
            JsonNode keysNode = jsonNode.get("keys");
            if (keysNode == null || keysNode.size() == 0) {
                throw new TableException("Hash shuffle requires non-empty hash keys.");
            }
            int[] keys = new int[keysNode.size()];
            for (int i = 0; i < keysNode.size(); ++i) {
                keys[i] = keysNode.get(i).asInt();
            }
            return ExecEdge.hashShuffle(keys);
        default:
            throw new TableException("Unsupported shuffle type: " + type);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) Shuffle(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.Shuffle) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)

Example 2 with Shuffle

use of org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.Shuffle in project flink by apache.

the class ShuffleJsonSerializer method serialize.

@Override
public void serialize(Shuffle shuffle, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeStartObject();
    Shuffle.Type type = shuffle.getType();
    jsonGenerator.writeStringField("type", type.name());
    switch(type) {
        case ANY:
        case SINGLETON:
        case BROADCAST:
        case FORWARD:
            // do nothing, type name is enough
            break;
        case HASH:
            HashShuffle hashShuffle = (HashShuffle) shuffle;
            jsonGenerator.writeFieldName("keys");
            jsonGenerator.writeArray(hashShuffle.getKeys(), // offset
            0, hashShuffle.getKeys().length);
            break;
        default:
            throw new TableException("Unsupported shuffle type: " + type);
    }
    jsonGenerator.writeEndObject();
}
Also used : TableException(org.apache.flink.table.api.TableException) Shuffle(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.Shuffle) HashShuffle(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.HashShuffle) HashShuffle(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.HashShuffle)

Aggregations

TableException (org.apache.flink.table.api.TableException)2 Shuffle (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.Shuffle)2 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)1 HashShuffle (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge.HashShuffle)1