Simplest thing might be to parse the sub-structure of the string right there in the parser, and store it in the AST.
Something similar happens with datetime literals. Julian > On May 20, 2022, at 02:20, Dmitry Sysolyatin <[email protected]> wrote: > > I need some advice. I started to work on > https://issues.apache.org/jira/browse/CALCITE-5159 and faced the problem > that I need a Parser factory inside Validator in order to parse a string > literal to array literal. > > Would it be correct to pass ParserFactory to Validator from calcite > architecture point of view or there is another way to do it more elegant ? > >> On Fri, May 20, 2022 at 1:35 AM Julian Hyde <[email protected]> wrote: >> >> As I commented in https://issues.apache.org/jira/browse/CALCITE-5159 < >> https://issues.apache.org/jira/browse/CALCITE-5159>, this feature is more >> like an array literal. Consider that >> >> DATE ‘2022-05-19’ >> >> is a date literal, and if I write >> >> INSERT INTO t (dateColumn) VALUES (‘2022-05-19’) >> >> or >> >> SELECT * >> FROM t >> WHERE dateColumn = ‘2022-05-19’ >> >> the character literals become date literals. This array literal seems to >> work similarly. The parsing can happen at prepare time, and if the literal >> is invalid prepare should fail. >> >> Julian >> >> >> >>> On May 19, 2022, at 1:48 AM, Dmitry Sysolyatin <[email protected]> >> wrote: >>> >>> Thanks! >>> But I think I shouldn't create my own implementation of TypeCoercion. I >> can >>> just extend the existing TypeCoercionImpl if I will add >>> isStringToArrayCastEnabled() (by analogy with isTypeCoercionEnabled) to >>> SqlCallBinding in order to only postgres dialect has this feature. >>> >>> On Mon, May 16, 2022 at 12:35 PM Stamatis Zampetakis <[email protected]> >>> wrote: >>> >>>> Hi Dmitry, >>>> >>>> There is the TypeCoercion [1] interface that allows you to customize how >>>> implicit casts work. >>>> I guess you need to create your own implementation, customize the >> behavior >>>> of the binaryComparisonCoercion method (possibly others as well), and >> pass >>>> it to the validator. >>>> >>>> Best, >>>> Stamatis >>>> >>>> [1] >>>> >>>> >> https://github.com/apache/calcite/blob/1bce280a2957326dc5c249cfd079edfd2c54adf4/core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercion.java >>>> >>>> On Thu, May 12, 2022 at 4:42 PM Dmitry Sysolyatin < >> [email protected] >>>>> >>>> wrote: >>>> >>>>> Hi! >>>>> >>>>> I would like to implement implicit cast from string to array as PG >> does. >>>>> For example: "SELECT ARRAY[1,2,3] = '{1,2,3};'" should return true >>>> instead >>>>> of exception for Postgres dialect >>>>> >>>>> Is there an easy way to implement implicit cast? >>>>> >>>> >> >>
