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

rejeb ben rejeb commented on PHOENIX-7391:
------------------------------------------

Hi [~stoty],

In my latest patch, as a workarownd, I created method 
[here|https://github.com/apache/phoenix-connectors/blob/8adb127b554f40cf1b32f855bb7d483ff57498a4/phoenix5-spark/src/main/java/org/apache/phoenix/spark/datasource/v2/reader/PhoenixDataSourceReader.java#L216]
  and 
[here|https://github.com/apache/phoenix-connectors/blob/8adb127b554f40cf1b32f855bb7d483ff57498a4/phoenix5-spark3/src/main/java/org/apache/phoenix/spark/sql/connector/PhoenixDataSource.java#L173]
 in connector using the same code approach and then tested different use cases 
with multitenant and salted tables and tests was successfull.
Since code in the method and PhoenixRuntime.generateColumnInfo is nearly the 
same and the fix is simple I haven't tested connectors with this patch however 
I added a test in this PR in order to validate that the fix works.

> PhoenixRuntime.generateColumnInfo does not filter tenant_id column
> ------------------------------------------------------------------
>
>                 Key: PHOENIX-7391
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-7391
>             Project: Phoenix
>          Issue Type: Bug
>          Components: core
>            Reporter: rejeb ben rejeb
>            Assignee: rejeb ben rejeb
>            Priority: Minor
>
> Given multitenant table:
> {code:java}
> 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{code}
>  
> Create View with tenantId= "MyTenantId":
> {code:java}
> CREATE VIEW IF NOT EXISTS TENANT_VIEW(TENANT_ONLY_COL VARCHAR) AS SELECT * 
> FROM MULTITENANT_TEST_TABLE {code}
> When call:
> {code:java}
> Properties props = new Properties();
> props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, "MyTenantId");
> Connection conn = DriverManager.getConnection(getUrl(), props);
> List<String> result = 
> PhoenixRuntime.generateColumnInfo(tsconn,"TENANT_VIEW",null).stream()
> .map(ColumnInfo::getDisplayName).collect(Collectors.toList());{code}
> Expected result is: GLOBAL_COL1,GLOBAL_COL2,TENANT_ONLY_COL
> Actual: TENANT_ID, GLOBAL_COL1,GLOBAL_COL2,TENANT_ONLY_COL
>  
> When I looked at method implementation I foud out that salted column was 
> filtered when getting columns info but not the tenantId column:
> {code:java}
> <line 5612> int offset = (table.getBucketNum() == null ? 0 : 1); {code}
>  
> As for Salt column, TENANT_ID column is an internal managed column so it 
> should be filtered when returning the list of columns.
> For generic process which use this method to get table column list, if 
> tenantId column is retruned in the list of column and the process try to 
> insert or fetch data with that list Phoenix will throw exception as it will 
> not recognize the column TENANT_ID.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to