deniskuzZ commented on code in PR #7000:
URL: https://github.com/apache/hive/pull/7000#discussion_r4807542565
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -437,37 +438,59 @@ public boolean supportsExternalViewCatalog() {
* @param deserializer Deserializer
* @param exprNodeDesc Filter expression extracted by Hive
* @return The residual predicate is always the entire filter. The pushed
predicate, which Iceberg prunes with, is
- * the entire filter, its conjuncts that don't read a virtual column, or
nothing.
+ * the filter with every operand of AND and OR that reads a virtual
column replaced with TRUE, or nothing if that
+ * leaves TRUE.
*/
@Override
public DecomposedPredicate decomposePredicate(JobConf jobConf, Deserializer
deserializer, ExprNodeDesc exprNodeDesc) {
DecomposedPredicate predicate = new DecomposedPredicate();
predicate.residualPredicate = (ExprNodeGenericFuncDesc) exprNodeDesc;
- ExprNodeDesc pushedPredicate = null;
-
- if (FunctionRegistry.isOpAnd(exprNodeDesc)) {
- // Leaving out a conjunct only widens the pushed predicate; Hive still
applies it through the residual predicate
- pushedPredicate = exprNodeDesc.clone();
- List<ExprNodeDesc> subExprNodes = pushedPredicate.getChildren();
- if (subExprNodes.removeIf(VirtualColumn::containsVirtualColumn)) {
- if (subExprNodes.size() == 1) {
- pushedPredicate = (subExprNodes.getFirst() instanceof
ExprNodeGenericFuncDesc) ?
- subExprNodes.getFirst() : null;
- } else if (subExprNodes.isEmpty()) {
- pushedPredicate = null;
- }
- }
- } else if (!VirtualColumn.containsVirtualColumn(exprNodeDesc)) {
- // Leaving out a disjunct narrows the predicate and loses rows, and
leaving out an operand makes it malformed,
- // so push all of it or nothing
- pushedPredicate = exprNodeDesc.clone();
+ if (widenVirtualColumnPredicates(exprNodeDesc.clone()) instanceof
ExprNodeGenericFuncDesc pushedPredicate) {
Review Comment:
Two small cleanups here:
1. `widenVirtualColumnPredicates` reads as if it widens the predicates on
virtual columns, but it replaces them with TRUE: the widening is what happens
to the filter as a whole. How about `replaceVirtualColumnPredicatesWithTrue`?
2. The `clone()` is needed because the method changes its argument in place
(`setChildren`), while the residual predicate is the same object as
`exprNodeDesc` and must stay the entire filter. Inside the call that's easy to
miss. With the new name the `if` line would also be 122 characters, over the
limit of 120, so a local variable and a comment would read better:
```java
@Override
public DecomposedPredicate decomposePredicate(JobConf jobConf,
Deserializer deserializer, ExprNodeDesc exprNodeDesc) {
DecomposedPredicate predicate = new DecomposedPredicate();
predicate.residualPredicate = (ExprNodeGenericFuncDesc) exprNodeDesc;
// The replacement changes the filter in place, and the residual
predicate must stay the entire filter
ExprNodeDesc pushedPredicate =
replaceVirtualColumnPredicatesWithTrue(exprNodeDesc.clone());
predicate.pushedPredicate = pushedPredicate instanceof
ExprNodeGenericFuncDesc funcDesc ? funcDesc : null;
return predicate;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]