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" ;
@@ -37,16 +37,18 @@ class TablePlanFormatter {
3737 private static final String PAGE_CACHE = "Cache H/M" ;
3838 private static final String TIME = "Time (ms)" ;
3939 private static final String ORDER = "Ordered by" ;
40- private static final String IDENTIFIERS = "Identifiers" ;
40+ public static final String IDENTIFIERS = "Identifiers" ;
4141 private static final String OTHER = "Other" ;
42+ public static final String DETAILS = "Details" ;
4243 private static final String SEPARATOR = ", " ;
4344 private static final Pattern DEDUP_PATTERN = Pattern .compile ("\\ s*(\\ S+)@\\ d+" );
45+ public static final int MAX_DETAILS_COLUMN_WIDTH = 100 ;
4446
45- private static final List <String > HEADERS = asList (OPERATOR , ESTIMATED_ROWS , ROWS , HITS , PAGE_CACHE , TIME , IDENTIFIERS , ORDER , OTHER );
47+ private static final List <String > HEADERS = asList (OPERATOR , DETAILS , ESTIMATED_ROWS , ROWS , HITS , PAGE_CACHE , TIME , IDENTIFIERS , ORDER , OTHER );
4648
4749 private static final Set <String > IGNORED_ARGUMENTS = new LinkedHashSet <>(
4850 asList ( "Rows" , "DbHits" , "EstimatedRows" , "planner" , "planner-impl" , "planner-version" , "version" , "runtime" , "runtime-impl" , "runtime-version" ,
49- "time" , "source-code" , "PageCacheMisses" , "PageCacheHits" , "PageCacheHitRatio" , "Order" ) );
51+ "time" , "source-code" , "PageCacheMisses" , "PageCacheHits" , "PageCacheHitRatio" , "Order" , "Details" ) );
5052 public static final Value ZERO_VALUE = Values .value (0 );
5153
5254 private int width (@ Nonnull String header , @ Nonnull Map <String , Integer > columns ) {
@@ -78,7 +80,8 @@ String formatPlan(@Nonnull Plan plan) {
7880 Map <String , Integer > columns = new HashMap <>();
7981 List <Line > lines = accumulate (plan , new Root (), columns );
8082
81- List <String > headers = HEADERS .stream ().filter (columns ::containsKey ).collect (Collectors .toList ());
83+ // Remove Identifiers column if we have a Details column
84+ List <String > headers = HEADERS .stream ().filter (header -> columns .containsKey (header ) && !(header .equals (IDENTIFIERS ) && columns .containsKey (DETAILS ))).collect (Collectors .toList ());
8285
8386 StringBuilder result = new StringBuilder ((2 + NEWLINE .length () + headers .stream ().mapToInt (h -> width (h , columns )).sum ()) * (lines .size () * 2 + 3 ));
8487
@@ -160,6 +163,8 @@ private String serialize(@Nonnull String key, @Nonnull Value v) {
160163 return v .asString ();
161164 case "PageCacheMisses" :
162165 return v .asNumber ().toString ();
166+ case "Details" :
167+ return v .asString ();
163168 default :
164169 return v .asObject ().toString ();
165170 }
@@ -207,6 +212,8 @@ private Map<String, Justified> details(@Nonnull Plan plan, @Nonnull Map<String,
207212 return mapping (TIME , new Right (String .format ("%.3f" , value .asLong () / 1000000.0d )), columns );
208213 case "Order" :
209214 return mapping ( ORDER , new Left ( String .format ( "%s" , value .asString () ) ), columns );
215+ case "Details" :
216+ return mapping ( DETAILS , new Left ( truncate (value .asString ()) ), columns );
210217 default :
211218 return Optional .empty ();
212219 }
@@ -436,4 +443,12 @@ public static <T1, T2> Pair<T1, T2> of(T1 _1, T2 _2) {
436443 return new Pair <>(_1 , _2 );
437444 }
438445 }
446+
447+ private String truncate ( String original ) {
448+ if (original .length () <= MAX_DETAILS_COLUMN_WIDTH ){
449+ return original ;
450+ }
451+
452+ return original .substring ( 0 , MAX_DETAILS_COLUMN_WIDTH - 3 ) + "..." ;
453+ }
439454}
0 commit comments