Java Code Examples for org.apache.iceberg.expressions.Expressions#and()
The following examples show how to use
org.apache.iceberg.expressions.Expressions#and() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindFiles.java From iceberg with Apache License 2.0 | 6 votes |
/** * Filter results to files in any one of the given partitions. * * @param spec a spec for the partitions * @param partitions a list of StructLike that stores a partition tuple * @return this for method chaining */ public Builder inPartitions(PartitionSpec spec, List<StructLike> partitions) { Preconditions.checkArgument(spec.equals(ops.current().spec(spec.specId())), "Partition spec does not belong to table: %s", table); Expression partitionSetFilter = Expressions.alwaysFalse(); for (StructLike partitionData : partitions) { Expression partFilter = Expressions.alwaysTrue(); for (int i = 0; i < spec.fields().size(); i += 1) { PartitionField field = spec.fields().get(i); partFilter = Expressions.and( partFilter, Expressions.equal(field.name(), partitionData.get(i, Object.class))); } partitionSetFilter = Expressions.or(partitionSetFilter, partFilter); } if (partitionFilter != Expressions.alwaysTrue()) { this.partitionFilter = Expressions.or(partitionFilter, partitionSetFilter); } else { this.partitionFilter = partitionSetFilter; } return this; }
Example 2
Source File: SparkFilters.java From iceberg with Apache License 2.0 | 5 votes |
public static Expression convert(Filter[] filters) { Expression expression = Expressions.alwaysTrue(); for (Filter filter : filters) { Expression converted = convert(filter); Preconditions.checkArgument(converted != null, "Cannot convert filter to Iceberg: %s", filter); expression = Expressions.and(expression, converted); } return expression; }
Example 3
Source File: ManifestReader.java From iceberg with Apache License 2.0 | 5 votes |
private Evaluator evaluator() { if (lazyEvaluator == null) { Expression projected = Projections.inclusive(spec, caseSensitive).project(rowFilter); Expression finalPartFilter = Expressions.and(projected, partFilter); if (finalPartFilter != null) { this.lazyEvaluator = new Evaluator(spec.partitionType(), finalPartFilter, caseSensitive); } else { this.lazyEvaluator = new Evaluator(spec.partitionType(), Expressions.alwaysTrue(), caseSensitive); } } return lazyEvaluator; }
Example 4
Source File: ScanSummary.java From iceberg with Apache License 2.0 | 5 votes |
static Expression joinFilters(List<Expression> expressions) { Expression result = Expressions.alwaysTrue(); for (Expression expression : expressions) { result = Expressions.and(result, expression); } return result; }
Example 5
Source File: IcebergFilterGenerator.java From metacat with Apache License 2.0 | 5 votes |
@Override public Object visit(final ASTBETWEEN node, final Object data) { final Object value = node.jjtGetChild(0).jjtAccept(this, data); final Object startValue = node.jjtGetChild(1).jjtAccept(this, data); final Object endValue = node.jjtGetChild(2).jjtAccept(this, data); final Expression compare1 = createIcebergExpression(value, startValue, node.not ? Compare.LT : Compare.GTE); final Expression compare2 = createIcebergExpression(value, endValue, node.not ? Compare.GT : Compare.LTE); return (node.not) ? Expressions.or(compare1, compare2) : Expressions.and(compare1, compare2); }
Example 6
Source File: IcebergStorage.java From iceberg with Apache License 2.0 | 4 votes |
private org.apache.iceberg.expressions.Expression convert(Expression expression) throws IOException { OpType op = expression.getOpType(); if (expression instanceof BinaryExpression) { Expression lhs = ((BinaryExpression) expression).getLhs(); Expression rhs = ((BinaryExpression) expression).getRhs(); switch (op) { case OP_AND: return Expressions.and(convert(lhs), convert(rhs)); case OP_OR: return Expressions.or(convert(lhs), convert(rhs)); case OP_BETWEEN: BetweenExpression between = (BetweenExpression) rhs; return Expressions.and( convert(OpType.OP_GE, (Column) lhs, (Const) between.getLower()), convert(OpType.OP_LE, (Column) lhs, (Const) between.getUpper()) ); case OP_IN: return ((InExpression) rhs).getValues().stream() .map(value -> convert(OpType.OP_EQ, (Column) lhs, (Const) value)) .reduce(Expressions.alwaysFalse(), Expressions::or); default: if (lhs instanceof Column && rhs instanceof Const) { return convert(op, (Column) lhs, (Const) rhs); } else if (lhs instanceof Const && rhs instanceof Column) { throw new FrontendException("Invalid expression ordering " + expression); } } } else if (expression instanceof UnaryExpression) { Expression unary = ((UnaryExpression) expression).getExpression(); switch (op) { case OP_NOT: return Expressions.not(convert(unary)); case OP_NULL: return Expressions.isNull(((Column) unary).getName()); default: throw new FrontendException("Unsupported unary operator" + op); } } throw new FrontendException("Failed to pushdown expression " + expression); }
Example 7
Source File: ManifestReader.java From iceberg with Apache License 2.0 | 4 votes |
public ManifestReader<F> filterPartitions(Expression expr) { this.partFilter = Expressions.and(partFilter, expr); return this; }
Example 8
Source File: ManifestReader.java From iceberg with Apache License 2.0 | 4 votes |
public ManifestReader<F> filterRows(Expression expr) { this.rowFilter = Expressions.and(rowFilter, expr); return this; }
Example 9
Source File: ManifestGroup.java From iceberg with Apache License 2.0 | 4 votes |
ManifestGroup filterData(Expression newDataFilter) { this.dataFilter = Expressions.and(dataFilter, newDataFilter); return this; }
Example 10
Source File: ManifestGroup.java From iceberg with Apache License 2.0 | 4 votes |
ManifestGroup filterFiles(Expression newFileFilter) { this.fileFilter = Expressions.and(fileFilter, newFileFilter); return this; }
Example 11
Source File: ManifestGroup.java From iceberg with Apache License 2.0 | 4 votes |
ManifestGroup filterPartitions(Expression newPartitionFilter) { this.partitionFilter = Expressions.and(partitionFilter, newPartitionFilter); return this; }
Example 12
Source File: IcebergFilterGenerator.java From metacat with Apache License 2.0 | 4 votes |
@Override public Object visit(final ASTAND node, final Object data) { return Expressions.and((Expression) node.jjtGetChild(0).jjtAccept(this, data), (Expression) node.jjtGetChild(1).jjtAccept(this, data)); }
Example 13
Source File: RewriteDataFilesAction.java From iceberg with Apache License 2.0 | 2 votes |
/** * Pass a row Expression to filter DataFiles to be rewritten. Note that all files that may contain data matching the * filter may be rewritten. * * @param expr Expression to filter out DataFiles * @return this for method chaining */ public RewriteDataFilesAction filter(Expression expr) { this.filter = Expressions.and(filter, expr); return this; }
Example 14
Source File: FindFiles.java From iceberg with Apache License 2.0 | 2 votes |
/** * Filter results using a record filter. Files that may contain at least one matching record * will be returned by {@link #collect()}. * * @param expr a record filter * @return this for method chaining */ public Builder withRecordsMatching(Expression expr) { this.rowFilter = Expressions.and(rowFilter, expr); return this; }
Example 15
Source File: FindFiles.java From iceberg with Apache License 2.0 | 2 votes |
/** * Filter results using a metadata filter for the data in a {@link DataFile}. * * @param expr a filter for {@link DataFile} metadata columns * @return this for method chaining */ public Builder withMetadataMatching(Expression expr) { this.fileFilter = Expressions.and(fileFilter, expr); return this; }