deniskuzZ commented on code in PR #4959:
URL: https://github.com/apache/hive/pull/4959#discussion_r1462870262


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/parser/ExpressionTree.java:
##########
@@ -263,26 +235,124 @@ public String toString() {
   public static class LeafNode extends TreeNode {
     public String keyName;
     public Operator operator;
-    /** Constant expression side of the operator. Can currently be a String or 
a Long. */
+    /**
+     * Constant expression side of the operator. Can currently be a String or 
a Long.
+     */
     public Object value;
     public boolean isReverseOrder = false;
-    private static final String PARAM_PREFIX = "hive_filter_param_";
 
     @Override
     protected void accept(TreeVisitor visitor) throws MetaException {
       visitor.visit(this);
     }
 
     @Override
-    public void generateJDOFilter(Configuration conf, Map<String, Object> 
params,
-                                  FilterBuilder filterBuilder, 
List<FieldSchema> partitionKeys) throws MetaException {
+    public String toString() {
+      return "LeafNode{" +
+          "keyName='" + keyName + '\'' +
+          ", operator='" + operator + '\'' +
+          ", value=" + value +
+          (isReverseOrder ? ", isReverseOrder=true" : "") +
+          '}';
+    }
+
+    /**
+     * Get partition column index in the table partition column list that
+     * corresponds to the key that is being filtered on by this tree node.
+     * @param partitionKeys list of partition keys.
+     * @param filterBuilder filter builder used to report error, if any.
+     * @return The index.
+     */
+    public static int getPartColIndexForFilter(String partitionKeyName,
+        List<FieldSchema> partitionKeys, FilterBuilder filterBuilder) throws 
MetaException {
+      assert (partitionKeys.size() > 0);
+      int partitionColumnIndex;
+      for (partitionColumnIndex = 0; partitionColumnIndex < 
partitionKeys.size();
+           ++partitionColumnIndex) {
+        if 
(partitionKeys.get(partitionColumnIndex).getName().equalsIgnoreCase(partitionKeyName))
 {
+          break;
+        }
+      }
+      if( partitionColumnIndex == partitionKeys.size()) {
+        filterBuilder.setError("Specified key <" + partitionKeyName +
+            "> is not a partitioning key for the table");
+        return -1;
+      }
+
+      return partitionColumnIndex;
+    }
+  }
+
+  /**
+   * Generate the JDOQL filter for the given expression tree
+   */
+  public static class JDOFilterGenerator extends TreeVisitor {
+
+    private static final String PARAM_PREFIX = "hive_filter_param_";
+
+    private Configuration conf;
+    private List<FieldSchema> partitionKeys;
+    // the filter builder to append to.
+    private FilterBuilder filterBuilder;
+    // the input map which is updated with the the parameterized values.
+    // Keys are the parameter names and values are the parameter values
+    private Map<String, Object> params;
+    private boolean onParsing = false;
+    private String keyName;
+    private Object value;
+    private Operator operator;
+    private boolean isReverseOrder;
+
+    public JDOFilterGenerator(Configuration conf, List<FieldSchema> 
partitionKeys,
+        FilterBuilder filterBuilder, Map<String, Object> params) {
+      this.conf = conf;
+      this.partitionKeys = partitionKeys;
+      this.filterBuilder = filterBuilder;
+      this.params = params;
+    }
+
+    private void beforeParsing() throws MetaException {
+      if (!onParsing && !filterBuilder.getFilter().isEmpty()) {
+        filterBuilder.append(" && ");
+      }
+      onParsing = true;
+    }
+
+    @Override
+    protected void beginTreeNode(TreeNode node) throws MetaException {
+      beforeParsing();
+      filterBuilder.append("( ");
+    }
+
+    @Override
+    protected void midTreeNode(TreeNode node) throws MetaException {
+      filterBuilder.append((node.getAndOr() == LogicalOperator.AND) ? " && " : 
" || ");
+    }
+
+    @Override
+    protected void endTreeNode(TreeNode node) throws MetaException {
+      filterBuilder.append(") ");
+    }
+
+    @Override
+    protected void visit(LeafNode node) throws MetaException {
+      beforeParsing();
+      keyName = node.keyName;

Review Comment:
   are you using `keyName`, `operator`, `value`, `isReverseOrder` somewhere?



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to