use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class HiveTableUtil method makePartitionFilter.
/**
* Generates a filter string for partition columns from the given filter expressions.
*
* @param partColOffset The number of non-partition columns -- used to shift field reference
* index
* @param partColNames The names of all partition columns
* @param expressions The filter expressions in CNF form
* @return an Optional filter string equivalent to the expressions, which is empty if the
* expressions can't be handled
*/
public static Optional<String> makePartitionFilter(int partColOffset, List<String> partColNames, List<Expression> expressions, HiveShim hiveShim) {
List<String> filters = new ArrayList<>(expressions.size());
ExpressionExtractor extractor = new ExpressionExtractor(partColOffset, partColNames, hiveShim);
for (Expression expression : expressions) {
String str = expression.accept(extractor);
if (str == null) {
return Optional.empty();
}
filters.add(str);
}
return Optional.of(String.join(" and ", filters));
}
use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class OrcFilters method convertOr.
private static Predicate convertOr(CallExpression callExp) {
if (callExp.getChildren().size() < 2) {
return null;
}
Expression left = callExp.getChildren().get(0);
Expression right = callExp.getChildren().get(1);
Predicate c1 = toOrcPredicate(left);
Predicate c2 = toOrcPredicate(right);
if (c1 == null || c2 == null) {
return null;
} else {
return new Or(c1, c2);
}
}
use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class TableImpl method createTemporalTableFunction.
@Override
public TemporalTableFunction createTemporalTableFunction(Expression timeAttribute, Expression primaryKey) {
Expression resolvedTimeAttribute = operationTreeBuilder.resolveExpression(timeAttribute, operationTree);
Expression resolvedPrimaryKey = operationTreeBuilder.resolveExpression(primaryKey, operationTree);
return TemporalTableFunctionImpl.create(operationTree, resolvedTimeAttribute, resolvedPrimaryKey);
}
use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class TableImpl method select.
@Override
public Table select(Expression... fields) {
List<Expression> expressionsWithResolvedCalls = preprocessExpressions(fields);
CategorizedExpressions extracted = OperationExpressionsUtils.extractAggregationsAndProperties(expressionsWithResolvedCalls);
if (!extracted.getWindowProperties().isEmpty()) {
throw new ValidationException("Window properties can only be used on windowed tables.");
}
if (!extracted.getAggregations().isEmpty()) {
QueryOperation aggregate = operationTreeBuilder.aggregate(Collections.emptyList(), extracted.getAggregations(), operationTree);
return createTable(operationTreeBuilder.project(extracted.getProjections(), aggregate, false));
} else {
return createTable(operationTreeBuilder.project(expressionsWithResolvedCalls, operationTree, false));
}
}
use of org.apache.flink.table.expressions.Expression 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);
}
}
Aggregations