use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty.DistributionType in project flink by apache.
the class RequiredDistributionJsonDeserializer method deserialize.
@Override
public RequiredDistribution deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
DistributionType type = DistributionType.valueOf(jsonNode.get("type").asText().toUpperCase());
switch(type) {
case ANY:
return InputProperty.ANY_DISTRIBUTION;
case SINGLETON:
return InputProperty.SINGLETON_DISTRIBUTION;
case BROADCAST:
return InputProperty.BROADCAST_DISTRIBUTION;
case UNKNOWN:
return InputProperty.UNKNOWN_DISTRIBUTION;
case HASH:
JsonNode keysNode = jsonNode.get("keys");
if (keysNode == null) {
throw new TableException("Hash distribution 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 InputProperty.hashDistribution(keys);
default:
throw new TableException("Unsupported distribution type: " + type);
}
}
use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty.DistributionType in project flink by apache.
the class RequiredDistributionJsonSerializer method serialize.
@Override
public void serialize(RequiredDistribution requiredDistribution, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
DistributionType type = requiredDistribution.getType();
jsonGenerator.writeStringField("type", type.name());
switch(type) {
case ANY:
case SINGLETON:
case BROADCAST:
case UNKNOWN:
// do nothing, type name is enough
break;
case HASH:
HashDistribution hashDistribution = (HashDistribution) requiredDistribution;
jsonGenerator.writeFieldName("keys");
jsonGenerator.writeArray(hashDistribution.getKeys(), // offset
0, hashDistribution.getKeys().length);
break;
default:
throw new TableException("Unsupported distribution type: " + type);
}
jsonGenerator.writeEndObject();
}
Aggregations