Thank you for sharing the link! It helps to derive array type, but how to properly implement parsing when type is known ?
I was thinking of defining a method 'parseLiteral(String, RelDataType)' in the 'SqlAbstractParserImpl' class that would call a specific parser method depending on the type. For instance, for INTEGER data type, it would call 'NumericLiteral()', and for TIMESTAMP data type, it would call 'SqlParseUtil.parseTimestampLiteral', and so on. But maybe there is a better way to do it On Mon, Mar 27, 2023 at 4:32 PM Julian Hyde <[email protected]> wrote: > Are you familiar with the work I did in > https://issues.apache.org/jira/browse/CALCITE-5424 to defer the creation > of literals? Previously when a literal is a type followed by a string, such > as DATE ‘1969-07-21’, the string was parsed in the parser; now we defer > parsing the string until validation time, when the desired type is known > (having consulted the type system and in particular type aliases). > > Your logic could hook into that, for collection types such as TIMESTAMP > ARRAY. > > > On Mar 27, 2023, at 4:07 AM, Dmitry Sysolyatin <[email protected]> > wrote: > > > > Hi! > > Some time ago, I implemented an implicit cast from string literals to > > arrays [1]. However, this implementation has limitations. For instance, > the > > following query will not work: > > select a.v = ARRAY[1,2] FROM UNNEST(ARRAY['{1,2}', '{3,4}']) as a(v); > > > > Additionally, an implicit cast from arrays to strings has not been > > implemented. > > > > I began working on these things [2][3] and faced the issue that I have no > > idea how to properly implement parsing of typed arrays using JavaCC. Here > > are some examples: > > > > SELECT TIMESTAMP ARRAY ''{"2000-07-20 20:17:40", "2001-07-20 20:17:40"}' > > SELECT ARRAY[TIMESTAMP '2000-07-20 20:17:40', TIMESTAMP '2001-07-20 > > 20:17:40'] || array '{"2000-07-20 20:17:40", "2001-07-20 20:17:40"}'; > > > > Does someone have an idea of the best way to implement this? > > > > Thanks! > > > > [1] https://issues.apache.org/jira/browse/CALCITE-5159 > > [2] > > > https://github.com/dssysolyatin/calcite/tree/feature/implicit-cast-betweeb > > [3] > > > https://github.com/dssysolyatin/calcite/commit/bb41df3fbb1671e190633ed95f1684ada54603c1 >
