Skip to content

Commit

Permalink
Implement toString in ExpressionRewriteRuleSet rules
Browse files Browse the repository at this point in the history
This makes toString reveal the underlying `ExpressionRewriter`
implementation (even if it's a lambda). Useful together with the verbose
`IterativeOptimizer` timeout reporting, which includes rules' timings.
  • Loading branch information
findepi committed Jan 11, 2022
1 parent 3f7d9c9 commit 79b61f9
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import static io.trino.sql.planner.plan.Patterns.values;
import static io.trino.sql.tree.SortItem.Ordering.ASCENDING;
import static io.trino.sql.tree.SortItem.Ordering.DESCENDING;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class ExpressionRewriteRuleSet
Expand Down Expand Up @@ -144,6 +145,12 @@ public Result apply(ProjectNode projectNode, Captures captures, Context context)
}
return Result.ofPlanNode(new ProjectNode(projectNode.getId(), projectNode.getSource(), assignments));
}

@Override
public String toString()
{
return format("%s(%s)", getClass().getSimpleName(), rewriter);
}
}

private static final class AggregationExpressionRewrite
Expand Down Expand Up @@ -214,6 +221,12 @@ public Result apply(AggregationNode aggregationNode, Captures captures, Context
}
return Result.empty();
}

@Override
public String toString()
{
return format("%s(%s)", getClass().getSimpleName(), rewriter);
}
}

private static final class FilterExpressionRewrite
Expand Down Expand Up @@ -241,6 +254,12 @@ public Result apply(FilterNode filterNode, Captures captures, Context context)
}
return Result.ofPlanNode(new FilterNode(filterNode.getId(), filterNode.getSource(), rewritten));
}

@Override
public String toString()
{
return format("%s(%s)", getClass().getSimpleName(), rewriter);
}
}

private static final class JoinExpressionRewrite
Expand Down Expand Up @@ -283,6 +302,12 @@ public Result apply(JoinNode joinNode, Captures captures, Context context)
}
return Result.empty();
}

@Override
public String toString()
{
return format("%s(%s)", getClass().getSimpleName(), rewriter);
}
}

private static final class ValuesExpressionRewrite
Expand Down Expand Up @@ -331,6 +356,12 @@ public Result apply(ValuesNode valuesNode, Captures captures, Context context)
}
return Result.empty();
}

@Override
public String toString()
{
return format("%s(%s)", getClass().getSimpleName(), rewriter);
}
}

private static final class PatternRecognitionExpressionRewrite
Expand Down Expand Up @@ -472,5 +503,11 @@ private Optional<ExpressionAndValuePointers> rewrite(ExpressionAndValuePointers

return Optional.empty();
}

@Override
public String toString()
{
return format("%s(%s)", getClass().getSimpleName(), rewriter);
}
}
}

0 comments on commit 79b61f9

Please sign in to comment.