phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gr...@apache.org
Subject [1/2] git commit: PHOENIX-979 Delete on key and non-key field
Date Thu, 22 May 2014 07:26:26 GMT
Repository: incubator-phoenix
Updated Branches:
  refs/heads/master 5db15f09f -> 6c3b6524e


PHOENIX-979 Delete on key and non-key field

Correct behavior of a delete that is filtered by a combination
of the full row key and a single non-key field.


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

Branch: refs/heads/master
Commit: 4954c7371cf88dc19d314bb81b178100fae315f8
Parents: 5db15f0
Author: Gabriel Reid <greid@apache.org>
Authored: Tue May 20 20:06:33 2014 +0200
Committer: Gabriel Reid <gabrielr@ngdata.com>
Committed: Thu May 22 07:05:03 2014 +0200

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DeleteIT.java    | 66 ++++++++++++++++----
 .../apache/phoenix/compile/DeleteCompiler.java  |  9 ++-
 2 files changed, 61 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/4954c737/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
index 03d5ccc..4d41141 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
@@ -70,24 +70,68 @@ public class DeleteIT extends BaseHBaseManagedTimeIT {
     private void testDeleteFilter(boolean autoCommit) throws Exception {
         Connection conn = DriverManager.getConnection(getUrl());
         initTableValues(conn);
-        
-        ResultSet rs;
-        rs = conn.createStatement().executeQuery("SELECT count(*) FROM IntIntKeyTest");
-        assertTrue(rs.next());
-        assertEquals(NUMBER_OF_ROWS, rs.getInt(1));
 
-        String deleteStmt ;
+        assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS);
+        
         conn.setAutoCommit(autoCommit);
-        deleteStmt = "DELETE FROM IntIntKeyTest WHERE 20 = j";
+        String deleteStmt = "DELETE FROM IntIntKeyTest WHERE 20 = j";
         assertEquals(1,conn.createStatement().executeUpdate(deleteStmt));
         if (!autoCommit) {
             conn.commit();
         }
-        
-        String query = "SELECT count(*) FROM IntIntKeyTest";
-        rs = conn.createStatement().executeQuery(query);
+
+        assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS - 1);
+    }
+
+    @Test
+    public void testDeleteByRowAndFilterAutoCommit() throws SQLException {
+        testDeleteByFilterAndRow(true);
+    }
+
+
+    @Test
+    public void testDeleteByRowAndFilterNoAutoCommit() throws SQLException {
+        testDeleteByFilterAndRow(false);
+    }
+
+    private void testDeleteByFilterAndRow(boolean autoCommit) throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+        initTableValues(conn);
+
+        assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS);
+
+        conn.setAutoCommit(autoCommit);
+
+        Statement stmt = conn.createStatement();
+
+        // This shouldn't delete anything, because the key matches but the filter doesn't
+        assertEquals(0, stmt.executeUpdate("DELETE FROM IntIntKeyTest WHERE i = 1 AND j =
1"));
+        if (!autoCommit) {
+            conn.commit();
+        }
+        assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS);
+
+        // This shouldn't delete anything, because the filter matches but the key doesn't
+        assertEquals(0, stmt.executeUpdate("DELETE FROM IntIntKeyTest WHERE i = -1 AND j
= 20"));
+        if (!autoCommit) {
+            conn.commit();
+        }
+        assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS);
+
+        // This should do a delete, because both the filter and key match
+        assertEquals(1, stmt.executeUpdate("DELETE FROM IntIntKeyTest WHERE i = 1 AND j =
10"));
+        if (!autoCommit) {
+            conn.commit();
+        }
+        assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS - 1);
+
+    }
+
+    private void assertTableCount(Connection conn, String tableName, int expectedNumberOfRows)
throws SQLException {
+        ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) FROM " + tableName);
         assertTrue(rs.next());
-        assertEquals(NUMBER_OF_ROWS - 1, rs.getInt(1));
+        assertEquals(expectedNumberOfRows, rs.getInt(1));
+        rs.close();
     }
     
     private static void assertIndexUsed (Connection conn, String query, String indexName,
boolean expectedToBeUsed) throws SQLException {

http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/4954c737/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
index e338280..59a7ce7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
@@ -38,6 +38,7 @@ import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
 import org.apache.phoenix.execute.AggregatePlan;
 import org.apache.phoenix.execute.MutationState;
+import org.apache.phoenix.filter.SkipScanFilter;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.index.IndexMetaDataCacheClient;
 import org.apache.phoenix.index.PhoenixIndexCodec;
@@ -227,9 +228,11 @@ public class DeleteCompiler {
         final StatementContext context = plan.getContext();
         // If we're doing a query for a set of rows with no where clause, then we don't need
to contact the server at all.
         // A simple check of the none existence of a where clause in the parse node is not
sufficient, as the where clause
-        // may have been optimized out. Instead, we check that there's a single filter which
must be the SkipScanFilter
-        // in this case.
-        if (noQueryReqd && ! (context.getScan().getFilter() instanceof FilterList)
&& context.getScanRanges().isPointLookup()) {
+        // may have been optimized out. Instead, we check that there's a single SkipScanFilter
+        if (noQueryReqd
+                && (!context.getScan().hasFilter()
+                    || context.getScan().getFilter() instanceof SkipScanFilter)
+                && context.getScanRanges().isPointLookup()) {
             return new MutationPlan() {
 
                 @Override


Mime
View raw message