Repository: phoenix
Updated Branches:
  refs/heads/master f13b16800 -> 928fc62e1


PHOENIX-2319 SELECT failed on secondary index when table's columns are ALL 
primary key


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

Branch: refs/heads/master
Commit: 928fc62e1d467884918b573abc02741ede77f62d
Parents: f13b168
Author: James Taylor <[email protected]>
Authored: Thu Oct 15 12:04:30 2015 -0700
Committer: James Taylor <[email protected]>
Committed: Thu Oct 15 12:04:30 2015 -0700

----------------------------------------------------------------------
 .../end2end/index/IndexExpressionIT.java        | 68 ++++++++++++++++++++
 .../apache/phoenix/index/IndexMaintainer.java   |  2 +-
 2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/928fc62e/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
index 1a5fbcc..c193ee6 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexExpressionIT.java
@@ -1343,4 +1343,72 @@ public class IndexExpressionIT extends 
BaseHBaseManagedTimeIT {
                }
        }
 
+       @Test
+       public void testImmutableTableOnlyHasPrimaryKeyIndex() throws Exception 
{
+               helpTestTableOnlyHasPrimaryKeyIndex(false, false);
+       }
+
+       @Test
+       public void testImmutableLocalTableOnlyHasPrimaryKeyIndex() throws 
Exception {
+               helpTestTableOnlyHasPrimaryKeyIndex(false, true);
+       }
+
+       @Test
+       public void testMutableTableOnlyHasPrimaryKeyIndex() throws Exception {
+               helpTestTableOnlyHasPrimaryKeyIndex(true, false);
+       }
+
+       @Test
+       public void testMutableLocalTableOnlyHasPrimaryKeyIndex() throws 
Exception {
+               helpTestTableOnlyHasPrimaryKeyIndex(true, true);
+       }
+
+       private void helpTestTableOnlyHasPrimaryKeyIndex(boolean mutable,
+                       boolean localIndex) throws Exception {
+               Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+               Connection conn = DriverManager.getConnection(getUrl(), props);
+               String nameSuffix = "t" + (mutable ? "_mutable" : "_immutable") 
+ (localIndex ? "_local" : "_global");
+               String tableName = "t" + nameSuffix;
+               String indexName = "idx" + nameSuffix;
+               try {
+                       conn.createStatement().execute(
+                               "CREATE TABLE " + tableName + " ("
+                                                       + "pk1 VARCHAR not 
null, "
+                                                       + "pk2 VARCHAR not 
null, "
+                                                       + "CONSTRAINT PK 
PRIMARY KEY (pk1, pk2))"
+                                                       + (!mutable ? 
"IMMUTABLE_ROWS=true" : ""));
+                       String query = "SELECT * FROM " + tableName;
+                       ResultSet rs = 
conn.createStatement().executeQuery(query);
+                       assertFalse(rs.next());
+                       conn.createStatement().execute(
+                               "CREATE " + (localIndex ? "LOCAL" : "")
+                                       + " INDEX " + indexName + " ON " + 
tableName + " (pk2, pk1)");
+                       query = "SELECT * FROM " + indexName;
+                       rs = conn.createStatement().executeQuery(query);
+                       assertFalse(rs.next());
+
+                       PreparedStatement stmt = conn.prepareStatement("UPSERT 
INTO " + tableName + " VALUES(?,?)");
+                       stmt.setString(1, "k11");
+                       stmt.setString(2, "k21");
+                       stmt.execute();
+                       conn.commit();
+
+            query = "SELECT * FROM " + indexName;
+            rs = conn.createStatement().executeQuery(query);
+            assertTrue(rs.next());
+            assertEquals("k21", rs.getString(1));
+            assertEquals("k11", rs.getString(2));
+            assertFalse(rs.next());
+            
+                       query = "SELECT * FROM " + tableName + " WHERE 
pk2='k21'";
+                       rs = conn.createStatement().executeQuery(query);
+                       assertTrue(rs.next());
+                       assertEquals("k11", rs.getString(1));
+                       assertEquals("k21", rs.getString(2));
+                       assertFalse(rs.next());
+               } finally {
+                       conn.close();
+               }
+       }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/928fc62e/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index a12f633..b060345 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -834,7 +834,7 @@ public class IndexMaintainer implements Writable, 
Iterable<ColumnReference> {
                 nDeleteCF++;
             }
         }
-        return nDeleteCF == this.nDataCFs;
+        return nDeleteCF == this.nDataCFs && nDeleteCF > 0;
     }
     
     private boolean hasIndexedColumnChanged(ValueGetter oldState, 
Collection<KeyValue> pendingUpdates) throws IOException {

Reply via email to