How to keep origin sql unchanged as much as possible when optimizing sql by HepPlanner?

20 Views Asked by At

I want to optimize sql by RelNode and then convert it into SqlNode so that I can get sql string to execute. After validation and optimization by HepPlanner, I got relNode. here is my rules,

CoreRules.FILTER_INTO_JOIN,
CoreRules.FILTER_PROJECT_TRANSPOSE,
CoreRules.FILTER_SUB_QUERY_TO_CORRELATE,
CoreRules.FILTER_MERGE,
CoreRules.PROJECT_TABLE_SCAN,
CoreRules.PROJECT_INTERPRETER_TABLE_SCAN,
CoreRules.JOIN_CONDITION_PUSH,
CoreRules.JOIN_SUB_QUERY_TO_CORRELATE,
PruneEmptyRules.PROJECT_INSTANCE

And the sql string of sqlNode by RelToSqlConverter below,

Select 
CAST(c1 AS `INT64`),
COUNT(*),
COUNT(c3)
...

My Original sql string is below,

Select 
c1,
COUNT(c2),
COUNT(CAST(c3 AS Nullable(Float64))
...

And the input schema to HepPlanner as below,

rowType=RecordType:peek(BIGINT c1, INTEGER c2, STRING c3)

(types in physical clickhouse table is (NULLABLE(INT64) c1, NULLABLE(INT32) c2, Nullable(String) c3))

My expectation is like this,

Select 
c1,
COUNT(c2)
COUNT(CAST(c3 AS Nullable(Float64))
...

How can I achieve this without type cast changed and no count(*) to keep origin sql unchanged as much as possible?

0

There are 0 best solutions below