Search in sources :

Example 1 with WatermarkSpec

use of org.apache.flink.table.catalog.WatermarkSpec in project flink by apache.

the class ResolvedSchemaJsonDeserializer method deserialize.

@Override
public ResolvedSchema deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    ObjectNode jsonNode = jsonParser.readValueAsTree();
    List<Column> columns = ctx.readValue(traverse(jsonNode.required(COLUMNS), jsonParser.getCodec()), ctx.getTypeFactory().constructCollectionType(List.class, Column.class));
    List<WatermarkSpec> watermarkSpecs = ctx.readValue(traverse(jsonNode.required(WATERMARK_SPECS), jsonParser.getCodec()), ctx.getTypeFactory().constructCollectionType(List.class, WatermarkSpec.class));
    UniqueConstraint primaryKey = deserializeOptionalField(jsonNode, PRIMARY_KEY, UniqueConstraint.class, jsonParser.getCodec(), ctx).orElse(null);
    return new ResolvedSchema(columns, watermarkSpecs, primaryKey);
}
Also used : ObjectNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode) WatermarkSpec(org.apache.flink.table.catalog.WatermarkSpec) Column(org.apache.flink.table.catalog.Column) UniqueConstraint(org.apache.flink.table.catalog.UniqueConstraint) List(java.util.List) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema)

Example 2 with WatermarkSpec

use of org.apache.flink.table.catalog.WatermarkSpec in project flink by apache.

the class PushWatermarkIntoTableSourceScanRuleBase method hasSourceWatermarkDeclaration.

private boolean hasSourceWatermarkDeclaration(TableSourceTable table) {
    final ResolvedSchema schema = table.contextResolvedTable().getResolvedSchema();
    final List<WatermarkSpec> specs = schema.getWatermarkSpecs();
    // we only support one watermark spec for now
    if (specs.size() != 1) {
        return false;
    }
    final ResolvedExpression watermarkExpr = specs.get(0).getWatermarkExpression();
    final FunctionDefinition function = unwrapFunctionDefinition(watermarkExpr);
    return function == BuiltInFunctionDefinitions.SOURCE_WATERMARK;
}
Also used : WatermarkSpec(org.apache.flink.table.catalog.WatermarkSpec) SourceWatermarkSpec(org.apache.flink.table.planner.plan.abilities.source.SourceWatermarkSpec) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) ShortcutUtils.unwrapFunctionDefinition(org.apache.flink.table.planner.utils.ShortcutUtils.unwrapFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema)

Example 3 with WatermarkSpec

use of org.apache.flink.table.catalog.WatermarkSpec in project flink by apache.

the class DynamicSourceUtils method pushWatermarkAssigner.

// --------------------------------------------------------------------------------------------
/**
 * Creates a specialized node for assigning watermarks.
 */
private static void pushWatermarkAssigner(FlinkRelBuilder relBuilder, ResolvedSchema schema) {
    final ExpressionConverter converter = new ExpressionConverter(relBuilder);
    final RelDataType inputRelDataType = relBuilder.peek().getRowType();
    // schema resolver has checked before that only one spec exists
    final WatermarkSpec watermarkSpec = schema.getWatermarkSpecs().get(0);
    final String rowtimeColumn = watermarkSpec.getRowtimeAttribute();
    final int rowtimeColumnIdx = inputRelDataType.getFieldNames().indexOf(rowtimeColumn);
    final RexNode watermarkRexNode = watermarkSpec.getWatermarkExpression().accept(converter);
    relBuilder.watermark(rowtimeColumnIdx, watermarkRexNode);
}
Also used : WatermarkSpec(org.apache.flink.table.catalog.WatermarkSpec) ExpressionConverter(org.apache.flink.table.planner.expressions.converter.ExpressionConverter) RelDataType(org.apache.calcite.rel.type.RelDataType) RelHint(org.apache.calcite.rel.hint.RelHint) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

WatermarkSpec (org.apache.flink.table.catalog.WatermarkSpec)3 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)2 List (java.util.List)1 RelHint (org.apache.calcite.rel.hint.RelHint)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexNode (org.apache.calcite.rex.RexNode)1 ObjectNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode)1 Column (org.apache.flink.table.catalog.Column)1 UniqueConstraint (org.apache.flink.table.catalog.UniqueConstraint)1 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)1 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)1 ExpressionConverter (org.apache.flink.table.planner.expressions.converter.ExpressionConverter)1 SourceWatermarkSpec (org.apache.flink.table.planner.plan.abilities.source.SourceWatermarkSpec)1 ShortcutUtils.unwrapFunctionDefinition (org.apache.flink.table.planner.utils.ShortcutUtils.unwrapFunctionDefinition)1