CALCITE-828 introduced the usage of RelBuilder in RelFieldTrimmer. In Hive, we are hitting an issue in RelFieldTrimmer with the following query:
The problem is that the indicator boolean in the Aggregate operator is set to true, as grouping sets are present. In particular, the plan is the following:
However, RelFieldTrimmer will remove the indicator columns, as the number of GroupingSets is <1. This creates a mismatch in the number of columns that results in assertion error. By the definition of the trim function over an Aggregate in RelFieldTrimmer, indicator columns should not be removed.
PS. I tried to reproduce the issue in Calcite using the following query:
But I could not, as Calcite infers directly the constant value for the grouping column.