Repository: phoenix Updated Branches: refs/heads/master ad2ad0cef -> f941e89f4
PHOENIX-1776 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/f941e89f Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f941e89f Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f941e89f Branch: refs/heads/master Commit: f941e89f4f3a3778282ffc8570c64a181e01c043 Parents: ad2ad0c Author: Samarth <[email protected]> Authored: Thu Mar 26 00:37:12 2015 -0700 Committer: Samarth <[email protected]> Committed: Thu Mar 26 00:37:12 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/f941e89f/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/f941e89f/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));
