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));
}
Aggregations