Search for uses of SqlKind.COALESCE. I initially thought that COALESCE was being expanded by a convertlet. But it seems that there isn’t such a covertlet. More likely that it is being simplified by RexSimplify.simplifyCoalesce.
If the result is significantly simpler, then I don’t think you should worry about sending the exact same expression to ES. Julian > On Aug 30, 2018, at 2:42 PM, Andrei Sereda <[email protected]> wrote: > > Hello, > > I’m trying to implement COALESCE for elastic adapter and would like to know > what is recommended approach to identify original function (after possible > rewrites). > > Let me give an example. > > Currently calcite converts COALESCE(attr, 'foo') into CASE(IS NOT > NULL(attr), attr, 'foo'). So in adapter I have to traverse RexCall and > check kind=CASE and operators[0] == IS NOT NULL and operators[1] == > INPUT_REF and operators[2] is literal to properly convert this call into > native elastic operation. Elastic has something similar > <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html#_missing_value_2> > to > coalesce (missing value) but not a generic case statement. > > What if tomorrow calcite decides to keep coalesce as is or rewrite to CASE(IS > NULL(attr),'foo', attr) ? It seems to me that trying all possible > combinations is a wrong thing to do (correct me if I’m wrong). > > How can I make this logic future-proof ? > > Thanks, > > Andrei.
