From a8c7bde703269f43cb36186e7d5cc90709138a50 Mon Sep 17 00:00:00 2001 From: Tobias Weber Date: Wed, 3 Apr 2024 18:23:45 +0200 Subject: [PATCH] Indent PolyAlgebra debug outputs --- .../org/polypheny/db/algebra/AbstractAlgNode.java | 14 +++++++++----- .../java/org/polypheny/db/algebra/AlgNode.java | 7 ++++++- .../java/org/polypheny/db/plan/AlgOptUtil.java | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java b/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java index 63b3a1c93c..bfad0518ce 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java +++ b/core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java @@ -357,9 +357,12 @@ public AlgWriter explainTerms( AlgWriter pw ) { @Override - public void buildPolyAlgebra( StringBuilder sb ) { + public void buildPolyAlgebra( StringBuilder sb, String prefix ) { + final String INDENT = " "; + String nextPrefix = prefix == null ? null : prefix + INDENT; + PolyAlgDeclaration decl = getPolyAlgDeclaration(); - sb.append( decl.opName ); + sb.append( prefix == null ? "" : prefix ).append( decl.opName ); sb.append( collectAttributes().serializeArguments( this ) ); int size = getInputs().size(); @@ -375,13 +378,14 @@ public void buildPolyAlgebra( StringBuilder sb ) { StringBuilder csb = new StringBuilder(); if ( projections.isEmpty() ) { - child.buildPolyAlgebra( csb ); + child.buildPolyAlgebra( csb, nextPrefix ); } else { - csb.append( PolyAlgRegistry.getDeclaration( LogicalRelProject.class ).opName ) + csb.append( nextPrefix ) + .append( PolyAlgRegistry.getDeclaration( LogicalRelProject.class ).opName ) .append( "#[" ) .append( PolyAlgUtils.joinMultiValued( projections, true ) ) .append( "](\n" ); - child.buildPolyAlgebra( csb ); + child.buildPolyAlgebra( csb, nextPrefix == null ? null : nextPrefix + INDENT ); csb.append( ")" ); } sb.append( csb ); diff --git a/core/src/main/java/org/polypheny/db/algebra/AlgNode.java b/core/src/main/java/org/polypheny/db/algebra/AlgNode.java index 023e99504d..c4acb18fe2 100644 --- a/core/src/main/java/org/polypheny/db/algebra/AlgNode.java +++ b/core/src/main/java/org/polypheny/db/algebra/AlgNode.java @@ -245,8 +245,13 @@ public interface AlgNode extends AlgOptNode, Cloneable { * The basic structure of PolyAlgebra is {@code OPERATOR[attributes](children)}. * * @param sb StringBuilder for building the representation + * @param prefix Prefix to be added in front of each operator (resulting in operators having a visual indentation) or null if not desired */ - void buildPolyAlgebra( StringBuilder sb ); + void buildPolyAlgebra( StringBuilder sb, String prefix ); + + default void buildPolyAlgebra( StringBuilder sb) { + buildPolyAlgebra( sb, null ); + } /** * Retrieves the PolyAlgDeclaration for this AlgNode implementation. diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java index 922db55fc8..6ca8574218 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java @@ -1365,7 +1365,7 @@ public static void registerAbstractAlgs( AlgPlanner planner ) { public static String dumpPlan( String header, AlgNode alg, ExplainFormat format, ExplainLevel detailLevel ) { //TODO: Delete lines for testing PolyAlg serialization StringBuilder sb = new StringBuilder(); - alg.buildPolyAlgebra( sb ); + alg.buildPolyAlgebra( sb, "" ); System.out.println( "===== " + header + " =====" ); System.out.println( sb ); System.out.print( "----> " );