0

I am trying to convert sql query to Tinkerpop Gremlin. sql2Gremlin library does it but it looks on join as relation while I am relying on no join approach where you can refer relations with dot as delimiter between two entity.

I have parsed and validated query and I have RelRoot object.

Apache calcite returns RelRoot object which is root of algebraic expression.

Lets say I dont want to apply any query optimization, How do i use my RelNode Visitor to transform the RelRoot into TinkerPop Gremlin DSL.

Ideally I would first use From clause and then apply filters defined in where clause? How is select, filters, From clause represent in RelRoot tree?

What does apache calcite means by relational expression or RelNode?

Rephrasing the same question without TinkerPop Gremlin context: How should I use RelRoot visitor to visit the RelRoot and transform the query to another DSL?

Nischal Kumar
  • 492
  • 7
  • 15

1 Answers1

2

I don't know why you insist on RelRoot and not RelNode tree, but Apache Calcite is doing its optimizations of relational algebra in RelNode stack. There is a class called RelVisitor that you might find interesting, since it can do exactly what you need: visit all RelNodes. You can then extract information you need from them and build your DSL with it.

EDIT: In RelVisitor, you have access to the parent node and the child nodes of the currently visited node. You can extract all the information usually available to the RelNode object (see docs), and if you cast it to specific relational algebra operation, for example, Project, you can extract what fields are inside Project operation by doing node.getRowType().getFieldList().forEach(field -> names.add(field.getName())), where names is a previously defined Set<String>. You can find the full code here.

You should also take a look at the algebra docs to understand how SQL maps to relational algebra in Calcite before attempting this.

igrgurina
  • 50
  • 7