use of org.apache.flink.table.expressions.ResolvedExpression 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;
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class FilterUtils method isRetainedAfterApplyingFilterPredicates.
public static boolean isRetainedAfterApplyingFilterPredicates(List<ResolvedExpression> predicates, Function<String, Comparable<?>> getter) {
for (ResolvedExpression predicate : predicates) {
if (predicate instanceof CallExpression) {
FunctionDefinition definition = ((CallExpression) predicate).getFunctionDefinition();
boolean result = false;
if (definition.equals(BuiltInFunctionDefinitions.OR)) {
// nested filter, such as (key1 > 2 or key2 > 3)
for (Expression expr : predicate.getChildren()) {
if (!(expr instanceof CallExpression && expr.getChildren().size() == 2)) {
throw new TableException(expr + " not supported!");
}
result = binaryFilterApplies((CallExpression) expr, getter);
if (result) {
break;
}
}
} else if (predicate.getChildren().size() == 2) {
result = binaryFilterApplies((CallExpression) predicate, getter);
} else {
throw new UnsupportedOperationException(String.format("Unsupported expr: %s.", predicate));
}
if (!result) {
return false;
}
} else {
throw new UnsupportedOperationException(String.format("Unsupported expr: %s.", predicate));
}
}
return true;
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class FilterPushDownSpec method apply.
public static SupportsFilterPushDown.Result apply(List<RexNode> predicates, DynamicTableSource tableSource, SourceAbilityContext context) {
if (tableSource instanceof SupportsFilterPushDown) {
RexNodeToExpressionConverter converter = new RexNodeToExpressionConverter(new RexBuilder(FlinkTypeFactory.INSTANCE()), context.getSourceRowType().getFieldNames().toArray(new String[0]), context.getFunctionCatalog(), context.getCatalogManager(), TimeZone.getTimeZone(context.getTableConfig().getLocalTimeZone()));
List<Expression> filters = predicates.stream().map(p -> {
scala.Option<ResolvedExpression> expr = p.accept(converter);
if (expr.isDefined()) {
return expr.get();
} else {
throw new TableException(String.format("%s can not be converted to Expression, please make sure %s can accept %s.", p.toString(), tableSource.getClass().getSimpleName(), p.toString()));
}
}).collect(Collectors.toList());
ExpressionResolver resolver = ExpressionResolver.resolverFor(context.getTableConfig(), name -> Optional.empty(), context.getFunctionCatalog().asLookup(str -> {
throw new TableException("We should not need to lookup any expressions at this point");
}), context.getCatalogManager().getDataTypeFactory(), (sqlExpression, inputRowType, outputType) -> {
throw new TableException("SQL expression parsing is not supported at this location.");
}).build();
return ((SupportsFilterPushDown) tableSource).applyFilters(resolver.resolve(filters));
} else {
throw new TableException(String.format("%s does not support SupportsFilterPushDown.", tableSource.getClass().getName()));
}
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class TestValuesCatalog method listPartitionsByFilter.
@Override
public List<CatalogPartitionSpec> listPartitionsByFilter(ObjectPath tablePath, List<Expression> filters) throws TableNotExistException, TableNotPartitionedException, CatalogException {
if (!supportListPartitionByFilter) {
throw new UnsupportedOperationException("TestValuesCatalog doesn't support list partition by filters");
}
List<CatalogPartitionSpec> partitions = listPartitions(tablePath);
if (partitions.isEmpty()) {
return partitions;
}
CatalogBaseTable table = this.getTable(tablePath);
TableSchema schema = table.getSchema();
List<ResolvedExpression> resolvedExpressions = filters.stream().map(filter -> {
if (filter instanceof ResolvedExpression) {
return (ResolvedExpression) filter;
}
throw new UnsupportedOperationException(String.format("TestValuesCatalog only works with resolved expressions. Get unresolved expression: %s", filter));
}).collect(Collectors.toList());
return partitions.stream().filter(partition -> {
Function<String, Comparable<?>> getter = getValueGetter(partition.getPartitionSpec(), schema);
return FilterUtils.isRetainedAfterApplyingFilterPredicates(resolvedExpressions, getter);
}).collect(Collectors.toList());
}
Aggregations