Search in sources :

Example 1 with DistributionType

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);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) DistributionType(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.DistributionType)

Example 2 with DistributionType

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();
}
Also used : TableException(org.apache.flink.table.api.TableException) HashDistribution(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.HashDistribution) DistributionType(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.DistributionType)

Aggregations

TableException (org.apache.flink.table.api.TableException)2 DistributionType (org.apache.flink.table.planner.plan.nodes.exec.InputProperty.DistributionType)2 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)1 HashDistribution (org.apache.flink.table.planner.plan.nodes.exec.InputProperty.HashDistribution)1