[
https://issues.apache.org/jira/browse/CALCITE-7737?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Darpan Lunagariya (e6data) updated CALCITE-7737:
------------------------------------------------
Description:
h2. Description
Add support for rewriting predicates on function results into equivalent
predicates on their input columns using function preimages.
For a function {{f}} and result domain {{D}}, the preimage is:
{code:none}
preimage(f, D) = {x | f(x) belongs to D}
{code}
Therefore:
{code:none}
SEARCH(f(column), D) <=> SEARCH(column, preimage(f, D))
{code}
The rewrite is applied only when exact equivalence can be established.
h2. Example
The {{YEAR}} function is monotonic over a date-time input: as the input
increases, the extracted year never decreases.
{code:sql}
YEAR(event_time) = 2020
{code}
The exact preimage of {{2020}} is the corresponding timestamp interval:
{code:sql}
event_time >= TIMESTAMP '2020-01-01 00:00:00'
AND event_time < TIMESTAMP '2021-01-01 00:00:00'
{code}
The function predicate can therefore be replaced with the base-column range.
h2. Initial scope
The initial generic implementation focuses on monotonic functions. For a
monotonic function, the preimage of an ordered result range can be represented
using straightforward input boundaries. These boundaries can be derived using a
symbolic inverse or bisection.
Non-monotonic functions may produce multiple disjoint input ranges and usually
require function-specific reasoning. They are not impossible to support, but
are outside the initial generic scope.
h2. Benefits
* It benefits frequently occurring monotonic functions like Floor, Ceil, Round,
some lossy cast(subject to runtime behaviour) etc.
* Enables file, row-group and page pruning using min/max statistics.
* Avoids evaluating the function for every row when the original predicate is
replaced with its exact preimage.
was:
h2. Description
Add support for rewriting predicates on function results into equivalent
predicates on their input columns using function preimages.
For a function {{f}} and result domain {{D}}, the preimage is:
{code:none}
preimage(f, D) = {x | f(x) belongs to D}
{code}
Therefore:
{code:none}
SEARCH(f(column), D) <=> SEARCH(column, preimage(f, D))
{code}
The rewrite is applied only when exact equivalence can be established.
h2. Example
The {{YEAR}} function is monotonic over a date-time input: as the input
increases, the extracted year never decreases.
{code:sql}
YEAR(event_time) = 2020
{code}
The exact preimage of {{2020}} is the corresponding timestamp interval:
{code:sql}
event_time >= TIMESTAMP '2020-01-01 00:00:00'
AND event_time < TIMESTAMP '2021-01-01 00:00:00'
{code}
The function predicate can therefore be replaced with the base-column range.
h2. Initial scope
The initial generic implementation focuses on monotonic functions. For a
monotonic function, the preimage of an ordered result range can be represented
using straightforward input boundaries. These boundaries can be derived using a
symbolic inverse or bisection.
Non-monotonic functions may produce multiple disjoint input ranges and usually
require function-specific reasoning. They are not impossible to support, but
are outside the initial generic scope.
h2. Benefits
* It benefits frequently occurring monotonic functions like Floor, Ceil, Round,
some lossy cast etc.
* Enables file, row-group and page pruning using min/max statistics.
* Avoids evaluating the function for every row when the original predicate is
replaced with its exact preimage.
> Predicate rewriting using function preimages
> --------------------------------------------
>
> Key: CALCITE-7737
> URL: https://issues.apache.org/jira/browse/CALCITE-7737
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Darpan Lunagariya (e6data)
> Assignee: Darpan Lunagariya (e6data)
> Priority: Minor
>
> h2. Description
> Add support for rewriting predicates on function results into equivalent
> predicates on their input columns using function preimages.
> For a function {{f}} and result domain {{D}}, the preimage is:
> {code:none}
> preimage(f, D) = {x | f(x) belongs to D}
> {code}
> Therefore:
> {code:none}
> SEARCH(f(column), D) <=> SEARCH(column, preimage(f, D))
> {code}
> The rewrite is applied only when exact equivalence can be established.
> h2. Example
> The {{YEAR}} function is monotonic over a date-time input: as the input
> increases, the extracted year never decreases.
> {code:sql}
> YEAR(event_time) = 2020
> {code}
> The exact preimage of {{2020}} is the corresponding timestamp interval:
> {code:sql}
> event_time >= TIMESTAMP '2020-01-01 00:00:00'
> AND event_time < TIMESTAMP '2021-01-01 00:00:00'
> {code}
> The function predicate can therefore be replaced with the base-column range.
> h2. Initial scope
> The initial generic implementation focuses on monotonic functions. For a
> monotonic function, the preimage of an ordered result range can be
> represented using straightforward input boundaries. These boundaries can be
> derived using a symbolic inverse or bisection.
> Non-monotonic functions may produce multiple disjoint input ranges and
> usually require function-specific reasoning. They are not impossible to
> support, but are outside the initial generic scope.
> h2. Benefits
> * It benefits frequently occurring monotonic functions like Floor, Ceil,
> Round, some lossy cast(subject to runtime behaviour) etc.
> * Enables file, row-group and page pruning using min/max statistics.
> * Avoids evaluating the function for every row when the original predicate is
> replaced with its exact preimage.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)