Search in sources :

Example 1 with UnresolvedWatermarkSpec

use of org.apache.flink.table.api.Schema.UnresolvedWatermarkSpec in project flink by apache.

the class DefaultSchemaResolver method resolveWatermarkSpecs.

private List<WatermarkSpec> resolveWatermarkSpecs(List<UnresolvedWatermarkSpec> unresolvedWatermarkSpecs, List<Column> inputColumns) {
    if (unresolvedWatermarkSpecs.size() == 0) {
        return Collections.emptyList();
    }
    if (unresolvedWatermarkSpecs.size() > 1) {
        throw new ValidationException("Multiple watermark definitions are not supported yet.");
    }
    final UnresolvedWatermarkSpec watermarkSpec = unresolvedWatermarkSpecs.get(0);
    // validate time attribute
    final String timeColumn = watermarkSpec.getColumnName();
    final Column validatedTimeColumn = validateTimeColumn(timeColumn, inputColumns);
    // resolve watermark expression
    final ResolvedExpression watermarkExpression;
    try {
        watermarkExpression = resolveExpression(inputColumns, watermarkSpec.getWatermarkExpression(), validatedTimeColumn.getDataType());
    } catch (Exception e) {
        throw new ValidationException(String.format("Invalid expression for watermark '%s'.", watermarkSpec.toString()), e);
    }
    final LogicalType outputType = watermarkExpression.getOutputDataType().getLogicalType();
    final LogicalType timeColumnType = validatedTimeColumn.getDataType().getLogicalType();
    validateWatermarkExpression(outputType);
    if (outputType.getTypeRoot() != timeColumnType.getTypeRoot()) {
        throw new ValidationException(String.format("The watermark declaration's output data type '%s' is different " + "from the time field's data type '%s'.", outputType, timeColumnType));
    }
    return Collections.singletonList(WatermarkSpec.of(watermarkSpec.getColumnName(), watermarkExpression));
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) PhysicalColumn(org.apache.flink.table.catalog.Column.PhysicalColumn) UnresolvedComputedColumn(org.apache.flink.table.api.Schema.UnresolvedComputedColumn) MetadataColumn(org.apache.flink.table.catalog.Column.MetadataColumn) ComputedColumn(org.apache.flink.table.catalog.Column.ComputedColumn) UnresolvedMetadataColumn(org.apache.flink.table.api.Schema.UnresolvedMetadataColumn) UnresolvedPhysicalColumn(org.apache.flink.table.api.Schema.UnresolvedPhysicalColumn) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) DataTypeUtils.replaceLogicalType(org.apache.flink.table.types.utils.DataTypeUtils.replaceLogicalType) LogicalType(org.apache.flink.table.types.logical.LogicalType) UnresolvedWatermarkSpec(org.apache.flink.table.api.Schema.UnresolvedWatermarkSpec) ValidationException(org.apache.flink.table.api.ValidationException)

Aggregations

UnresolvedComputedColumn (org.apache.flink.table.api.Schema.UnresolvedComputedColumn)1 UnresolvedMetadataColumn (org.apache.flink.table.api.Schema.UnresolvedMetadataColumn)1 UnresolvedPhysicalColumn (org.apache.flink.table.api.Schema.UnresolvedPhysicalColumn)1 UnresolvedWatermarkSpec (org.apache.flink.table.api.Schema.UnresolvedWatermarkSpec)1 ValidationException (org.apache.flink.table.api.ValidationException)1 ComputedColumn (org.apache.flink.table.catalog.Column.ComputedColumn)1 MetadataColumn (org.apache.flink.table.catalog.Column.MetadataColumn)1 PhysicalColumn (org.apache.flink.table.catalog.Column.PhysicalColumn)1 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1 DataTypeUtils.replaceLogicalType (org.apache.flink.table.types.utils.DataTypeUtils.replaceLogicalType)1