You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/08/15 08:46:25 UTC
git commit: PHOENIX-1047 Auto cast - add/sub decimal constant and
integer
Repository: phoenix
Updated Branches:
refs/heads/3.0 3a6a9ddd8 -> 19dc23aa5
PHOENIX-1047 Auto cast - add/sub decimal constant and integer
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/19dc23aa
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/19dc23aa
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/19dc23aa
Branch: refs/heads/3.0
Commit: 19dc23aa511b31106b1ed791524ebc16ff3170c6
Parents: 3a6a9dd
Author: James Taylor <jt...@salesforce.com>
Authored: Thu Aug 14 23:50:13 2014 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Thu Aug 14 23:50:13 2014 -0700
----------------------------------------------------------------------
.../phoenix/end2end/ArithmeticQueryIT.java | 29 ++++++++++++++++++++
.../org/apache/phoenix/schema/PDataType.java | 11 +-------
.../arithmetic/ArithmeticOperationTest.java | 5 ++--
3 files changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/19dc23aa/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 ddc3f79..52c76a9 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
@@ -829,4 +829,33 @@ public class ArithmeticQueryIT extends BaseHBaseManagedTimeIT {
assertEquals(0, rs.getLong(1));
assertFalse(rs.next());
}
+
+ @Test
+ public void testCastingOnConstantAddInArithmeticEvaluation() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl = "CREATE TABLE IF NOT EXISTS test_table (k1 INTEGER NOT NULL, v1 INTEGER CONSTRAINT pk PRIMARY KEY (k1))";
+ conn.createStatement().execute(ddl);
+ String dml = "UPSERT INTO test_table (k1, v1) VALUES (2, 2)";
+ conn.createStatement().execute(dml);
+ conn.commit();
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1 / (v1 + 0.5) FROM test_table");
+ assertTrue(rs.next());
+ double d = rs.getDouble(1);
+ assertEquals(0.8, d, 0.01);
+ }
+
+ @Test
+ public void testCastingOnConstantSubInArithmeticEvaluation() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl = "CREATE TABLE IF NOT EXISTS test_table (k1 INTEGER NOT NULL, v1 INTEGER CONSTRAINT pk PRIMARY KEY (k1))";
+ conn.createStatement().execute(ddl);
+ String dml = "UPSERT INTO test_table (k1, v1) VALUES (2, 2)";
+ conn.createStatement().execute(dml);
+ conn.commit();
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1 / (v1 - 0.5) FROM test_table");
+ assertTrue(rs.next());
+ assertEquals(1.333333333, rs.getDouble(1), 0.001);
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/19dc23aa/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
index a915b2f..714028c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PDataType.java
@@ -1333,16 +1333,7 @@ public enum PDataType {
@Override
public Integer getScale(Object o) {
- if (o == null) {
- return null;
- }
- BigDecimal v = (BigDecimal) o;
- int scale = v.scale();
- if (scale == 0) {
- return null;
- }
- // If we have 5.0, we still want scale to be null
- return v.remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO) == 0 ? null : scale;
+ return null;
}
@Override
http://git-wip-us.apache.org/repos/asf/phoenix/blob/19dc23aa/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java b/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
index 97cf665..d90c6b6 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/arithmetic/ArithmeticOperationTest.java
@@ -18,6 +18,7 @@
package org.apache.phoenix.arithmetic;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -123,7 +124,7 @@ public class ArithmeticOperationTest {
boolean evaluated;
op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), PDataType.DECIMAL);
- assertEquals(Integer.valueOf(3),op1.getScale());
+ assertNull(op1.getScale());
op2 = LiteralExpression.newConstant(1, PDataType.INTEGER);
children = Arrays.<Expression>asList(op1, op2);
e = new DecimalAddExpression(children);
@@ -254,7 +255,7 @@ public class ArithmeticOperationTest {
// Decimal with no precision and scale.
op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), PDataType.DECIMAL);
- assertEquals(Integer.valueOf(1),op1.getScale());
+ assertNull(op1.getScale());
op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
children = Arrays.<Expression>asList(op1, op2);
e = new DecimalMultiplyExpression(children);