Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

Add collectBooleanOperands helper function to flatten chained OR and AND
expressions into a flat list, matching ClickHouse's EXPLAIN AST format.

Previously, "a OR b OR c" would produce nested output like:
Function or
ExpressionList (2)
Function or (2)
a
b
c

Now it produces the expected flat format:
Function or
ExpressionList (3)
a
b
c

This change applies the flattening in three places:

  • explainBinaryExpr (main expression handling)
  • explainAliasedExpr (aliased expressions)
  • explainWithElement (WITH clause elements)

This fixes 419 explain tests.

Add collectBooleanOperands helper function to flatten chained OR and AND
expressions into a flat list, matching ClickHouse's EXPLAIN AST format.

Previously, "a OR b OR c" would produce nested output like:
  Function or
    ExpressionList (2)
      Function or (2)
        a
        b
      c

Now it produces the expected flat format:
  Function or
    ExpressionList (3)
      a
      b
      c

This change applies the flattening in three places:
- explainBinaryExpr (main expression handling)
- explainAliasedExpr (aliased expressions)
- explainWithElement (WITH clause elements)

This fixes 419 explain tests.
1. SampleRatio: Convert decimal values like 0.1 to fractions like 1/10
   in EXPLAIN output, matching ClickHouse's format for SAMPLE clauses.
   Added floatToFraction() helper to find simple fraction representation.

2. Aliased negative integers: Always output aliased negative integer
   literals as "Literal Int64_-N" instead of "Function negate". The
   previous code only did this in subquery context, but ClickHouse
   always uses the literal format for aliased expressions.

Fixes 4 explain tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants