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 2015/08/31 03:22:01 UTC
phoenix git commit: PHOENIX-2206 Math function called with PK column
ignores WHERE clause
Repository: phoenix
Updated Branches:
refs/heads/master 16fcdf9e1 -> da37b9dac
PHOENIX-2206 Math function called with PK column ignores WHERE clause
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/da37b9da
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/da37b9da
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/da37b9da
Branch: refs/heads/master
Commit: da37b9dacd071ad6afc044602cbef56c21d62033
Parents: 16fcdf9
Author: James Taylor <jt...@salesforce.com>
Authored: Sun Aug 30 18:21:14 2015 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Sun Aug 30 18:21:34 2015 -0700
----------------------------------------------------------------------
.../phoenix/end2end/ExpFunctionEnd2EndIT.java | 24 ++++++++++++++++++++
.../apache/phoenix/compile/WhereOptimizer.java | 15 ------------
.../phoenix/compile/WhereOptimizerTest.java | 11 +++++++++
3 files changed, 35 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/da37b9da/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
index 8772400..a723c6b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java
@@ -18,6 +18,8 @@
package org.apache.phoenix.end2end;
import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.sql.Connection;
@@ -125,4 +127,26 @@ public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeIT {
testUnsignedNumberSpec(conn, d);
}
}
+
+ @Test
+ public void testExpForLeadingPK() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl = "create table test (id integer primary key)";
+ conn.createStatement().execute(ddl);
+ String dml = "upsert into test values (?)";
+ PreparedStatement stmt = conn.prepareStatement(dml);
+ for (int i = 1; i <= 5; i++) {
+ stmt.setInt(1, i);
+ stmt.execute();
+ }
+ conn.commit();
+
+ ResultSet rs = conn.createStatement().executeQuery("select ID, exp(ID) from test where exp(ID) < 10");
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+ assertFalse(rs.next());
+ }
+
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/da37b9da/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
index 1caec55..95cea83 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereOptimizer.java
@@ -829,17 +829,6 @@ public class WhereOptimizer {
this.table = table;
}
-// private boolean isFullyQualified(int pkSpan) {
-// int nPKColumns = table.getPKColumns().size();
-// return table.getBucketNum() == null ? pkSpan == nPKColumns : pkSpan == nPKColumns-1;
-// }
- @Override
- public KeySlots defaultReturn(Expression node, List<KeySlots> l) {
- // Passes the CompositeKeyExpression up the tree
- return l.size() == 1 ? l.get(0) : null;
- }
-
-
@Override
public Iterator<Expression> visitEnter(CoerceExpression node) {
return node.getChildren().iterator();
@@ -873,10 +862,6 @@ public class WhereOptimizer {
public KeySlots visitLeave(OrExpression node, List<KeySlots> l) {
KeySlots keySlots = orKeySlots(node, l);
if (keySlots == null) {
- // If we don't clear the child list, we end up passing some of
- // the child expressions of the OR up the tree, causing only
- // those expressions to form the scan start/stop key.
- l.clear();
return null;
}
return keySlots;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/da37b9da/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
index 79ec3f5..2413013 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/WhereOptimizerTest.java
@@ -96,6 +96,17 @@ public class WhereOptimizerTest extends BaseConnectionlessQueryTest {
assertEquals(limit, plan.getLimit());
return plan.getContext();
}
+
+ @Test
+ public void testMathFunc() throws SQLException {
+ Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
+ conn.createStatement().execute("create table test (id integer primary key)");
+ Scan scan = compileStatement("select ID, exp(ID) from test where exp(ID) < 10").getScan();
+
+ assertNotNull(scan.getFilter());
+ assertTrue(scan.getStartRow().length == 0);
+ assertTrue(scan.getStopRow().length == 0);
+ }
@Test
public void testSingleKeyExpression() throws SQLException {