PHOENIX-1776 The literal -1.0 (floating point) should not be converted to -1 
(Integer) (Dave Hacker)

Conflicts:
        
phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/f490692c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f490692c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f490692c

Branch: refs/heads/3.0
Commit: f490692c2935707497153381312bbf8fea709749
Parents: a828537
Author: Samarth <samarth.j...@salesforce.com>
Authored: Thu Mar 26 00:37:12 2015 -0700
Committer: James Taylor <jtay...@salesforce.com>
Committed: Thu Apr 2 16:57:06 2015 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/ArithmeticQueryIT.java      | 28 ++++++++++++++++++++
 .../phoenix/compile/CreateTableCompiler.java    |  5 ++--
 .../apache/phoenix/parse/LiteralParseNode.java  |  1 +
 .../apache/phoenix/parse/ParseNodeFactory.java  | 11 ++++++--
 4 files changed, 40 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
index 21af737..3cb4b57 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
@@ -857,4 +857,32 @@ public class ArithmeticQueryIT extends 
BaseHBaseManagedTimeIT {
         assertTrue(rs.next());
         assertEquals(1.333333333, rs.getDouble(1), 0.001);
     }
+
+    @Test
+    public void testFloatingPointUpsert() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE test (id VARCHAR not null primary key, name 
VARCHAR, lat FLOAT)";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO test(id,name,lat) VALUES ('testid', 
'testname', -1.00)";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT lat FROM 
test");
+        assertTrue(rs.next());
+        assertEquals(-1.0f, rs.getFloat(1), 0.001);
+    }
+
+    @Test
+    public void testFloatingPointMultiplicationUpsert() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE test (id VARCHAR not null primary key, name 
VARCHAR, lat FLOAT)";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO test(id,name,lat) VALUES ('testid', 
'testname', -1.00 * 1)";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT lat FROM 
test");
+        assertTrue(rs.next());
+        assertEquals(-1.0f, rs.getFloat(1), 0.001);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
index ac50285..4af0cc9 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
@@ -51,6 +51,7 @@ import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.DelegateConnectionQueryServices;
 import org.apache.phoenix.schema.ColumnRef;
 import org.apache.phoenix.schema.MetaDataClient;
+import org.apache.phoenix.schema.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PMetaData;
 import org.apache.phoenix.schema.PTable;
@@ -58,8 +59,6 @@ import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableRef;
-import org.apache.phoenix.schema.types.PDataType;
-import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.QueryUtil;
 
@@ -318,7 +317,7 @@ public class CreateTableCompiler {
 
         @Override
         public PDataType getDataType() {
-            return PVarbinary.INSTANCE;
+            return PDataType.VARBINARY;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
index f9bbea1..a291b2a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
@@ -37,6 +37,7 @@ public class LiteralParseNode extends TerminalParseNode {
     public static final ParseNode NULL = new LiteralParseNode(null);
     public static final ParseNode ZERO = new LiteralParseNode(0);
     public static final ParseNode ONE = new LiteralParseNode(1);
+    public static final ParseNode MINUS_ONE = new LiteralParseNode(-1L);
     
     private final Object value;
     private final PDataType type;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 9ab31b1..7d14e58 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -542,8 +542,15 @@ public class ParseNodeFactory {
        return new ArrayConstructorNode(upsertStmtArray);
     }
 
-    public MultiplyParseNode negate(ParseNode child) {
-        return new MultiplyParseNode(Arrays.asList(child,this.literal(-1)));
+
+    public ParseNode negate(ParseNode child) {
+        // Prevents reparsing of -1 from becoming 1*-1 and 1*1*-1 with each 
re-parsing
+        if (LiteralParseNode.ONE.equals(child) && 
((LiteralParseNode)child).getType().isCoercibleTo(
+                PDataType.LONG)) {
+            return LiteralParseNode.MINUS_ONE;
+        }
+        return new 
MultiplyParseNode(Arrays.asList(child,LiteralParseNode.MINUS_ONE));
+
     }
 
     public NotEqualParseNode notEqual(ParseNode lhs, ParseNode rhs) {

Reply via email to