[ 
https://issues.apache.org/jira/browse/PHOENIX-1271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14165955#comment-14165955
 ] 

James Taylor commented on PHOENIX-1271:
---------------------------------------

Sorry for the delay, [~bruno]. I like the approach, but there's one issue that 
would make this potentially expensive - to find out if a table is multi-tenant, 
you're faulting the PTable into the cache with the PhoenixRuntime.getTable() 
call:
{code}
+            // Each time a new table is encountered, check if it is 
multi-tenant or not
+            if 
(!PhoenixDatabaseMetaData.SYSTEM_CATALOG.equals(getStringColumn(tuple, 
schemaIndex))) {
+                String tableName = getStringColumn(tuple, tableNameIndex);
+                if (tableName == null || !tableName.equals(previousTable)) {
+                    previousTable = tableName;
+                    inMultiTenantTable = PhoenixRuntime.getTable(connection, 
tableName).isMultiTenant();
+                    tenantColumnSkipped = false;
+                }
+            }
{code}
Instead, I'd recommend that you tweak the query itself if you're on a 
tenant-specific connection such that the table header row is included in the 
results:
{code}
    boolean isTenantSpecificConnection = connection.getTenantId() != null;
    if (isTenantSpecificConnection) {
            where = "( (" + where + ") OR ("
                + COLUMN_FAMILY + " is null AND " + " COLUMN_NAME + " is null)";
    }
{code}
Then your TenantColumnFilteringIterator can check if the COLUMN_FAMILY and 
COLUMN_NAME is null and know that you're on the table header row. In this case, 
you can set your inMultiTenantTable because you'll have that column in the 
Tuple. You can also get rid of the check of the table name changing, as you'll 
know it changed each time you encounter the table header row. One change you 
could make is to add to the end of the ORDER BY we're doing to order by 
ORDINAL_POSITION as well. That way you could know to skip the first row right 
after the table header.

One other issue that you may or may not want to take care of is adjusting the 
ORDINAL_POSITION. You'd really want to decrement it by one in this case where 
you're filtering out the tenant id column (which you know is the first column).

> Column metadata doesn't hide tenant column on tenant-specific connections.
> --------------------------------------------------------------------------
>
>                 Key: PHOENIX-1271
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1271
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Karel Vervaeke
>         Attachments: PHOENIX-1271.patch, TenantColumnFilteringResultSet.java
>
>
> connection.getMetaData().getColumns(...) always returns all columns.
> For multi-tenant tables it would make more sense if the first PK (the 
> tenant-id column) would be excluded. If we do this the number of columns 
> returned would match the number of columns you get when executing a "select 
> *" query.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to