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

Julian Hyde edited comment on CALCITE-6027 at 9/28/23 6:15 AM:
---------------------------------------------------------------

For those particular cases, you should make sure that constant reduction works.

For the general case, I get your point that {{cardinality(map_keys(m))}} → 
{{cardinality(m)}} for all {{m}}. And similarly {{map_values}}. This could be 
done in {{RexSimplify}}.


was (Author: julianhyde):
You don't need a special rule. Just do constant reduction.

> Add the rule to rewrite cardinality on map_keys and map_values functions
> ------------------------------------------------------------------------
>
>                 Key: CALCITE-6027
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6027
>             Project: Calcite
>          Issue Type: New Feature
>          Components: core
>    Affects Versions: 1.35.0
>            Reporter: Ran Tao
>            Assignee: Ran Tao
>            Priority: Major
>
> when we call cardinality on map_keys or map_values, such as:
> {code:java}
> select cardinality(map_keys(map['foo', 1, 'bar', 2]));
> select cardinality(map_values(map['foo', 1, 'bar', 2]));{code}
> they can be safely simplified to
> {code:java}
> select cardinality(map['foo', 1, 'bar', 2]);
> select cardinality(map['foo', 1, 'bar', 2]); {code}
>  
> Some other mature engines such as presto/trino has same optimized logic.



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

Reply via email to