You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "James Taylor (JIRA)" <ji...@apache.org> on 2015/04/01 21:35:52 UTC

[jira] [Commented] (PHOENIX-1794) Support Long.MIN_VALUE for phoenix BIGINT type.

    [ https://issues.apache.org/jira/browse/PHOENIX-1794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14391294#comment-14391294 ] 

James Taylor commented on PHOENIX-1794:
---------------------------------------

Rather than just treating MIN_LONG specially, we should just generally handle constants that don't fit into a Long as a BigDecimal. The code is nearly identical, but we get more bang-for-the-buck. Just check if bd <= MAX_LONG. If yes, create the literal (use bd.longValue() instead of the string as there's no need to reparse the String). If it's too big, just keep it as a BigDecimal - your test has shown that this works fine and is coerced to a long when possible in the UPSERT statement. You can add a few more tests around when it's bigger than ABS(MIN_LONG) too. Also, I'd do the same range check in DOUBLE in the grammar file so we handle that case nicely as well, since you're mucking around with it anyway.
{code}
--- phoenix-core/src/main/antlr3/PhoenixSQL.g	(revision 2bf8c6788efb6dad7513f7bb14d2e9d75d7b50e3)
+++ phoenix-core/src/main/antlr3/PhoenixSQL.g	(revision )
@@ -204,7 +204,9 @@
     private int anonBindNum;
     private ParseNodeFactory factory;
     private ParseContext.Stack contextStack = new ParseContext.Stack();
-
+    
+    private static BigDecimal MIN_LONG = new BigDecimal(Long.MIN_VALUE).negate();
+
     public void setParseNodeFactory(ParseNodeFactory factory) {
         this.factory = factory;
     }
@@ -932,8 +934,13 @@
     :   l=LONG {
             try {
                 String lt = l.getText();
-                Long v = Long.valueOf(lt.substring(0, lt.length() - 1));
-                ret = factory.literal(v);
+                lt = lt.substring(0, lt.length() - 1);
+                BigDecimal bd = new BigDecimal(lt);
+                if (MIN_LONG.equals(bd)) {
+                    ret = factory.literal(bd);
+                } else {
+                    ret = factory.literal(Long.valueOf(lt));
+                }
             } catch (NumberFormatException e) { // Shouldn't happen since we just parsed a number
                 throwRecognitionException(l);
             }
{code}

> Support Long.MIN_VALUE for phoenix BIGINT type.
> -----------------------------------------------
>
>                 Key: PHOENIX-1794
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1794
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: Dave Hacker
>            Assignee: Dave Hacker
>         Attachments: PHOENIX-1794.patch
>
>
> Currently Possible values for BIGINT type: -9223372036854775807 to 9223372036854775807. 
> This is not fully inclusive of the set of all Long values in java, to do so we need to support Long.MIN_VALUE = -9223372036854775808



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)