Yes, using Planner does abstract away some of the details for you which could be a good way to get started. The code snippet you posted would be a good start. core/src/test/java/org/apache/calcite/tools/PlannerTest.java has a lot of examples of the use of the planner interface. If you're looking for a more comprehensive example, Apache Hive uses Calcite's optimizer.
The other things you mentioned should all be possible with Calcite and possible to add incrementally. -- Michael Mior [email protected] 2017-09-26 11:35 GMT-04:00 Enrico Olivelli <[email protected]>: > Thank you for your Quick response Michael. > I will try to follow your suggestions > I will be back soon with my results > > There is another API Frameworks.getPlanner() which does something similar > Planner planner = Frameworks.getPlanner(config); > SqlNode parsed = planner.parse("SELECT * FROM MYTABLE"); > RelRoot rel = planner.rel(parsed); > > > I will have to deal with: > - schema changes > - caching plans > - multiple schemas > - indexes/costs based planer > > Do you (or any one else) have some links to test cases or other usages of > Calcite as planner ? > > Cheers > -- Enrico > > > > 2017-09-26 17:27 GMT+02:00 Michael Mior <[email protected]>: > > > That's definitely possible and is definitely the kind of use case Calcite > > is designed for. In terms of Calcite APIs, the approach would be > something > > like the following: > > > > Use SqlParser to get a SqlNode representing the query > > Implement CatalogReader to provide access to the schema > > Convert the SqlNode to a RelNode (relational algebra expression) using > > SqlToRelConverter > > Construct a RelOptPlanner instance and set the root of your planner to > the > > RelNode from your query > > Call findBestExp on the planner and then walk the generated expression > tree > > to generate a HerdDB plan > > > > This can hopefully get you pointed in the right direction. Personally, > I'm > > not sure how you would best incorporate the use of indexes, but I'm sure > > someone else will be able to chime in. > > > > Cheers, > > -- > > Michael Mior > > [email protected] > > > > 2017-09-26 10:36 GMT-04:00 Enrico Olivelli <[email protected]>: > > > > > Hi, > > > I would like to use Calcite as SQLPlanner in my open source project > > HerdDB > > > https://github.com/diennea/herddb > > > > > > HerdDB is a distributed database built in Java, it is essentially a > > > distributed key-value store but is has an SQL layer which is the > > entrypoint > > > for JDBC clients. > > > > > > Currently we have a very simple SQLPlanner, that is a component which > > maps > > > SQL language to an internal AST which represents the access plan to > data. > > > > > > I heard about Calcite and as far as I can see it would be easy to > > integrate > > > Calcite as SQL Planner. > > > > > > > > > I am expecting to have something like this: > > > 1) Give to Calcite an SQL query + Current schema + available > indexes.... > > > 2) Calcite which creates a access plan using Calcite AST > > > 3) Convert Calcite AST to HerdDB access plan AST > > > > > > I am not looking at something on the client-side I would like to use > > > Calcite on the server > > > is is possible ? > > > > > > Thank you in advance > > > > > > Enrico Olivelli > > > [email protected] > > > > > >
