[
https://issues.apache.org/jira/browse/CALCITE-4978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17472701#comment-17472701
]
Vladimir Ozerov commented on CALCITE-4978:
------------------------------------------
Hi [~zabetak], [~julianhyde].
The list of constants might be used by the built-in and custom rules. Notable
examples are {{AggregateProjectPullUpConstantsRule}} and
{{ReduceExpressionsRule}}.
The list of constants is derived from predicates generated by
{{RelMdPredicates}}. The problem is that the constant derivation logic is
tightly coupled to {{RelOptPredicateList}}, and the
https://issues.apache.org/jira/browse/CALCITE-1465 made this coupling absolute.
First, the current derivation logic is very simplistic and can work only with
{{EQUALS}} and {{IS NOT NULL}} statements. This limits what constants could be
derived. We may try to improve the constant derivation logic in
{{RexUtil.predicateConstants}} as Statamits suggested. No doubt that the
product would benefit from it. However, I would argue that there is the second
issue - constant derivation might be *product-dependent*. For example, there
could be custom functions that are not transparent to Apache Calcite, but
together they impose some sensible constraints that the product's implementor
may use. E.g., one system may use {{TIMESTAMP}} with milliseconds, while
another one uses microseconds. In this case, the predicates {{tsCol>1 Jan 2022
10:00:005 AND tsCol<1 Jan 2022 10:00:007}} might be reduced to {{1 Jan 2022
10:00:006}} in the first system, but not in the second.
Currently, the only way to introduce such behavior is to override the affected
rules (i.e., copy-paste them). If the constant derivation is externalized
somehow (e.g., {{RelOptPredicateList.of(..., Function<> constantDeriveFn)}},
then we can move it to the rule configuration (or {{RelOptCluster}}), so that
the custom derivation could be employed by the target system without
copy-pastes.
Does it make sense to you?
> Allow custom constant map in RelOptPredicateList
> ------------------------------------------------
>
> Key: CALCITE-4978
> URL: https://issues.apache.org/jira/browse/CALCITE-4978
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.29.0
> Reporter: Vladimir Ozerov
> Assignee: Vladimir Ozerov
> Priority: Minor
>
> {{RelOptPredicateList}} tries to infer constants from the predicates passed
> to the {{of(...)}} factory methods. However, the underlying mechanic is
> limited and handles only a small subset of possible constant derivation
> strategies. We may want to implement such strategies gradually (inference
> from AND/OR, ranges, etc.), but it might be a big effort.
> This ticket proposes a new factory method that allows users to pass custom
> constant maps.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)