You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2015/07/31 02:43:26 UTC

[26/43] hive git commit: HIVE-10799. Refactor the SearchArgumentFactory to remove the AST-specific factory. (omalley reviewed by prasanth_j)

http://git-wip-us.apache.org/repos/asf/hive/blob/c178a6e9/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java
----------------------------------------------------------------------
diff --git a/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java b/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java
index 0a95363..3a92565 100644
--- a/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java
+++ b/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/PredicateLeaf.java
@@ -18,6 +18,10 @@
 
 package org.apache.hadoop.hive.ql.io.sarg;
 
+import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
+
+import java.sql.Date;
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -43,14 +47,27 @@ public interface PredicateLeaf {
    * The possible types for sargs.
    */
   public static enum Type {
-    INTEGER, // all of the integer types except long
-    LONG,
-    FLOAT,   // float and double
-    STRING,  // string, char, varchar
-    DATE,
-    DECIMAL,
-    TIMESTAMP,
-    BOOLEAN
+    INTEGER(Integer.class), // all of the integer types except long
+    LONG(Long.class),
+    FLOAT(Double.class),   // float and double
+    STRING(String.class),  // string, char, varchar
+    DATE(Date.class),
+    DECIMAL(HiveDecimalWritable.class),
+    TIMESTAMP(Timestamp.class),
+    BOOLEAN(Boolean.class);
+
+    private final Class cls;
+    Type(Class cls) {
+      this.cls = cls;
+    }
+
+    /**
+     * For all SARG leaves, the values must be the matching class.
+     * @return the value class
+     */
+    public Class getValueClass() {
+      return cls;
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/c178a6e9/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java
----------------------------------------------------------------------
diff --git a/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java b/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java
index 84604cb..bc0d503 100644
--- a/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java
+++ b/serde/src/java/org/apache/hadoop/hive/ql/io/sarg/SearchArgument.java
@@ -215,58 +215,78 @@ public interface SearchArgument {
     /**
      * Add a less than leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @param literal the literal
      * @return this
      */
-    public Builder lessThan(String column, Object literal);
+    public Builder lessThan(String column, PredicateLeaf.Type type,
+                            Object literal);
 
     /**
      * Add a less than equals leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @param literal the literal
      * @return this
      */
-    public Builder lessThanEquals(String column, Object literal);
+    public Builder lessThanEquals(String column, PredicateLeaf.Type type,
+                                  Object literal);
 
     /**
      * Add an equals leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @param literal the literal
      * @return this
      */
-    public Builder equals(String column, Object literal);
+    public Builder equals(String column, PredicateLeaf.Type type,
+                          Object literal);
 
     /**
      * Add a null safe equals leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @param literal the literal
      * @return this
      */
-    public Builder nullSafeEquals(String column, Object literal);
+    public Builder nullSafeEquals(String column, PredicateLeaf.Type type,
+                                  Object literal);
 
     /**
      * Add an in leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @param literal the literal
      * @return this
      */
-    public Builder in(String column, Object... literal);
+    public Builder in(String column, PredicateLeaf.Type type,
+                      Object... literal);
 
     /**
      * Add an is null leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @return this
      */
-    public Builder isNull(String column);
+    public Builder isNull(String column, PredicateLeaf.Type type);
 
     /**
      * Add a between leaf to the current item on the stack.
      * @param column the name of the column
+     * @param type the type of the expression
      * @param lower the literal
      * @param upper the literal
      * @return this
      */
-    public Builder between(String column, Object lower, Object upper);
+    public Builder between(String column, PredicateLeaf.Type type,
+                           Object lower, Object upper);
+
+    /**
+     * Add a truth value to the expression.
+     * @param truth
+     * @return this
+     */
+    public Builder literal(TruthValue truth);
 
     /**
      * Build and return the SearchArgument that has been defined. All of the

http://git-wip-us.apache.org/repos/asf/hive/blob/c178a6e9/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java
----------------------------------------------------------------------
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java
index a17d2cc..885828a 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java
@@ -46,6 +46,10 @@ public class HiveDecimalWritable implements WritableComparable<HiveDecimalWritab
   public HiveDecimalWritable() {
   }
 
+  public HiveDecimalWritable(String value) {
+    set(HiveDecimal.create(value));
+  }
+
   public HiveDecimalWritable(byte[] bytes, int scale) {
     set(bytes, scale);
   }
@@ -58,6 +62,10 @@ public class HiveDecimalWritable implements WritableComparable<HiveDecimalWritab
     set(value);
   }
 
+  public HiveDecimalWritable(long value) {
+    set((HiveDecimal.create(value)));
+  }
+
   public void set(HiveDecimal value) {
     set(value.unscaledValue().toByteArray(), value.scale());
   }