Search in sources :

Example 1 with CatalogPlanCompilation

use of org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation in project flink by apache.

the class ContextResolvedTableJsonSerializer method serialize.

@Override
public void serialize(ContextResolvedTable contextResolvedTable, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    final CatalogPlanCompilation planCompilationOption = SerdeContext.get(serializerProvider).getConfiguration().get(TableConfigOptions.PLAN_COMPILE_CATALOG_OBJECTS);
    if (contextResolvedTable.isAnonymous() && planCompilationOption == CatalogPlanCompilation.IDENTIFIER) {
        throw cannotSerializeAnonymousTable(contextResolvedTable.getIdentifier());
    }
    jsonGenerator.writeStartObject();
    if (!contextResolvedTable.isAnonymous()) {
        // Serialize object identifier
        jsonGenerator.writeObjectField(FIELD_NAME_IDENTIFIER, contextResolvedTable.getIdentifier());
    }
    if ((contextResolvedTable.isPermanent() || contextResolvedTable.isAnonymous()) && planCompilationOption != CatalogPlanCompilation.IDENTIFIER) {
        jsonGenerator.writeFieldName(FIELD_NAME_CATALOG_TABLE);
        try {
            ResolvedCatalogTableJsonSerializer.serialize(contextResolvedTable.getResolvedTable(), planCompilationOption == CatalogPlanCompilation.ALL, jsonGenerator, serializerProvider);
        } catch (ValidationException e) {
            throw new ValidationException(String.format("Error when trying to serialize table '%s'.", contextResolvedTable.getIdentifier()), e);
        }
    }
    jsonGenerator.writeEndObject();
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) CatalogPlanCompilation(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation)

Example 2 with CatalogPlanCompilation

use of org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation in project flink by apache.

the class RexNodeJsonSerializer method serialize.

@Override
public void serialize(RexNode rexNode, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    final ReadableConfig config = SerdeContext.get(serializerProvider).getConfiguration();
    final CatalogPlanCompilation compilationStrategy = config.get(TableConfigOptions.PLAN_COMPILE_CATALOG_OBJECTS);
    switch(rexNode.getKind()) {
        case INPUT_REF:
        case TABLE_INPUT_REF:
            serializeInputRef((RexInputRef) rexNode, jsonGenerator, serializerProvider);
            break;
        case LITERAL:
            serializeLiteral((RexLiteral) rexNode, jsonGenerator, serializerProvider);
            break;
        case FIELD_ACCESS:
            serializeFieldAccess((RexFieldAccess) rexNode, jsonGenerator, serializerProvider);
            break;
        case CORREL_VARIABLE:
            serializeCorrelVariable((RexCorrelVariable) rexNode, jsonGenerator, serializerProvider);
            break;
        case PATTERN_INPUT_REF:
            serializePatternFieldRef((RexPatternFieldRef) rexNode, jsonGenerator, serializerProvider);
            break;
        default:
            if (rexNode instanceof RexCall) {
                serializeCall((RexCall) rexNode, jsonGenerator, serializerProvider, compilationStrategy);
            } else {
                throw new TableException("Unknown RexNode: " + rexNode);
            }
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) ReadableConfig(org.apache.flink.configuration.ReadableConfig) TableException(org.apache.flink.table.api.TableException) CatalogPlanCompilation(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation)

Example 3 with CatalogPlanCompilation

use of org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation in project flink by apache.

the class AggregateCallJsonSerializer method serialize.

@Override
public void serialize(AggregateCall aggCall, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    final ReadableConfig config = SerdeContext.get(serializerProvider).getConfiguration();
    final CatalogPlanCompilation compilationStrategy = config.get(TableConfigOptions.PLAN_COMPILE_CATALOG_OBJECTS);
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(FIELD_NAME_NAME, aggCall.getName());
    RexNodeJsonSerializer.serializeSqlOperator(aggCall.getAggregation(), jsonGenerator, serializerProvider, compilationStrategy == CatalogPlanCompilation.ALL);
    jsonGenerator.writeFieldName(FIELD_NAME_ARG_LIST);
    jsonGenerator.writeStartArray();
    for (int arg : aggCall.getArgList()) {
        jsonGenerator.writeNumber(arg);
    }
    jsonGenerator.writeEndArray();
    jsonGenerator.writeNumberField(FIELD_NAME_FILTER_ARG, aggCall.filterArg);
    jsonGenerator.writeBooleanField(FIELD_NAME_DISTINCT, aggCall.isDistinct());
    jsonGenerator.writeBooleanField(FIELD_NAME_APPROXIMATE, aggCall.isApproximate());
    jsonGenerator.writeBooleanField(FIELD_NAME_IGNORE_NULLS, aggCall.ignoreNulls());
    serializerProvider.defaultSerializeField(FIELD_NAME_TYPE, aggCall.getType(), jsonGenerator);
    jsonGenerator.writeEndObject();
}
Also used : ReadableConfig(org.apache.flink.configuration.ReadableConfig) CatalogPlanCompilation(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation)

Aggregations

CatalogPlanCompilation (org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanCompilation)3 ReadableConfig (org.apache.flink.configuration.ReadableConfig)2 RexCall (org.apache.calcite.rex.RexCall)1 TableException (org.apache.flink.table.api.TableException)1 ValidationException (org.apache.flink.table.api.ValidationException)1