The problematic case happens when an array column of date/datetime
is simultaneously specified in an Array Join clause without aliases
and in a time converter, such as toYYYYMM.
After applying Array Join without aliases, the column's name refers
to the flattened array items, however, its data type is recognized
as a ColumnArray still, which leads to the unexpected exception
throws when building the preimage for the time converters.
As a quick fix, we more strictly check the data types of the time
converters and quit the preimage optimization pass early.
This commit checks the corner case where the comparator is none
of equals, notEquals, less, lessOrEquals, greater, greaterOrEquals,
and throws LOGICAL_ERROR exception if so.
As is suggested in issue #15257, the function preimage is a general
solution to the optimization problem with predicates containing the
date and datetime converters. This commit implements the idea by
adding the new methods, hasInformationAboutPreimage and getPreimage,
to IFunction/IFunctionBase, and having the specific convert functions
define their own preimage. Moreover, we added a new pass in the
TreeOptimizer and a new AST visitor for in-place rewriting the AST
with the converters' preimage.
Specifically, the optimization is applied to toYear and toYYYYMM.