Are you asking about RexUtil::flatten or some other helper function? On Wed, Aug 9, 2023 at 5:28 PM Julian Hyde <[email protected]> wrote:
> Flattened expressions - so that AND never contains a child that is > AND, and OR never contains a child that is OR - is a canonized form > that seems to have more advantages than disadvantages. It's never > larger than the original (unlike CNF and DNF), frequently smaller than > the original, doesn't take much effort to canonize, and allows the > multiple consumers of expressions (simplifications, planner rules) to > make some assumptions that yield good results efficiently. > > If you are only producing expressions you want Calcite to be liberal > in what it accepts; but if you are consuming expressions (e.g. > maintaining a rule) you want Calcite to be conservative in what it > accepts. You can't please both producers and consumers - it's a zero > sum game - but flattened expressions seemed to be a reasonable > compromise. > > I hope there's a simple process to get your expressions flattened. If > there's not, log a bug, so that there's a documented process. > > By the way, your note reminds me that we're not as diligent at > flattening OR as we are at flattening AND. We should fix that. > > Julian > > On Wed, Aug 9, 2023 at 9:09 AM Ian Bertolacci > <[email protected]> wrote: > > > > Hello, > > I’m curious about why Filter requires that the condition be a flattened > tree? > > We have some transformations which occasionally result in non-flat > trees, which causes issues for us in testing. > > > > I know we can avoid this by constructing expressions using RelBuilder or > the RexUtil.composeConjunction, but our transformers work very similar to > RexShuttle, which simply clones a RexCall on reconstruction. > > So there are situations where a subexpression to an `AND` or `OR` > expression result in a nested `AND` or `OR` expression. > > One solution is to use RexUtil.flatten, but that only applies flattening > for subexpressions with the same operator, so that expressions like `AND( > A, AND( B, C ), OR( E, OR( F, G ) )` only get partially flattened to only > gets flattened to `AND( A, B, C, OR( E, OR( F, G) )` which still isn’t > flat; the correct flattening would be `AND( A, B, C, OR( E, F, G ) )` > > Similarly, something like `AND( A, AND( B, C ) ) == …` wouldn’t get > flattened at all. > > > > Is there a real reason for having this assertion? > > Would removing it cause problems? > > Thanks! > > -Ian J. Bertolacci >
