Hi all,

Sometime earlier I emailed asking about how it might be possible to
auto-generate a GraphQL API for Calcite schemas, and to convert GraphQL
queries
into Calcite queries.

Stamatis Zampetakis replied pointing me towards the Pig examples (Thank
you! I
wasn't subscribed to the list and didn't know how to reply) and I'm happy to
report I've made what I consider good progress =)

Currently, I am able to:

- Consume an "org.calcite.schema.Schema" and generate a "GraphQLSchema"
from it
- Consume a GraphQL query for the generated GraphQLSchema, and convert the
"where" clause into the corresponding RelNode expressions

However, I've been stuck on a small issue and I've not been able to figure
it
out.

The RelNode I am generating is incorrectly translating an "OR" expression
into
an "AND" expression. I am using "RelBuilder.or()":

https://gist.github.com/GavinRay97/b40b3359674e94dfa7dd9c26146f8573#file-main-kt-L197-L262

For reference, here is the GraphQL query (for the "HR" schema I am testing
with):
https://gist.github.com/GavinRay97/b40b3359674e94dfa7dd9c26146f8573#file-main-kt-L460-L486

And the SQL I expect it to generate roughly:
https://gist.github.com/GavinRay97/b40b3359674e94dfa7dd9c26146f8573#file-main-kt-L447-L458

For the expected SQL, the plan that is generated is:
===============================================================
LogicalProject(inputs=[0], exprs=[[$2, $3, $1, $4]])
  LogicalFilter(condition=[AND(=(CAST($1):INTEGER NOT NULL, 20), >($3,
8000),
  <($3, 10000), OR(=(CAST($2):VARCHAR, 'Eric'), =(CAST($4):INTEGER, 10)))])
    LogicalTableScan(table=[[hr, emps]])

But for the GraphQL query, what is generated is the below plan:
===============================================================
LogicalProject(empid=[$0], name=[$2])
  LogicalFilter(condition=[AND(=($1, 20), SEARCH($3, Sarg[[8000..10000]]),
=($2,
  'Eric'), =($4, 10))])
    LogicalTableScan(table=[[emps]])


Using "RelToSqlConverter", it gives:
===============================================================
SELECT
    "empid", "name"
FROM
    "emps"
WHERE
    "deptno" = 20 AND ("salary" >= 8000 AND "salary" <= 10000) AND "name" =
    'Eric' AND "commission" = 10

The last line should be "AND (name = 'Eric' OR commission = 10)" If anyone
has
any ideas, I would be grateful for them. Probably I am using some part of
the API
wrong I assume.

Thank you =)

Reply via email to