The strategy of subclassing CalcitePrepareImpl is definitely right. You can’t change the createSqlValidator method (at line 721) because, as well as being private, it is static. Instead, you should probably subclass CalcitePreparingStatement and override its createSqlValidator method (at line 1088).
I don’t know whether anyone has done this — as first on the trail, you may need to hack through the undergrowth — but it’s the right way to go. Note that JdbcTest.MockDdlDriver uses a similar approach to substitute a different parser. I’d recommend that you try to write a similar unit test — say a validator that throws if the query has an even number of expressions in the SELECT clause. Julian > On Feb 21, 2023, at 4:02 PM, Oliver Lee <[email protected]> wrote: > > Hello Calcite contributors, > > I would like to have a subclass of CalciteSqlValidator to do custom SqlNode > validation. > > My planned approach is to make these following changes to allow for this > behavior: > > - > > Add a Driver.java > > <https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/jdbc/Driver.java#L62> > constructor to allow for setting prepareFactory > - > > Subclass CalcitePrepareImpl, change the createSqlValidator > > <https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java#L721> > access modifier to protected (from private) and override such that it > can return a custom SqlValidator class instead of CalciteSqlValidator > > <https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java#L737> > - > > Create a custom SqlValidator class that overrides the validate(SqlNode > topNode) > > <https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java#L780> > with desired custom validation logic. > > > Does anyone have comments or suggestions regarding this use case? > Thanks. > > - Oliver Lee
