use of org.apache.flink.table.expressions.ResolvedExpression 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));
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class PushPartitionIntoTableSourceScanRule method readPartitionFromCatalogAndPrune.
private List<Map<String, String>> readPartitionFromCatalogAndPrune(RexBuilder rexBuilder, FlinkContext context, Catalog catalog, ObjectIdentifier tableIdentifier, List<String> allFieldNames, Seq<RexNode> partitionPredicate, Function<List<Map<String, String>>, List<Map<String, String>>> pruner) throws TableNotExistException, TableNotPartitionedException {
ObjectPath tablePath = tableIdentifier.toObjectPath();
// build filters
RexNodeToExpressionConverter converter = new RexNodeToExpressionConverter(rexBuilder, allFieldNames.toArray(new String[0]), context.getFunctionCatalog(), context.getCatalogManager(), TimeZone.getTimeZone(context.getTableConfig().getLocalTimeZone()));
ArrayList<Expression> partitionFilters = new ArrayList<>();
Option<ResolvedExpression> subExpr;
for (RexNode node : JavaConversions.seqAsJavaList(partitionPredicate)) {
subExpr = node.accept(converter);
if (!subExpr.isEmpty()) {
partitionFilters.add(subExpr.get());
} else {
// if part of expr is unresolved, we read all partitions and prune.
return readPartitionFromCatalogWithoutFilterAndPrune(catalog, tablePath, pruner);
}
}
try {
return catalog.listPartitionsByFilter(tablePath, partitionFilters).stream().map(CatalogPartitionSpec::getPartitionSpec).collect(Collectors.toList());
} catch (UnsupportedOperationException e) {
return readPartitionFromCatalogWithoutFilterAndPrune(catalog, tablePath, pruner);
}
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class ProjectionOperationFactory method validateAndGetUniqueNames.
private String[] validateAndGetUniqueNames(List<ResolvedExpression> namedExpressions) {
// we need to maintain field names order to match with types
final Set<String> names = new LinkedHashSet<>();
extractNames(namedExpressions).stream().map(name -> name.orElseThrow(() -> new TableException("Could not name a field in a projection."))).forEach(name -> {
if (!names.add(name)) {
throw new ValidationException("Ambiguous column name: " + name);
}
});
return names.toArray(new String[0]);
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class ValuesOperationFactory method convertArrayToExpectedType.
private Optional<ResolvedExpression> convertArrayToExpectedType(ResolvedExpression sourceExpression, CollectionDataType targetDataType, ExpressionResolver.PostResolverFactory postResolverFactory) {
DataType elementTargetDataType = targetDataType.getElementDataType();
List<ResolvedExpression> resolvedChildren = sourceExpression.getResolvedChildren();
ResolvedExpression[] castedChildren = new ResolvedExpression[resolvedChildren.size()];
for (int i = 0; i < resolvedChildren.size(); i++) {
Optional<ResolvedExpression> castedChild = convertToExpectedType(resolvedChildren.get(i), elementTargetDataType, postResolverFactory);
if (castedChild.isPresent()) {
castedChildren[i] = castedChild.get();
} else {
return Optional.empty();
}
}
return Optional.of(postResolverFactory.array(targetDataType, castedChildren));
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class ValuesOperationFactory method extractLogicalTypesAtPosition.
private List<LogicalType> extractLogicalTypesAtPosition(List<List<ResolvedExpression>> resolvedRows, int rowPosition) {
List<LogicalType> typesAtIPosition = new ArrayList<>();
for (List<ResolvedExpression> resolvedExpression : resolvedRows) {
LogicalType outputLogicalType = resolvedExpression.get(rowPosition).getOutputDataType().getLogicalType();
typesAtIPosition.add(outputLogicalType);
}
return typesAtIPosition;
}
Aggregations