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

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


The following commit(s) were added to refs/heads/master by this push:
     new 11620e79dc PHOENIX-7391 Do not return tenant_id column when getting 
columns list using PhoenixRuntime.generateColumnInfo
11620e79dc is described below

commit 11620e79dccf5159ba5d9e3bd8a4e73f5856ffbc
Author: rbenrejeb <[email protected]>
AuthorDate: Sat Aug 31 00:08:07 2024 +0200

    PHOENIX-7391 Do not return tenant_id column when getting columns list using 
PhoenixRuntime.generateColumnInfo
---
 .../org/apache/phoenix/util/PhoenixRuntime.java    | 14 +++++++----
 .../apache/phoenix/end2end/PhoenixRuntimeIT.java   | 27 +++++++++++++++++++++-
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java 
b/phoenix-core-client/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index 20641e4af4..88ad2e36ef 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -558,10 +558,16 @@ public class PhoenixRuntime {
         Set<String> unresolvedColumnNames = new TreeSet<String>();
         if (columns == null || columns.isEmpty()) {
             // use all columns in the table
-               int offset = (table.getBucketNum() == null ? 0 : 1);
-               for (int i = offset; i < table.getColumns().size(); i++) {
-                  PColumn pColumn = table.getColumns().get(i);
-               columnInfoList.add(PhoenixRuntime.getColumnInfo(pColumn)); 
+            int offset = 0;
+            if (table.getBucketNum() != null) {
+                offset++;
+            }
+            if (table.getTenantId() != null) {
+                offset++;
+            }
+            for (int i = offset; i < table.getColumns().size(); i++) {
+                PColumn pColumn = table.getColumns().get(i);
+                columnInfoList.add(PhoenixRuntime.getColumnInfo(pColumn));
             }
         } else {
             // Leave "null" as indication to skip b/c it doesn't exist
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
index ef42866772..e494b4f81d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PhoenixRuntimeIT.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.end2end;
 import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
 import java.sql.Connection;
@@ -28,6 +29,8 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.hadoop.hbase.CompareOperator;
 import org.apache.hadoop.hbase.client.Result;
@@ -46,6 +49,7 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.tuple.ResultTuple;
 import org.apache.phoenix.schema.types.PVarchar;
+import org.apache.phoenix.util.ColumnInfo;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
@@ -83,7 +87,28 @@ public class PhoenixRuntimeIT extends 
ParallelStatsDisabledIT {
     public void testGetTenantIdExpressionForUnsaltedTable() throws Exception {
         testGetTenantIdExpression(false);
     }
-    
+
+    @Test
+    public void testGenererateColumnInfoTenantTable() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        conn.setAutoCommit(true);
+        conn.createStatement().execute("CREATE TABLE MULTITENANT_TABLE 
(TENANT_ID VARCHAR NOT NULL, GLOBAL_COL1 VARCHAR, GLOBAL_COL2 VARCHAR 
CONSTRAINT pk PRIMARY KEY (TENANT_ID, GLOBAL_COL1)) MULTI_TENANT=true");
+        Properties props = new Properties();
+        props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, "MyTenantId");
+        Connection tconn = DriverManager.getConnection(getUrl(), props);
+        tconn.setAutoCommit(true);
+        tconn.createStatement().execute("CREATE VIEW IF NOT EXISTS 
TENANT_VIEW(TENANT_ONLY_COL VARCHAR) AS SELECT * FROM MULTITENANT_TABLE");
+
+        List<String> expected = 
Arrays.asList("GLOBAL_COL1","GLOBAL_COL2","TENANT_ONLY_COL");
+
+        List<String> result = PhoenixRuntime
+                .generateColumnInfo(tconn,"TENANT_VIEW",null)
+                .stream()
+                .map(ColumnInfo::getDisplayName).collect(Collectors.toList());
+
+        assertEquals(expected,result);
+    }
+
     private static Filter getUserTableAndViewsFilter() {
         SingleColumnValueFilter tableFilter = new 
SingleColumnValueFilter(TABLE_FAMILY_BYTES, 
PhoenixDatabaseMetaData.TABLE_TYPE_BYTES, CompareOperator.EQUAL, 
Bytes.toBytes(PTableType.TABLE.getSerializedValue()));
         tableFilter.setFilterIfMissing(true);

Reply via email to