You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by la...@apache.org on 2021/03/23 17:53:09 UTC

[phoenix] branch 5.1 updated: PHOENIX-6424 SELECT cf1.* FAILS with a WHERE clause including cf2.

This is an automated email from the ASF dual-hosted git repository.

larsh pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.1 by this push:
     new 2fce483  PHOENIX-6424 SELECT cf1.* FAILS with a WHERE clause including cf2.
2fce483 is described below

commit 2fce483df1244957f7fc17a3b5a80f782315ec60
Author: Lars <la...@apache.org>
AuthorDate: Sun Mar 21 19:14:53 2021 -0700

    PHOENIX-6424 SELECT cf1.* FAILS with a WHERE clause including cf2.
---
 .../apache/phoenix/end2end/MultiCfQueryExecIT.java | 65 ++++++++++++++++++++++
 .../phoenix/iterate/BaseResultIterators.java       |  4 ++
 .../apache/phoenix/util/EncodedColumnsUtil.java    |  2 +-
 3 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
index 9299f93..a02012b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
@@ -342,6 +342,71 @@ public class MultiCfQueryExecIT extends ParallelStatsEnabledIT {
     }
 
     @Test
+    public void testCFWildcardProjection() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String tableName = generateUniqueName();
+            String ddl =
+                    "CREATE TABLE IF NOT EXISTS " + tableName + " (pk1 INTEGER NOT NULL PRIMARY KEY, x.v1 VARCHAR, y.v2 INTEGER)";
+            conn.createStatement().execute(ddl);
+            conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES(1, 'test', 2)");
+            conn.commit();
+
+            ResultSet rs = conn.createStatement().executeQuery("SELECT x.* FROM "+tableName+" WHERE y.v2 = 2");
+            assertTrue(rs.next());
+            assertEquals("test", rs.getString(1));
+            rs.close();
+
+            // make sure this works with a local index as well (only the data plan needs to be adjusted)
+            conn.createStatement().execute("CREATE LOCAL INDEX " + tableName + "_IDX ON " + tableName + "(y.v2)");
+            conn.commit();
+
+            rs = conn.createStatement().executeQuery("SELECT x.* FROM "+tableName+" WHERE y.v2 = 2");
+            assertTrue(rs.next());
+            assertEquals("test", rs.getString(1));
+            rs.close();
+
+            rs = conn.createStatement().executeQuery("SELECT y.* FROM "+tableName+" WHERE x.v1 <> 'blah'");
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            rs.close();
+        }
+    }
+
+    @Test
+    public void testMultipleCFWildcardProjection() throws Exception {
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            String tableName = generateUniqueName();
+            String ddl =
+                    "CREATE TABLE IF NOT EXISTS " + tableName + " (pk1 INTEGER NOT NULL PRIMARY KEY, x.v1 VARCHAR, y.v2 INTEGER, z.v3 INTEGER)";
+            conn.createStatement().execute(ddl);
+            conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES(1, 'test', 2, 3)");
+            conn.commit();
+
+            ResultSet rs = conn.createStatement().executeQuery("SELECT x.*, z.* FROM "+tableName+" WHERE y.v2 = 2");
+            assertTrue(rs.next());
+            assertEquals("test", rs.getString(1));
+            assertEquals(3, rs.getInt(2));
+            rs.close();
+
+            // make sure this works with a local index as well (only the data plan needs to be adjusted)
+            conn.createStatement().execute("CREATE LOCAL INDEX " + tableName + "_IDX ON " + tableName + "(y.v2)");
+            conn.commit();
+
+            rs = conn.createStatement().executeQuery("SELECT x.*, z.* FROM "+tableName+" WHERE y.v2 = 2");
+            assertTrue(rs.next());
+            assertEquals("test", rs.getString(1));
+            assertEquals(3, rs.getInt(2));
+            rs.close();
+
+            rs = conn.createStatement().executeQuery("SELECT x.*, y.* FROM "+tableName+" WHERE z.v3 = 3");
+            assertTrue(rs.next());
+            assertEquals("test", rs.getString(1));
+            assertEquals(2, rs.getInt(2));
+            rs.close();
+        }
+    }
+
+    @Test
     public void testMixedDefaultAndExplicitCFs() throws Exception {
         try (Connection conn = DriverManager.getConnection(getUrl())) {
             String tableName = generateUniqueName();
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
index 68c00a0..c6f7f5d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
@@ -496,6 +496,10 @@ public abstract class BaseResultIterators extends ExplainTable implements Result
                         trackedColumnsBitset.set(qualifier);
                     }
                 }
+            } else {
+                // cannot use EncodedQualifiersColumnProjectionFilter in this case
+                // since there's an unknown set of qualifiers (cf.*)
+                trackedColumnsBitset = null;
             }
             columnsTracker.put(cf, cols);
         }
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
index 11a8fd5..f1c0b1d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/EncodedColumnsUtil.java
@@ -133,7 +133,7 @@ public class EncodedColumnsUtil {
          * Disabling this optimization for tables with more than one column family.
          * See PHOENIX-3890.
          */
-        return !scan.isRaw() && table.getColumnFamilies().size() <= 1 && table.getImmutableStorageScheme() != null
+        return !scan.isRaw() && table.getColumnFamilies().size() == 1 && table.getImmutableStorageScheme() != null
                 && table.getImmutableStorageScheme() == ImmutableStorageScheme.ONE_CELL_PER_COLUMN
                 && usesEncodedColumnNames(table) && !table.isTransactional()
                 && !ScanUtil.hasDynamicColumns(table);