I was working on parsing sql queries and then turning them into their parse trees, but in calcite, the smallest node is broken down to SqlIdentifier. Which doesn’t specify the context of the node.
I want to know if that Identifier node is a table name or a column name etc. But I haven’t found any way to do that in the parsing stage, all require me to go ahead with the Validation stage. I just want the parse tree to be more detailed.
I was looking at approaches like backtracking, or maintaining a data structure to figure out the context but I am stuck there as well.
Any help is appreciated, please, thank you!
I have tried backtracking to get more context, even maintaining a special data structure to store nodes and figure out, except for the validator class I have found no inbuilt method. If there is no inbuilt method, is there a data structure approach I can use to figure this out?
2
Answers
In short, no. Suppose your query is
In order to resolve that
empno
column in theSELECT
clause, Calcite needs to look at all the tables in theFROM
clause, make sure they exist, and gather the names and types of the columns in those tables. That is the validation process.After validation, it can resolve
empno
toe.empno
and report that its type isINTEGER NOT NULL
, but not before.Maybe you can use SqlSelect.getFrom() to get table names. just like this: