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 99c0cc4  PHOENIX-6423 Wildcard queries fail with mixed default and 
explicit column families.
99c0cc4 is described below

commit 99c0cc49f674d67e11243f80d7d22bed3dc56ab7
Author: Lars <la...@apache.org>
AuthorDate: Sat Mar 20 13:19:14 2021 -0700

    PHOENIX-6423 Wildcard queries fail with mixed default and explicit column 
families.
---
 .../apache/phoenix/end2end/MultiCfQueryExecIT.java | 26 ++++++++++++++++++++++
 .../apache/phoenix/compile/ProjectionCompiler.java |  5 +++++
 2 files changed, 31 insertions(+)

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 01da2d8..9299f93 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,32 @@ public class MultiCfQueryExecIT extends 
ParallelStatsEnabledIT {
     }
 
     @Test
+    public void testMixedDefaultAndExplicitCFs() 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, v1 VARCHAR, y.v1 INTEGER)";
+            conn.createStatement().execute(ddl);
+            conn.createStatement().execute("UPSERT INTO " + tableName + " 
VALUES(1, 'test', 2)");
+            conn.commit();
+            ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM 
"+tableName);
+            assertTrue(rs.next());
+            // Without PHOENIX-6423 this would throw a type mismatch 
exception, because it would confuse the 3rd
+            // column to also be the VARCHAR column.
+            assertEquals(2, rs.getInt(3));
+            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 + "(v1)");
+            conn.commit();
+            rs = conn.createStatement().executeQuery("SELECT * FROM 
"+tableName);
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(3));
+            rs.close();
+        }
+    }
+
+    @Test
     public void testBug3890() throws Exception {
         try (Connection conn = DriverManager.getConnection(getUrl())) {
             String tableName = generateUniqueName();
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
index 31af76a..bae0f0c 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ProjectionCompiler.java
@@ -159,6 +159,11 @@ public class ProjectionCompiler {
                         String schemaName = table.getSchemaName().getString();
                         ref = resolver.resolveColumn(schemaName.length() == 0 
? null : schemaName, table.getTableName().getString(), colName);
                     }
+                    // The freshly revolved column's family better be the same 
as the original one.
+                    // If not, trigger the disambiguation logic. Also see 
PTableImpl.getColumnForColumnName(...)
+                    if (column.getFamilyName() != null && 
!column.getFamilyName().equals(ref.getColumn().getFamilyName())) {
+                        throw new AmbiguousColumnException();
+                    }
                 } catch (AmbiguousColumnException e) {
                     if (column.getFamilyName() != null) {
                         ref = resolver.resolveColumn(tableAlias != null ? 
tableAlias : table.getTableName().getString(), 
column.getFamilyName().getString(), colName);

Reply via email to