I'm currently working on CALCITE-6044. I have a problem that I thought would be solved by mq.getAllPredicates(rel) but the output is from a perspective that doesn't seem useful for my problem, which is, given this query:
select deptno, ename, sum(sal)from empwhere deptno=1010group by deptno, ename and a call to areColumnsUnique(Aggregate rel, mq, bitSetOf(1), false), I'd like it to return true. It currently returns true for columns {0, 1} on account that those are the columns in the group by clause. However, it doesn't recognize that since deptno is set to a constant, the remaining column (ename/1) is by itself an effective key. To solve this, I plan to collect a bitset of the constant columns (would be {0} in this example), and remove those columns from the group-by columns. I thought the way to collect those columns was to call mq.getAllPredicates(rel) and take the columns from constantMap.keySet(), however, the RexInputRefs are relative to the table scans (returning column 7 instead of 0), ignoring the effects on column ordering of the projection and aggregation. Is there an existing utility that can either transform these results or return them from the perspective of the current RelNode? Paul Jackson