hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1188858 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/parse/Hive.g java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java test/queries/clientpositive/literal_ints.q test/results/clientpositive/literal_ints.q.out
Date Tue, 25 Oct 2011 19:07:31 GMT
Author: jvs
Date: Tue Oct 25 19:07:31 2011
New Revision: 1188858

URL: http://svn.apache.org/viewvc?rev=1188858&view=rev
Log:
HIVE-2509. Literal bigint
(Jonathan Chang via jvs)


Added:
    hive/trunk/ql/src/test/queries/clientpositive/literal_ints.q
    hive/trunk/ql/src/test/results/clientpositive/literal_ints.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g?rev=1188858&r1=1188857&r2=1188858&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g Tue Oct 25 19:07:31 2011
@@ -1846,6 +1846,9 @@ constant
     :
     Number
     | StringLiteral
+    | BigintLiteral
+    | SmallintLiteral
+    | TinyintLiteral
     | charSetStringLiteral
     | booleanValue
     ;
@@ -2400,6 +2403,21 @@ CharSetLiteral
     | '0' 'X' (HexDigit|Digit)+
     ;
 
+BigintLiteral
+    :
+    (Digit)+ 'L'
+    ;
+
+SmallintLiteral
+    :
+    (Digit)+ 'S'
+    ;
+
+TinyintLiteral
+    :
+    (Digit)+ 'Y'
+    ;
+
 Number
     :
     (Digit)+ ( DOT (Digit)* (Exponent)? | Exponent)?

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java?rev=1188858&r1=1188857&r2=1188858&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/TypeCheckProcFactory.java Tue Oct
25 19:07:31 2011
@@ -129,7 +129,10 @@ public final class TypeCheckProcFactory 
 
     opRules.put(new RuleRegExp("R1", HiveParser.TOK_NULL + "%"),
         getNullExprProcessor());
-    opRules.put(new RuleRegExp("R2", HiveParser.Number + "%"),
+    opRules.put(new RuleRegExp("R2", HiveParser.Number + "%|" +
+        HiveParser.TinyintLiteral + "%|" +
+        HiveParser.SmallintLiteral + "%|" +
+        HiveParser.BigintLiteral + "%"),
         getNumExprProcessor());
     opRules
         .put(new RuleRegExp("R3", HiveParser.Identifier + "%|"
@@ -217,9 +220,23 @@ public final class TypeCheckProcFactory 
       // try to parse the expression in that order to ensure that the
       // most specific type is used for conversion.
       try {
-        v = Double.valueOf(expr.getText());
-        v = Long.valueOf(expr.getText());
-        v = Integer.valueOf(expr.getText());
+        if (expr.getText().endsWith("L")) {
+          // Literal bigint.
+          v = Long.valueOf(expr.getText().substring(
+                0, expr.getText().length() - 1));
+        } else if (expr.getText().endsWith("S")) {
+          // Literal smallint.
+          v = Short.valueOf(expr.getText().substring(
+                0, expr.getText().length() - 1));
+        } else if (expr.getText().endsWith("Y")) {
+          // Literal tinyint.
+          v = Byte.valueOf(expr.getText().substring(
+                0, expr.getText().length() - 1));
+        } else {
+          v = Double.valueOf(expr.getText());
+          v = Long.valueOf(expr.getText());
+          v = Integer.valueOf(expr.getText());
+        }
       } catch (NumberFormatException e) {
         // do nothing here, we will throw an exception in the following block
       }

Added: hive/trunk/ql/src/test/queries/clientpositive/literal_ints.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/literal_ints.q?rev=1188858&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/literal_ints.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/literal_ints.q Tue Oct 25 19:07:31 2011
@@ -0,0 +1,3 @@
+EXPLAIN SELECT 100, 100Y, 100S, 100L FROM src LIMIT 1;
+
+SELECT 100, 100Y, 100S, 100L FROM src LIMIT 1;

Added: hive/trunk/ql/src/test/results/clientpositive/literal_ints.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/literal_ints.q.out?rev=1188858&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/literal_ints.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/literal_ints.q.out Tue Oct 25 19:07:31 2011
@@ -0,0 +1,51 @@
+PREHOOK: query: EXPLAIN SELECT 100, 100Y, 100S, 100L FROM src LIMIT 1
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN SELECT 100, 100Y, 100S, 100L FROM src LIMIT 1
+POSTHOOK: type: QUERY
+ABSTRACT SYNTAX TREE:
+  (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME src))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR
TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR 100) (TOK_SELEXPR 100Y) (TOK_SELEXPR 100S) (TOK_SELEXPR
100L)) (TOK_LIMIT 1)))
+
+STAGE DEPENDENCIES:
+  Stage-1 is a root stage
+  Stage-0 is a root stage
+
+STAGE PLANS:
+  Stage: Stage-1
+    Map Reduce
+      Alias -> Map Operator Tree:
+        src 
+          TableScan
+            alias: src
+            Select Operator
+              expressions:
+                    expr: 100
+                    type: int
+                    expr: 100
+                    type: tinyint
+                    expr: 100
+                    type: smallint
+                    expr: 100
+                    type: bigint
+              outputColumnNames: _col0, _col1, _col2, _col3
+              Limit
+                File Output Operator
+                  compressed: false
+                  GlobalTableId: 0
+                  table:
+                      input format: org.apache.hadoop.mapred.TextInputFormat
+                      output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+
+  Stage: Stage-0
+    Fetch Operator
+      limit: 1
+
+
+PREHOOK: query: SELECT 100, 100Y, 100S, 100L FROM src LIMIT 1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: file:/var/folders/71/h_j6fpg10r33hvx1lcxlgttcw61_4s/T/jonchang/hive_2011-10-21_11-16-07_740_3692263834720831080/-mr-10000
+POSTHOOK: query: SELECT 100, 100Y, 100S, 100L FROM src LIMIT 1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: file:/var/folders/71/h_j6fpg10r33hvx1lcxlgttcw61_4s/T/jonchang/hive_2011-10-21_11-16-07_740_3692263834720831080/-mr-10000
+100	100	100	100



Mime
View raw message