You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Jark Wu (Jira)" <ji...@apache.org> on 2020/12/02 15:53:00 UTC

[jira] [Commented] (FLINK-20447) Querying grouy by PK does not work

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

Jark Wu commented on FLINK-20447:
---------------------------------

Even if {{Code}} is the primary key, you still have to wrap non-grouped-fields in agg functions (e.g. MAX, MIN), or group by all the fields, because this is **syntax**. 

Primary key is just used for optimization, e.g. the optimizer can remove useless aggregations.

> Querying grouy by PK does not work
> ----------------------------------
>
>                 Key: FLINK-20447
>                 URL: https://issues.apache.org/jira/browse/FLINK-20447
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table SQL / API
>    Affects Versions: 1.11.2
>            Reporter: Zhenwei Feng
>            Priority: Major
>
> Since PRIMARY KEY is unique, it should be feasible to screen columns by PK.
> The problem could be reproduced by creating a simple table:
> {code:java}
> CREATE TABLE test_table(    
>   Code STRING,    
>   Name  STRING,    
>   ...,    
>   PRIMARY KEY (Code) NOT ENFORCED
> )WITH (...)
> {code}
> then parsing a SQL statement `SELECT *FROM test_table GROUP BY Code`. An exception as below will be thrown:
>  
> {code:java}
>  org.apache.calcite.sql.validate.SqlValidatorException: Expression 'test_table.Name' is not being grouped
> {code}
>  
>  
>  
>  



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