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);
}
}
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();
}
Aggregations