Pull Request Reviews for Avatica
Hey everyone! Looking at the open pull requests for Avatica [1], it seems that there are a few that have been languishing for a while. Some of them seem pretty uncontroversial and simple, but there are some that will require further discussion (whether through the jira issue or here on the list). Can community members please spare some time to review some of the PRs and commit them? Francis [1] https://github.com/apache/calcite-avatica/pulls
[jira] [Created] (CALCITE-6317) Optimization CoreRules.PROJECT_REDUCE_EXPRESSIONS is unsound
Mihai Budiu created CALCITE-6317: Summary: Optimization CoreRules.PROJECT_REDUCE_EXPRESSIONS is unsound Key: CALCITE-6317 URL: https://issues.apache.org/jira/browse/CALCITE-6317 Project: Calcite Issue Type: Bug Components: core Affects Versions: 1.36.0 Reporter: Mihai Budiu Here is a query taken from agg.iq: {code:sql} select deptno, gender, grouping_id(deptno, gender, deptno), count(*) as c from emp where deptno = 10 group by rollup(gender, deptno) {code} The query plan initially is {code} LogicalProject(DEPTNO=[$1], GENDER=[$0], EXPR$2=[$2], C=[$3]), id = 72 LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[GROUPING_ID($1, $0, $1)], C=[COUNT()]), id = 71 LogicalProject(GENDER=[$2], DEPTNO=[$1]), id = 70 LogicalFilter(condition=[=($1, 10)]), id = 66 LogicalTableScan(table=[[schema, EMP]]), id = 65 {code} After applying PROJECT_REDUCE_EXPRESSIONS the plan looks like: {code} LogicalProject(DEPTNO=[CAST(10):INTEGER], GENDER=[$0], EXPR$2=[$2], C=[$3]), id = 82 LogicalAggregate(group=[{0, 1}], groups=[[{0, 1}, {0}, {}]], EXPR$2=[GROUPING_ID($1, $0, $1)], C=[COUNT()]), id = 78 LogicalProject(GENDER=[$2], DEPTNO=[CAST(10):INTEGER]), id = 84 LogicalFilter(condition=[=($1, 10)]), id = 74 LogicalTableScan(table=[[schema, EMP]]), id = 65 {code} The problem is in the outer LogicalProject, where the value 10 has replaced DEPTNO. However, DEPTNO can also be NULL, because of the groups in the LogicalAggregate. The constant should not be pushed past the aggregation. -- This message was sent by Atlassian Jira (v8.20.10#820010)
Re: Need Help on RelToSqlConverter simple use case
Please ignore my previous mail. I was able to get expected results. I got the project list properly expanded using visitRoot(relNode).asStatement(). Earlier I was using visitInput(relNode, 0).asQueryOrValues() which was generating wild card based projection list. Regards, Karthick On Sat, Mar 9, 2024 at 10:06 AM Karthick S wrote: > Hi All, > > I am trying to use calcite as a sql rewrite layer to attach some default > filter conditions on the incoming SQL queries for execution. I have been > able to successfully add FilterRule and modified the logicalplan to include > the filter. But when the convert the query back from RelNode to SqlNode, > the final query keeps * in the projection list instead of actual column > references. > > Even without using any filter additions, I am unable to produce the > correct query back. > > SELECT `F`.`FACID`, `F`.`NAME`, `F`.`MONTHLYMAINTENANCE` > FROM `FACILITIES` AS `F` > > Post Validation : > SELECT `F`.`FACID`, `F`.`NAME`, `F`.`MONTHLYMAINTENANCE` > FROM `FACILITIES` AS `F` > > Logical Plan > LogicalProject(FACID=[$0], NAME=[$1], MONTHLYMAINTENANCE=[$5]) > LogicalTableScan(table=[[facilities]]) > > > Logical Plan to SQL query: > SELECT * > FROM "facilities" > > Someone please guide me what am I missing here ? LogicalProject has all > the fields that i originally had in the input query, however when the query > produced out of RelToSqlConverter is having generic wild card * > > Regards, > Karthick >
Need Help on RelToSqlConverter simple use case
Hi All, I am trying to use calcite as a sql rewrite layer to attach some default filter conditions on the incoming SQL queries for execution. I have been able to successfully add FilterRule and modified the logicalplan to include the filter. But when the convert the query back from RelNode to SqlNode, the final query keeps * in the projection list instead of actual column references. Even without using any filter additions, I am unable to produce the correct query back. SELECT `F`.`FACID`, `F`.`NAME`, `F`.`MONTHLYMAINTENANCE` FROM `FACILITIES` AS `F` Post Validation : SELECT `F`.`FACID`, `F`.`NAME`, `F`.`MONTHLYMAINTENANCE` FROM `FACILITIES` AS `F` Logical Plan LogicalProject(FACID=[$0], NAME=[$1], MONTHLYMAINTENANCE=[$5]) LogicalTableScan(table=[[facilities]]) Logical Plan to SQL query: SELECT * FROM "facilities" Someone please guide me what am I missing here ? LogicalProject has all the fields that i originally had in the input query, however when the query produced out of RelToSqlConverter is having generic wild card * Regards, Karthick