2626import static org .neo4j .shell .prettyprint .OutputFormatter .NEWLINE ;
2727import static org .neo4j .shell .prettyprint .OutputFormatter .repeat ;
2828
29- class TablePlanFormatter {
29+ public class TablePlanFormatter {
3030
31- private static final String UNNAMED_PATTERN_STRING = " (UNNAMED|FRESHID|AGGREGATION)(\\ d+)" ;
31+ private static final String UNNAMED_PATTERN_STRING = " (UNNAMED|FRESHID|AGGREGATION|NODE|REL )(\\ d+)" ;
3232 private static final Pattern UNNAMED_PATTERN = Pattern .compile (UNNAMED_PATTERN_STRING );
3333 private static final String OPERATOR = "Operator" ;
3434 private static final String ESTIMATED_ROWS = "Estimated Rows" ;
@@ -38,16 +38,18 @@ class TablePlanFormatter {
3838 private static final String TIME = "Time (ms)" ;
3939 private static final String ORDER = "Ordered by" ;
4040 private static final String MEMORY = "Memory (Bytes)" ;
41- private static final String IDENTIFIERS = "Identifiers" ;
41+ public static final String IDENTIFIERS = "Identifiers" ;
4242 private static final String OTHER = "Other" ;
43+ public static final String DETAILS = "Details" ;
4344 private static final String SEPARATOR = ", " ;
4445 private static final Pattern DEDUP_PATTERN = Pattern .compile ("\\ s*(\\ S+)@\\ d+" );
46+ public static final int MAX_DETAILS_COLUMN_WIDTH = 100 ;
4547
46- private static final List <String > HEADERS = asList (OPERATOR , ESTIMATED_ROWS , ROWS , HITS , PAGE_CACHE , TIME , MEMORY , IDENTIFIERS , ORDER , OTHER );
48+ private static final List <String > HEADERS = asList (OPERATOR , DETAILS , ESTIMATED_ROWS , ROWS , HITS , PAGE_CACHE , TIME , MEMORY , IDENTIFIERS , ORDER , OTHER );
4749
4850 private static final Set <String > IGNORED_ARGUMENTS = new LinkedHashSet <>(
4951 asList ( "Rows" , "DbHits" , "EstimatedRows" , "planner" , "planner-impl" , "planner-version" , "version" , "runtime" , "runtime-impl" , "runtime-version" ,
50- "time" , "source-code" , "PageCacheMisses" , "PageCacheHits" , "PageCacheHitRatio" , "Order" , "Memory" , "GlobalMemory" ) );
52+ "time" , "source-code" , "PageCacheMisses" , "PageCacheHits" , "PageCacheHitRatio" , "Order" , "Memory" , "GlobalMemory" , "Details" ) );
5153 public static final Value ZERO_VALUE = Values .value (0 );
5254
5355 private int width (@ Nonnull String header , @ Nonnull Map <String , Integer > columns ) {
@@ -79,7 +81,8 @@ String formatPlan(@Nonnull Plan plan) {
7981 Map <String , Integer > columns = new HashMap <>();
8082 List <Line > lines = accumulate (plan , new Root (), columns );
8183
82- List <String > headers = HEADERS .stream ().filter (columns ::containsKey ).collect (Collectors .toList ());
84+ // Remove Identifiers column if we have a Details column
85+ List <String > headers = HEADERS .stream ().filter (header -> columns .containsKey (header ) && !(header .equals (IDENTIFIERS ) && columns .containsKey (DETAILS ))).collect (Collectors .toList ());
8386
8487 StringBuilder result = new StringBuilder ((2 + NEWLINE .length () + headers .stream ().mapToInt (h -> width (h , columns )).sum ()) * (lines .size () * 2 + 3 ));
8588
@@ -161,6 +164,8 @@ private String serialize(@Nonnull String key, @Nonnull Value v) {
161164 return v .asString ();
162165 case "PageCacheMisses" :
163166 return v .asNumber ().toString ();
167+ case "Details" :
168+ return v .asString ();
164169 default :
165170 return v .asObject ().toString ();
166171 }
@@ -208,6 +213,8 @@ private Map<String, Justified> details(@Nonnull Plan plan, @Nonnull Map<String,
208213 return mapping (TIME , new Right (String .format ("%.3f" , value .asLong () / 1000000.0d )), columns );
209214 case "Order" :
210215 return mapping ( ORDER , new Left ( String .format ( "%s" , value .asString () ) ), columns );
216+ case "Details" :
217+ return mapping ( DETAILS , new Left ( truncate (value .asString ()) ), columns );
211218 case "Memory" :
212219 return mapping ( MEMORY , new Right ( String .format ( "%s" , value .asNumber ().toString () ) ), columns );
213220 default :
@@ -439,4 +446,12 @@ public static <T1, T2> Pair<T1, T2> of(T1 _1, T2 _2) {
439446 return new Pair <>(_1 , _2 );
440447 }
441448 }
449+
450+ private String truncate ( String original ) {
451+ if (original .length () <= MAX_DETAILS_COLUMN_WIDTH ){
452+ return original ;
453+ }
454+
455+ return original .substring ( 0 , MAX_DETAILS_COLUMN_WIDTH - 3 ) + "..." ;
456+ }
442457}
0 commit comments