Github user jinfengni commented on a diff in the pull request:
https://github.com/apache/drill/pull/637#discussion_r86489899
--- Diff:
exec/java-exec/src/main/java/org/apache/drill/exec/expr/stat/ParquetPredicates.java
---
@@ -0,0 +1,334 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.stat;
+
+import org.apache.drill.common.expression.BooleanOperator;
+import org.apache.drill.common.expression.ExpressionPosition;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.LogicalExpressionBase;
+import org.apache.drill.common.expression.visitors.ExprVisitor;
+import org.apache.parquet.column.statistics.Statistics;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public abstract class ParquetPredicates {
+ public static abstract class ParquetCompPredicate extends
LogicalExpressionBase implements ParquetFilterPredicate {
+ protected final LogicalExpression left;
+ protected final LogicalExpression right;
+
+ public ParquetCompPredicate(LogicalExpression left, LogicalExpression
right) {
+ super(left.getPosition());
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public Iterator<LogicalExpression> iterator() {
+ final List<LogicalExpression> args = new ArrayList<>();
+ args.add(left);
+ args.add(right);
+ return args.iterator();
+ }
+
+ @Override
+ public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E>
visitor, V value) throws E {
+ return visitor.visitUnknown(this, value);
+ }
+
+ }
+
+ public static abstract class ParquetBooleanPredicate extends
BooleanOperator implements ParquetFilterPredicate {
+ public ParquetBooleanPredicate(String name, List<LogicalExpression>
args, ExpressionPosition pos) {
+ super(name, args, pos);
+ }
+
+ @Override
+ public <T, V, E extends Exception> T accept(ExprVisitor<T, V, E>
visitor, V value) throws E {
+ return visitor.visitBooleanOperator(this, value);
+ }
+ }
+
+ public static class AndPredicate extends ParquetBooleanPredicate {
+ public AndPredicate(String name, List<LogicalExpression> args,
ExpressionPosition pos) {
+ super(name, args, pos);
+ }
+
+ @Override
+ public boolean canDrop(RangeExprEvaluator evaluator) {
+ // "and" : as long as one branch is OK to drop, we can drop it.
+ for (LogicalExpression child : this) {
+ if (((ParquetFilterPredicate) child).canDrop(evaluator)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ public static class OrPredicate extends ParquetBooleanPredicate {
+ public OrPredicate(String name, List<LogicalExpression> args,
ExpressionPosition pos) {
+ super(name, args, pos);
+ }
+
+ @Override
+ public boolean canDrop(RangeExprEvaluator evaluator) {
+ for (LogicalExpression child : this) {
+ // "long" : as long as one branch is NOT ok to drop, we can NOT
drop it.
+ if (! ((ParquetFilterPredicate) child).canDrop(evaluator)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+
+ // is this column chunk composed entirely of nulls?
+ // assumes the column chunk's statistics is not empty
+ protected static boolean isAllNulls(Statistics stat, long rowCount) {
+ return stat.getNumNulls() == rowCount;
+ }
+
+ // are there any nulls in this column chunk?
+ // assumes the column chunk's statistics is not empty
+ protected static boolean hasNulls(Statistics stat) {
+ return stat.getNumNulls() > 0;
+ }
+
+ /**
+ * EQ (=) predicate
+ */
+ public static class EqualPredicate extends ParquetCompPredicate {
+ public EqualPredicate(LogicalExpression left, LogicalExpression right)
{
+ super(left, right);
+ }
+
+ @Override
+ public boolean canDrop(RangeExprEvaluator evaluator) {
--- End diff --
Add comments to explain the main differences:
1. expressions in filter predicate, including CAST expression.
2. requirements of ColumnChunkMetaData
3. column compare constant_value vs expression_of_column compare
expression_of_column.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---