Re: Implicit cast from string to array
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 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 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 >> 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 >>> 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 < >> dm.sysolya...@gmail.com >>>>> >>>> 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? >>>>> >>>> >> >>
Re: Implicit cast from string to array
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 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 > 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 > > 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 < > dm.sysolya...@gmail.com > >>> > >> 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? > >>> > >> > >
Re: Implicit cast from string to array
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 > 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 > 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 >> >> 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? >>> >>
[jira] [Created] (CALCITE-5159) PG dialect should support implicit cast from string to array
Dmitry Sysolyatin created CALCITE-5159: -- Summary: PG dialect should support implicit cast from string to array Key: CALCITE-5159 URL: https://issues.apache.org/jira/browse/CALCITE-5159 Project: Calcite Issue Type: Improvement Components: core Reporter: Dmitry Sysolyatin Assignee: Dmitry Sysolyatin According to the documentation [https://www.postgresql.org/docs/current/arrays.html] Postgres dialect should support implicit cast from string to array: {code:java} SELECT ARRAY[1,2,3] = '{1,2,3}' {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)
Re: Implicit cast from string to array
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 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 > > 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? > > >
Re: Implicit cast from string to array
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 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? >
Implicit cast from string to array
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?