What are you trying to achieve?

If you want Calcite to understand an unparsed SQL expression then you
need a SQL parser. RelBuilder is not a SQL parser. SqlParser is a SQL
parser.

On Mon, Jan 9, 2023 at 4:37 PM Heiko <[email protected]> wrote:
>
> Say from some legacy system I get some valid select stmt, e.g. "select a, b
> from foobar" (and known field names/types, how do I push this as an
> unparsed subquery into a relbuilder so I can do something like
>
>     RelNode node = builder
>         .projectPlus(builder.call(MINUS, builder.field("b"),
> builder.field("a")))
>         .build();
>
>     Result result = new RelToSqlConverter(dialect).visitRoot(node);
>
>     String sqlString = result
>         .asSelect()
>         .toSqlString(dialect)
>         .getSql();
>
> where "sqlString" would then become something like
>
> SELECT `a` - `b` FROM (select a, b from foobar) AS `$f1`
>
> (note; I could of course parse the SELECT statement but I'm not 100%
> convinced all the possible SQL select statements would be parseable by
> Calcite, so when they're not I want to use above approach to treat them
> basically as black-box subqueries)
>
> Thanks,
> -Heiko

Reply via email to