Search in sources :

Example 41 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class RexWindowBoundJsonDeserializer method deserialize.

@Override
public RexWindowBound deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode jsonNode = jsonParser.readValueAsTree();
    String kind = jsonNode.get(FIELD_NAME_KIND).asText().toUpperCase();
    switch(kind) {
        case KIND_CURRENT_ROW:
            return RexWindowBounds.CURRENT_ROW;
        case KIND_UNBOUNDED_FOLLOWING:
            return RexWindowBounds.UNBOUNDED_FOLLOWING;
        case KIND_UNBOUNDED_PRECEDING:
            return RexWindowBounds.UNBOUNDED_PRECEDING;
        case KIND_BOUNDED_WINDOW:
            RexNode offset = null;
            if (jsonNode.get(FIELD_NAME_OFFSET) != null) {
                offset = deserializationContext.readValue(jsonNode.get(FIELD_NAME_OFFSET).traverse(jsonParser.getCodec()), RexNode.class);
            }
            if (offset != null && jsonNode.get(FIELD_NAME_IS_FOLLOWING) != null) {
                return RexWindowBounds.following(offset);
            } else if (offset != null && jsonNode.get(FIELD_NAME_IS_PRECEDING) != null) {
                return RexWindowBounds.preceding(offset);
            } else {
                throw new TableException("Unknown RexWindowBound: " + jsonNode.toString());
            }
        default:
            throw new TableException("Unknown RexWindowBound: " + jsonNode.toString());
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) RexNode(org.apache.calcite.rex.RexNode)

Example 42 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class AggregateCallJsonDeserializer method deserialize.

@Override
public AggregateCall deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    final JsonNode jsonNode = jsonParser.readValueAsTree();
    final SerdeContext serdeContext = SerdeContext.get(ctx);
    final String name = jsonNode.required(FIELD_NAME_NAME).asText();
    final SqlAggFunction aggFunction = (SqlAggFunction) RexNodeJsonDeserializer.deserializeSqlOperator(jsonNode, serdeContext);
    final List<Integer> argList = new ArrayList<>();
    final JsonNode argListNode = jsonNode.required(FIELD_NAME_ARG_LIST);
    for (JsonNode argNode : argListNode) {
        argList.add(argNode.intValue());
    }
    final int filterArg = jsonNode.required(FIELD_NAME_FILTER_ARG).asInt();
    final boolean distinct = jsonNode.required(FIELD_NAME_DISTINCT).asBoolean();
    final boolean approximate = jsonNode.required(FIELD_NAME_APPROXIMATE).asBoolean();
    final boolean ignoreNulls = jsonNode.required(FIELD_NAME_IGNORE_NULLS).asBoolean();
    final RelDataType relDataType = RelDataTypeJsonDeserializer.deserialize(jsonNode.required(FIELD_NAME_TYPE), serdeContext);
    return AggregateCall.create(aggFunction, distinct, approximate, ignoreNulls, argList, filterArg, RelCollations.EMPTY, relDataType, name);
}
Also used : ArrayList(java.util.ArrayList) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlAggFunction(org.apache.calcite.sql.SqlAggFunction)

Example 43 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class DataTypeJsonDeserializer method deserialize.

@Override
public DataType deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    final JsonNode dataTypeNode = jsonParser.readValueAsTree();
    final SerdeContext serdeContext = SerdeContext.get(ctx);
    return deserialize(dataTypeNode, serdeContext);
}
Also used : JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)

Example 44 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class LogicalTypeJsonDeserializer method deserialize.

@Override
public LogicalType deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    final JsonNode logicalTypeNode = jsonParser.readValueAsTree();
    final SerdeContext serdeContext = SerdeContext.get(ctx);
    return deserialize(logicalTypeNode, serdeContext);
}
Also used : JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)

Example 45 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class WindowReferenceJsonDeserializer method deserialize.

@Override
public WindowReference deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    final JsonNode input = jsonParser.readValueAsTree();
    String name = input.get(FIELD_NAME_NAME).asText();
    LogicalType type = deserializationContext.readValue(input.get(FIELD_NAME_TYPE).traverse(jsonParser.getCodec()), LogicalType.class);
    return new WindowReference(name, type);
}
Also used : LogicalType(org.apache.flink.table.types.logical.LogicalType) JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) WindowReference(org.apache.flink.table.runtime.groupwindow.WindowReference)

Aggregations

DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)28 JsonParser (com.fasterxml.jackson.core.JsonParser)21 IOException (java.io.IOException)17 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)7 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)7 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)6 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)6 Map (java.util.Map)6 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)5 List (java.util.List)5 ObjectNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Iterator (java.util.Iterator)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3