commit 23a1df8bf93fcf0f633727c90bc818a1fd855842 Author: Owen O'Malley Date: Thu May 23 11:27:46 2013 -0700 HIVE-4579 Create a SARG interface for RecordReaders diff --git ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ColumnName.java ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ColumnName.java new file mode 100644 index 0000000..b316220 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/io/sarg/ColumnName.java @@ -0,0 +1,31 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.hadoop.hive.ql.io.sarg; + +/** + * A description of a column + */ +public interface ColumnName { + + /** + * The simple name of the column + * @return the column name + */ + public String getName(); +} diff --git ql/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java ql/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java new file mode 100644 index 0000000..78e065c --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java @@ -0,0 +1,54 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.hadoop.hive.ql.io.sarg; + +import java.util.List; + +/** + * The primitive predicates that form a SearchArgument. + */ +public interface PredicateLeaf { + + public static enum Operator { + EQUALS, LESS_THAN, LESS_THAN_EQUALS, GREATER_THAN, GREATER_THAN_EQUALS, + NOT_EQUALS, IN, BETWEEN, IS_NULL + } + + public static enum Type { + INTEGER, FLOAT, STRING + } + + public Operator getOperator(); + + public Type getType(); + + public ColumnName getColumnName(); + + /** + * Get the literal half of the predicate leaf. + * @return a LongWritable, DoubleWritable, or Text + */ + public Object getLiteral(); + + /** + * For operators with multiple literals (IN and BETWEEN), get the literals. + * @return the list of literals + */ + public List getLiteralList(); +} diff --git ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java new file mode 100644 index 0000000..a470429 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java @@ -0,0 +1,67 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.hadoop.hive.ql.io.sarg; + +import org.apache.hadoop.hive.ql.plan.ExprNodeDesc; + +import java.util.List; + +/** + * Primary interface for + * SearchArgument, which are the subset of predicates + * that can be pushed down to the RecordReader. Each SearchArgument consists + * of a series of SearchClauses that must each be true for the row to be + * accepted by the filter. + * + * This requires that the filter be normalized into conjunctive normal form + * (CNF). + */ +public interface SearchArgument { + + public static enum YES_NO_MAYBE { YES, NO, MAYBE} + + /** + * Get the leaf predicates that are required to evaluate the predicate. The + * list will have the duplicates removed. + * @return the list of leaf predicates + */ + public List getLeaves(); + + /** + * Evaluate the entire predicate based on the values for the leaf predicates. + * @param leaves the value of each leaf predicate + * @return the value of hte entire predicate + */ + public YES_NO_MAYBE evaluate(YES_NO_MAYBE[] leaves); + + /** + * A factory for creating SearchArguments. Java doesn't allow static methods + * in interfaces. *DOH* + */ + public static class Factory { + public SearchArgument create(ExprNodeDesc expression) { + return new SearchArgumentImpl(expression); + } + } + + /** + * Use this instance to create SearchArgument instances. + */ + public static final Factory FACTORY = new Factory(); +} diff --git ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java new file mode 100644 index 0000000..607262d --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgumentImpl.java @@ -0,0 +1,43 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.hadoop.hive.ql.io.sarg; + +import org.apache.hadoop.hive.ql.plan.ExprNodeDesc; + +import java.util.List; + +/** + * The implementation of SearchArguments. + */ +final class SearchArgumentImpl implements SearchArgument { + + SearchArgumentImpl(ExprNodeDesc expression) { + // TODO + } + + @Override + public List getLeaves() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public YES_NO_MAYBE evaluate(YES_NO_MAYBE[] leaves) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } +}