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

Jark Wu commented on FLINK-22196:
---------------------------------

Looks like a bug. But if partial fields of primary key is projected, the the 
whole primary key (or unique key) is not exist anymore. We should return null 
instead of filter out -1 indices. 

> FlinkRelMdUniqueKeys#getTableUniqueKeys should filter out  the column indices 
> which the does not exist in current row schema
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-22196
>                 URL: https://issues.apache.org/jira/browse/FLINK-22196
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Planner
>    Affects Versions: 1.12.2
>            Reporter: Lsw_aka_laplace
>            Priority: Major
>
> Well since we have supported project push-down, some primary-key in original 
> schema may not exist no longer more, so the non-existed column shall be 
> filtered out.
>  
> Current code:
> {code:java}
> val columns = relOptTable.getRowType.getFieldNames
> val columnIndices = schema.getPrimaryKey.get().getColumns map { c =>
>   columns.indexOf(c)
> }
> {code}
> May be supposed to correct to:
> {code:java}
> val columns = relOptTable.getRowType.getFieldNames
> val columnIndices = schema
>   .getPrimaryKey
>   .get()
>   .getColumns
>   .map(columns.indexOf)
>   .filterNot(_ == -1) // filter out the non-exist column
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to