Search in sources :

Example 6 with Builder

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvSchema.Builder in project flink by apache.

the class RexNodeJsonDeserializer method deserializeSarg.

@SuppressWarnings({ "UnstableApiUsage", "rawtypes", "unchecked" })
private static RexNode deserializeSarg(JsonNode sargNode, RelDataType relDataType, SerdeContext serdeContext) {
    final RexBuilder rexBuilder = serdeContext.getRexBuilder();
    final ArrayNode rangesNode = (ArrayNode) sargNode.required(FIELD_NAME_RANGES);
    final Builder builder = builder();
    for (JsonNode rangeNode : rangesNode) {
        Range range = all();
        if (rangeNode.has(FIELD_NAME_BOUND_LOWER)) {
            final JsonNode lowerNode = rangeNode.required(FIELD_NAME_BOUND_LOWER);
            final Comparable<?> boundValue = (Comparable<?>) deserializeLiteralValue(lowerNode, relDataType.getSqlTypeName(), serdeContext);
            assert boundValue != null;
            final BoundType boundType = serializableToCalcite(BoundType.class, lowerNode.required(FIELD_NAME_BOUND_TYPE).asText());
            final Range<?> r = boundType == BoundType.OPEN ? greaterThan(boundValue) : atLeast(boundValue);
            range = range.intersection(r);
        }
        if (rangeNode.has(FIELD_NAME_BOUND_UPPER)) {
            final JsonNode upperNode = rangeNode.required(FIELD_NAME_BOUND_UPPER);
            final Comparable<?> boundValue = (Comparable<?>) deserializeLiteralValue(upperNode, relDataType.getSqlTypeName(), serdeContext);
            assert boundValue != null;
            final BoundType boundType = serializableToCalcite(BoundType.class, upperNode.required(FIELD_NAME_BOUND_TYPE).asText());
            final Range<?> r = boundType == BoundType.OPEN ? lessThan(boundValue) : atMost(boundValue);
            range = range.intersection(r);
        }
        if (range.hasUpperBound() || range.hasLowerBound()) {
            builder.add(range);
        }
    }
    final boolean containsNull = sargNode.required(FIELD_NAME_CONTAINS_NULL).booleanValue();
    return rexBuilder.makeSearchArgumentLiteral(Sarg.of(containsNull, builder.build()), relDataType);
}
Also used : BoundType(com.google.common.collect.BoundType) Builder(com.google.common.collect.ImmutableRangeSet.Builder) RexBuilder(org.apache.calcite.rex.RexBuilder) RexBuilder(org.apache.calcite.rex.RexBuilder) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) ArrayNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode) Range(com.google.common.collect.Range)

Example 7 with Builder

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvSchema.Builder in project flink by apache.

the class LogicalTypeJsonDeserializer method deserializeStructuredTypeFromPlan.

private static LogicalType deserializeStructuredTypeFromPlan(JsonNode logicalTypeNode, SerdeContext serdeContext) {
    final ObjectIdentifier identifier;
    if (logicalTypeNode.has(FIELD_NAME_OBJECT_IDENTIFIER)) {
        identifier = ObjectIdentifierJsonDeserializer.deserialize(logicalTypeNode.get(FIELD_NAME_OBJECT_IDENTIFIER).asText(), serdeContext);
    } else {
        identifier = null;
    }
    final Class<?> implementationClass;
    if (logicalTypeNode.has(FIELD_NAME_IMPLEMENTATION_CLASS)) {
        implementationClass = loadClass(logicalTypeNode.get(FIELD_NAME_IMPLEMENTATION_CLASS).asText(), serdeContext, "structured type");
    } else {
        implementationClass = null;
    }
    final StructuredType.Builder builder;
    if (identifier != null && implementationClass != null) {
        builder = StructuredType.newBuilder(identifier, implementationClass);
    } else if (identifier != null) {
        builder = StructuredType.newBuilder(identifier);
    } else {
        builder = StructuredType.newBuilder(implementationClass);
    }
    if (logicalTypeNode.has(FIELD_NAME_DESCRIPTION)) {
        builder.description(logicalTypeNode.get(FIELD_NAME_FIELD_DESCRIPTION).asText());
    }
    final ArrayNode attributeNodes = (ArrayNode) logicalTypeNode.get(FIELD_NAME_ATTRIBUTES);
    final List<StructuredAttribute> attributes = new ArrayList<>();
    for (JsonNode attributeNode : attributeNodes) {
        final String attributeName = attributeNode.get(FIELD_NAME_ATTRIBUTE_NAME).asText();
        final LogicalType attributeType = deserialize(attributeNode.get(FIELD_NAME_ATTRIBUTE_TYPE), serdeContext);
        final String attributeDescription;
        if (attributeNode.has(FIELD_NAME_ATTRIBUTE_DESCRIPTION)) {
            attributeDescription = attributeNode.get(FIELD_NAME_ATTRIBUTE_DESCRIPTION).asText();
        } else {
            attributeDescription = null;
        }
        attributes.add(new StructuredAttribute(attributeName, attributeType, attributeDescription));
    }
    builder.attributes(attributes);
    if (logicalTypeNode.has(FIELD_NAME_FINAL)) {
        builder.setFinal(logicalTypeNode.get(FIELD_NAME_FINAL).asBoolean());
    }
    if (logicalTypeNode.has(FIELD_NAME_INSTANTIABLE)) {
        builder.setInstantiable(logicalTypeNode.get(FIELD_NAME_INSTANTIABLE).asBoolean());
    }
    if (logicalTypeNode.has(FIELD_NAME_COMPARISON)) {
        builder.comparison(StructuredComparison.valueOf(logicalTypeNode.get(FIELD_NAME_COMPARISON).asText()));
    }
    if (logicalTypeNode.has(FIELD_NAME_SUPER_TYPE)) {
        final StructuredType superType = (StructuredType) deserialize(logicalTypeNode.get(FIELD_NAME_SUPER_TYPE), serdeContext);
        builder.superType(superType);
    }
    return builder.build();
}
Also used : ArrayList(java.util.ArrayList) StructuredAttribute(org.apache.flink.table.types.logical.StructuredType.StructuredAttribute) LogicalType(org.apache.flink.table.types.logical.LogicalType) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) ArrayNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier) StructuredType(org.apache.flink.table.types.logical.StructuredType)

Aggregations

JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)3 RexBuilder (org.apache.calcite.rex.RexBuilder)2 ArrayNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode)2 Builder (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvSchema.Builder)2 Column (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.dataformat.csv.CsvSchema.Column)2 LogicalType (org.apache.flink.table.types.logical.LogicalType)2 BoundType (com.google.common.collect.BoundType)1 Builder (com.google.common.collect.ImmutableRangeSet.Builder)1 Range (com.google.common.collect.Range)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 RexWindowBound (org.apache.calcite.rex.RexWindowBound)1 SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 ObjectMapper (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader)1 ObjectWriter (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)1 ChangelogMode (org.apache.flink.table.connector.ChangelogMode)1