Skip to content

Commit

Permalink
Indent PolyAlgebra debug outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-weber committed Apr 3, 2024
1 parent 3888e85 commit a8c7bde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 9 additions & 5 deletions core/src/main/java/org/polypheny/db/algebra/AbstractAlgNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 );
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/org/polypheny/db/algebra/AlgNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/plan/AlgOptUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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( "----> " );
Expand Down

0 comments on commit a8c7bde

Please sign in to comment.