The literal -1.0 (floating point) should not be converted to -1 (Integer) (Dave Hacker)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/24ee2c66 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/24ee2c66 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/24ee2c66 Branch: refs/heads/4.x-HBase-1.x Commit: 24ee2c66711664eb296d89522ecf8f6a950eb249 Parents: 8ea426c Author: Thomas <[email protected]> Authored: Thu Mar 26 13:11:35 2015 -0700 Committer: Thomas <[email protected]> Committed: Thu Mar 26 13:11:35 2015 -0700 ---------------------------------------------------------------------- .../phoenix/end2end/ArithmeticQueryIT.java | 28 ++++++++++++++++++++ .../apache/phoenix/parse/ParseNodeFactory.java | 4 ++- 2 files changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/24ee2c66/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 2df1827..72eb016 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 @@ -957,4 +957,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/24ee2c66/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 931f327..eb1768c 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 @@ -47,6 +47,7 @@ import org.apache.phoenix.schema.SortOrder; import org.apache.phoenix.schema.TypeMismatchException; import org.apache.phoenix.schema.stats.StatisticsCollectionScope; import org.apache.phoenix.schema.types.PDataType; +import org.apache.phoenix.schema.types.PLong; import org.apache.phoenix.schema.types.PTimestamp; import org.apache.phoenix.util.SchemaUtil; @@ -577,7 +578,8 @@ public class ParseNodeFactory { 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)) { + if (LiteralParseNode.ONE.equals(child) && ((LiteralParseNode)child).getType().isCoercibleTo( + PLong.INSTANCE)) { return LiteralParseNode.MINUS_ONE; } return new MultiplyParseNode(Arrays.asList(child,LiteralParseNode.MINUS_ONE));
