Got it. Thanks for the detail. I'll submit some unit tests for
RelBuilderTest to demonstrate this usage for others.


Thanks,

Andy.

--

Andy Grove
Chief Architect
AgilData - Simple Streaming SQL that Scales
www.agildata.com


On Thu, Nov 19, 2015 at 5:24 PM, Julian Hyde <[email protected]> wrote:

> A Project needs one input. It’s not negotiable.
>
> If you want to generate a single row, use RelBuilder.values(). There are
> several overloaded forms, but for your case probably
>
>   RelBuilder builder;
>   builder.values(“i”, 123)
>     .build();
>
> will do the trick. The VALUES relational operator is a leaf: it has no
> inputs, and produces a constant relation. In SQL terms, you are generating
>
>   VALUES (123);
>
> Other overloaded forms of the overloaded values method allow multiple
> columns and multiple rows, e.g.
>
>   VALUES (123, ‘a’), (234, ‘bcd’);
>
> Your mind has probably been poisoned by MySQL and Postgres’ non-standard
> FROM-less queries:
>
>   SELECT 123;
>
> Julian
>
>
>
> > On Nov 19, 2015, at 4:16 PM, Andy Grove <[email protected]> wrote:
> >
> > Hi,
> >
> > I'm now working on a project to translate some proprietary SQL to a
> Calcite
> > relational plan using the RelBuilder API.
> >
> > I have a question about literal projections. I can do this OK:
> >
> > // SELECT 123 FROM EMP
> > builder
> >    .scan("EMP")
> >    .project(builder.literal(123))
> >    .build();
> >
> > However, if I try and do "SELECT 123" without a relation, it fails with
> an
> > ArrayIndexOutOfBoundsException.
> >
> > // SELECT 123
> > builder
> >    .project(builder.literal(123))
> >    .build();
> >
> > Is there an extra step I need to add a fake relation, or is this a bug?
> I'm
> > happy to dig in and fix this if it is a bug, but wanted to verify first
> if
> > this expected to work or not.
> >
> > Thanks,
> >
> > Andy.
> >
> > --
> >
> > Andy Grove
> > Chief Architect
> > AgilData - Simple Streaming SQL that Scales
> > www.agildata.com
>
>

Reply via email to