As you think about this, I might suggest trying to use Substrait as an intermediate serialized representation between ZetaSQL and Calcite. We have already done some work on Substrait <=> Calcite [1] and are hoping some work can be done to add support for ZetaSQL => Substrait [2]. The benefit here is that people could also then use ZetaSQL with other systems that are supporting Substrait and one could avoid writing custom code for this one conversion. It also means ZetaSQL => Substrait code could stay in c++ and Substrait => Calcite code could stay in the JVM without having to write some kind of cross language boundary api calls (jni or similar).
[1] https://github.com/substrait-io/substrait-java [2] https://github.com/google/zetasql/issues/97 On Fri, Apr 22, 2022 at 11:25 AM Miguel Hernández Sandoval < rogelio.hernan...@wizeline.com> wrote: > Thanks Gavin/Julian, this is very helpful, I really appreciate it. About > contributing this feature as a module in Calcite, I'll let know the owners > of this > translation feature, I think they know it better and could contribute with > more knowledge and experience. > > Mike > > On Thu, Apr 21, 2022 at 4:36 PM Julian Hyde <jhyde.apa...@gmail.com> > wrote: > > > It’s complicated. Windowed aggregates start off as instances of RexOver > > expressions inside a Project and are later converted (by > > ProjectToWindowRule [1]) into Window relational operators. > > > > Both of these representations exist in RelNode-land and I’m not sure > which > > should be considered ‘canonical’. Window is a little bit more ‘physical’ > > than Project. At some stage in planning it is assumed that all RexOver > > instances have been converted. > > > > Julian > > > > [1] > > > https://github.com/apache/calcite/blob/bebe473fab2e242736614659ed6e5d04eeeb8bf5/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java#L74 > > < > > > https://github.com/apache/calcite/blob/bebe473fab2e242736614659ed6e5d04eeeb8bf5/core/src/main/java/org/apache/calcite/rel/rules/ProjectToWindowRule.java#L74 > > > > > > > > > On Apr 20, 2022, at 1:11 PM, Julian Hyde <jhyde.apa...@gmail.com> > wrote: > > > > > > It’s very interesting that you want to convert ZetaSQL to and from > > Calcite. I think other people will be interested in this. (It would help > > some of the things I am doing in my $dayjob at Google.) Would you > consider > > contributing this as a new module in Calcite? Or creating a standalone > > project on GitHub? > > > > > > Julian > > > > > > > > >> On Apr 20, 2022, at 12:27 PM, Miguel Hernández Sandoval < > > rogelio.hernan...@wizeline.com> wrote: > > >> > > >> Hi everyone, > > >> I'm currently working on a converter from a ZetaSQL AST to a > CalciteSQL > > >> Relational Operator Tree as part of a BeamSQL feature for Apache Beam. > > >> > > >> Right now, I'm trying to build a Relational Operator Tree that > > represents a > > >> window function (e.g. "*select SUM(a) over(), COUNT(b) over() From > T*"). > > >> I've read this document[1] where it is explained how relational > > operators > > >> work in Calcite but it doesn't contain more details about Window or > > >> LogicalWindow. > > >> It could be useful to know what a tree of this kind of function should > > look > > >> like in order to choose an approach. > > >> > > >> Could you give me some pointers on how to create a Relational Operator > > Tree > > >> that maps to a window function? > > >> Is there any other documentation you suggest? > > >> > > >> Thank you all for your help. > > >> > > >> [1] > > https://www.querifylabs.com/blog/relational-operators-in-apache-calcite > > >> > > >> -- > > >> > > >> Miguel Hernández Sandoval | WIZELINE > > >> > > >> Software Engineer > > >> > > >> rogelio.hernan...@wizeline.com > > >> > > >> Amado Nervo 2200, Esfera P6, Col. Jardines del Sol, 45050 Zapopan, > Jal. > > >> > > >> -- > > >> *This email and its contents (including any attachments) are being > sent > > to > > >> you on the condition of confidentiality and may be protected by legal > > >> privilege. Access to this email by anyone other than the intended > > recipient > > >> is unauthorized. If you are not the intended recipient, please > > immediately > > >> notify the sender by replying to this message and delete the material > > >> immediately from your system. Any further use, dissemination, > > distribution > > >> or reproduction of this email is strictly prohibited. Further, no > > >> representation is made with respect to any content contained in this > > email.* > > > > > > > > > -- > > Miguel Hernández Sandoval | WIZELINE > > Software Engineer > > rogelio.hernan...@wizeline.com > > Amado Nervo 2200, Esfera P6, Col. Jardines del Sol, 45050 Zapopan, Jal. > > -- > *This email and its contents (including any attachments) are being sent to > you on the condition of confidentiality and may be protected by legal > privilege. Access to this email by anyone other than the intended recipient > is unauthorized. If you are not the intended recipient, please immediately > notify the sender by replying to this message and delete the material > immediately from your system. Any further use, dissemination, distribution > or reproduction of this email is strictly prohibited. Further, no > representation is made with respect to any content contained in this > email.* >