You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Jonathan Sternberg <jo...@bodo.ai> on 2023/04/17 20:41:07 UTC

Extending SqlValidatorImpl with custom nodes

Hi,

When attempting to implement new nodes, such as create table or drop table,
and utilize the sql validator, what's the suggested manner for
implementation?

I see SqlValidatorImpl is the default implementation of the validator, but
I don't see a way to add new node types to the validator. When I create an
SqlCreate or SqlDrop and pass it to the validator, it throws an exception
in "registerQuery" since that node type isn't one of the expected node
types. At the same time, the methods inside of this class are all protected
so I can't extend and overwrite them to handle new node types.

Is there another recommended way to handle node validation for custom
nodes? Especially top level nodes.

--Jonathan Sternberg

Re: Extending SqlValidatorImpl with custom nodes

Posted by LakeShen <sh...@gmail.com>.
Hi Jonathan,

In my opinion, I think SqlCreate or SqlDrop doesn't need pass it to the
validator.
When create table or drop table sql was parsed to SqlNode(SqlCreate Or
SqlDrop),firstly you should determine what type of SqlNode it is and then
use the appropriate Handler to handle your DDL statements.

Maybe you could refer to dremio-oss, the example code like this :
[1] DropTableHandler:
https://github.com/dremio/dremio-oss/blob/master/sabot/kernel/src/main/java/com/dremio/exec/planner/sql/handlers/direct/DropTableHandler.java
[2] CreateTableHandler:
https://github.com/dremio/dremio-oss/blob/master/sabot/kernel/src/main/java/com/dremio/exec/planner/sql/handlers/query/CreateTableHandler.java

Hope can help you.

Best,
Lake Shen

Jonathan Sternberg <jo...@bodo.ai> 于2023年4月18日周二 04:42写道:

> Hi,
>
> When attempting to implement new nodes, such as create table or drop table,
> and utilize the sql validator, what's the suggested manner for
> implementation?
>
> I see SqlValidatorImpl is the default implementation of the validator, but
> I don't see a way to add new node types to the validator. When I create an
> SqlCreate or SqlDrop and pass it to the validator, it throws an exception
> in "registerQuery" since that node type isn't one of the expected node
> types. At the same time, the methods inside of this class are all protected
> so I can't extend and overwrite them to handle new node types.
>
> Is there another recommended way to handle node validation for custom
> nodes? Especially top level nodes.
>
> --Jonathan Sternberg
>