PIG-4798: big integer literals fail to parse

git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1766879 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 4051e23..71c573e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -50,6 +50,8 @@
  
 BUG FIXES
 
+PIG-4798: big integer literals fail to parse (szita via daijy)
+
 PIG-5045: CSVExcelStorage Load: A Quoted Field with a Single Escaped Quote """" Becomes "" This should become " instead
   (szita via daijy)
 
diff --git a/src/docs/src/documentation/content/xdocs/basic.xml b/src/docs/src/documentation/content/xdocs/basic.xml
index a31653d..050530b 100644
--- a/src/docs/src/documentation/content/xdocs/basic.xml
+++ b/src/docs/src/documentation/content/xdocs/basic.xml
@@ -1335,6 +1335,26 @@
          </tr>
          <tr>
             <td>
+               <p>biginteger</p>
+            </td>
+            <td>
+               <p>19211921192119211921BI</p>
+            </td>
+            <td>
+            </td>
+         </tr>
+         <tr>
+            <td>
+               <p>bigdecimal</p>
+            </td>
+            <td>
+               <p>192119211921.192119211921BD</p>
+            </td>
+            <td>
+            </td>
+         </tr>
+         <tr>
+            <td>
                <p><strong>Complex Data Types</strong></p>
             </td>
             <td>
@@ -1388,7 +1408,18 @@
          <p>To specify a long constant, l or L must be appended to the number (for example, 12345678L). If the l or L is not specified, but the number is too large to fit into an int, the problem will be detected at parse time and the processing is terminated. </p>
       </li>
       <li>
-         <p>Any numeric constant with decimal point (for example, 1.5) and/or exponent (for example, 5e+1) is treated as double unless it ends with f or F in which case it is assigned type float (for example,  1.5f). </p>
+         <p>Any numeric constant with decimal point (for example, 1.5) and/or exponent (for example, 5e+1) is treated as double unless it ends with the following characters:</p>
+         <ul>
+            <li>
+               <p>f or F in which case it is assigned type float (for example,  1.5f)</p>
+            </li>
+            <li>
+               <p>BD or bd in which case it is assigned type BigDecimal (for example,  12345678.12345678BD)</p>
+            </li>
+         </ul>
+      </li>
+      <li>
+         <p>BigIntegers can be specified by supplying BI or bi at the end of the number (for example, 123456789123456BI)</p>
       </li>
       <li>
          <p>There is no native constant type for datetime field. You can use a ToDate udf with chararray constant as argument to generate a datetime value. </p>
diff --git a/src/org/apache/pig/parser/LogicalPlanBuilder.java b/src/org/apache/pig/parser/LogicalPlanBuilder.java
index 307f33f..df4a92a 100644
--- a/src/org/apache/pig/parser/LogicalPlanBuilder.java
+++ b/src/org/apache/pig/parser/LogicalPlanBuilder.java
@@ -1357,13 +1357,19 @@
         return Long.parseLong( num );
     }
 
+    /**
+     * Parse big integer formatted string (e.g. "1234567890123BI") into BigInteger object
+     */
     static BigInteger parseBigInteger(String s) {
-        String num = s.substring( 0, s.length() - 1 );
+        String num = s.substring( 0, s.length() - 2 );
         return new BigInteger( num );
     }
 
+    /**
+     * Parse big decimal formatted string (e.g. "123456.7890123BD") into BigDecimal object
+     */
     static BigDecimal parseBigDecimal(String s) {
-        String num = s.substring( 0, s.length() - 1 );
+        String num = s.substring( 0, s.length() - 2 );
         return new BigDecimal( num );
     }
 
diff --git a/src/org/apache/pig/parser/QueryParser.g b/src/org/apache/pig/parser/QueryParser.g
index bb0af5d..d7bc019 100644
--- a/src/org/apache/pig/parser/QueryParser.g
+++ b/src/org/apache/pig/parser/QueryParser.g
@@ -889,6 +889,8 @@
        | LONGINTEGER
        | FLOATNUMBER
        | DOUBLENUMBER
+       | BIGINTEGERNUMBER
+       | BIGDECIMALNUMBER
        | QUOTEDSTRING
        | NULL
        | TRUE
diff --git a/test/org/apache/pig/parser/TestQueryParser.java b/test/org/apache/pig/parser/TestQueryParser.java
index 4e56167..4aa8691 100644
--- a/test/org/apache/pig/parser/TestQueryParser.java
+++ b/test/org/apache/pig/parser/TestQueryParser.java
@@ -652,4 +652,14 @@
     public void testSplit2() throws Exception {
         shouldPass("SPLIT logs INTO logins IF command == 'login', all_quits IF command == 'quit';");
     }
+
+    @Test
+    public void testBigDecimalParsing() throws Exception {
+        shouldPass("B = FILTER A BY $1 < 1234567890.123456789BD;");
+    }
+
+    @Test
+    public void testBigIntegerParsing() throws Exception {
+        shouldPass("B = FILTER A BY $1 < 1234567890123456789BI;");
+    }
 }