I'm struggling with parsing the expressoin properly. If I simply add the
operator (i.e. ::) to the binary operators list, the query is parsed but
the operand that is supposed to be a type, is parsed as an identifier
instead. And eventually the validation fails because that identifier (ex:
integer, regproc..etc) isn't found in any table, which is true because it's
a type (i.e. keyword), not an identifier.

Could someone guide me on this please?

I also need some help understanding this part of the parser:
-------
LOOKAHEAD(3) op = BinaryRowOperator() {
    checkNonQueryExpression(exprContext);
    list.add(new SqlParserUtil.ToTreeListItem(op, getPos()));
}
Expression2b(ExprContext.ACCEPT_SUB_QUERY, list)
-------

To me, this looks like the operator is consumed before its operands.
Shouldn't this expression be something like
-------
list.add(new SqlParserUtil.ToTreeListItem(SimpleIdentifier(), getPos()));
// LHS operaand
list.add(new SqlParserUtil.ToTreeListItem(BinaryRowOperator(), getPos()));
// Binary operator
list.add(new SqlParserUtil.ToTreeListItem(SimpleIdentifier(), getPos()));
// RHS operand
-------
How is it possible to identify the operator before its operands ?!

Thanks,
Gelbana


On Fri, Feb 15, 2019 at 9:49 PM Julian Hyde <[email protected]> wrote:

> I’ve added comments to the JIRA case.
>
> > On Feb 15, 2019, at 5:22 AM, Muhammad Gelbana <[email protected]>
> wrote:
> >
> > Here is what I've done so far for CALCITE-2843
> > <https://issues.apache.org/jira/browse/CALCITE-2843>:
> > https://github.com/MGelbana/calcite/pull/1/files
> > I appreciate a quick overview and guidance if I'm going in the wrong
> > direction.
> >
> > Thanks,
> > Gelbana
> >
> >
> > On Thu, Feb 14, 2019 at 5:57 PM Muhammad Gelbana <[email protected]>
> > wrote:
> >
> >> @Stamatis, I very appreciate you taking the time to comment on the
> issues
> >> I opened basd on this thread. I'm currently going through Babel's
> Parser.jj
> >> file and JavaCC documentations trying to understand what I need to do
> and
> >> where.
> >>
> >> Considering you're probably more acquainted than I am. I'll gladly work
> >> with you on a branch to fix this, based on your instructions of course.
> >> Otherwise, I'll continue working on my own.
> >>
> >> Thanks,
> >> Gelbana
> >>
> >>
> >> On Mon, Feb 11, 2019 at 11:31 PM Muhammad Gelbana <[email protected]>
> >> wrote:
> >>
> >>> Your replies are very much appreciated. I'll see what I can do.
> >>>
> >>> @Julian, I believe '=' acts as a boolean operator here because the
> query
> >>> returns boolean results for that part of the selection.
> >>>
> >>> Thanks,
> >>> Gelbana
> >>>
> >>>
> >>> On Mon, Feb 11, 2019 at 8:38 PM Julian Hyde <[email protected]> wrote:
> >>>
> >>>> There are a few Postgres-isms in that SQL:
> >>>> The “::” (as a shorthand for cast) in 'typinput='array_in'::regproc
> >>>> The ‘=‘ (as a shorthand for alias) in 'typinput='array_in'::regproc’
> >>>> Use of a table function without the ’TABLE’ keyword, in 'from
> >>>> generate_series(1, array_upper(current_schemas(false), 1))’
> >>>>
> >>>> Babel does not handle any of those right now, but it could.
> >>>> Contributions welcome.
> >>>>
> >>>> Julian
> >>>>
> >>>>
> >>>>> On Feb 11, 2019, at 6:14 AM, Stamatis Zampetakis <[email protected]>
> >>>> wrote:
> >>>>>
> >>>>> Hi Gelbana,
> >>>>>
> >>>>> In order to use the Babel parser you need to also set an appropriate
> >>>>> factory to your parser configuration since
> >>>>> setting only the conformance is not enough.
> >>>>>
> >>>>> Try adding the following:
> >>>>> ...
> >>>>> configBuilder().setParserFactory(SqlBabelParserImpl.FACTORY);
> >>>>>
> >>>>> Having said that I am not sure if Babel can handle the syntax you
> >>>> provided.
> >>>>>
> >>>>> Best,
> >>>>> Stamatis
> >>>>>
> >>>>>
> >>>>>
> >>>>> Στις Σάβ, 9 Φεβ 2019 στις 10:46 μ.μ., ο/η Muhammad Gelbana <
> >>>>> [email protected]> έγραψε:
> >>>>>
> >>>>>> I'm trying to parse a PostgreSQL metadata query but a parsing
> >>>> exception is
> >>>>>> thrown.
> >>>>>>
> >>>>>> Here is my code:
> >>>>>>
> >>>>>> Config parserConfig =
> >>>>>> configBuilder().setConformance(SqlConformanceEnum.BABEL).build();
> >>>>>> FrameworkConfig frameworkConfig =
> >>>>>> Frameworks.newConfigBuilder().parserConfig(parserConfig).build();
> >>>>>> Planner planner = Frameworks.getPlanner(frameworkConfig);
> >>>>>> planner.parse("SELECT typinput='array_in'::regproc, typtype FROM
> >>>>>> pg_catalog.pg_type LEFT JOIN (select ns.oid as nspoid, ns.nspname,
> >>>> r.r from
> >>>>>> pg_namespace as ns join ( select s.r, (current_schemas(false))[s.r]
> as
> >>>>>> nspname from generate_series(1, array_upper(current_schemas(false),
> >>>> 1)) as
> >>>>>> s(r) ) as r using ( nspname )) as sp ON sp.nspoid = typnamespace
> WHERE
> >>>>>> typname = $1 ORDER BY sp.r, pg_type.oid DESC LIMIT 1");
> >>>>>>
> >>>>>> *The exception title is* "Exception in thread "main"
> >>>>>> org.apache.calcite.sql.parser.SqlParseException: Encountered ":" at
> >>>> line 1,
> >>>>>> column 27."
> >>>>>>
> >>>>>> Am I doing something wrong or is the parser still not ready for such
> >>>> syntax
> >>>>>> ?
> >>>>>>
> >>>>>> Thanks,
> >>>>>> Gelbana
> >>>>>>
> >>>>
> >>>>
>
>

Reply via email to