CALCITE-1618, we need to move to new Calcite release to fix it.
Due to this, SortProjectTransposeRule ignores CAST in the Project operator.
will be transformed into:
which is incorrect.
The problem seems to be in the permutation method in RelOptUtil, which is called in L87. The method actually considers a CAST on a reference as a valid column permutation of the column referenced; probably it should not.
permutation is only called by this rule and UnionPullUpConstantsRule, thus it seems it is safe to fix the semantics of the method.