Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 01073ed

Browse files
Only render Indentifiers column if there is no Details column
1 parent 9e66a84 commit 01073ed

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellVerboseIntegrationTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.neo4j.shell.cli.Format;
1414
import org.neo4j.shell.exception.CommandException;
1515
import org.neo4j.shell.prettyprint.PrettyConfig;
16+
import org.neo4j.shell.prettyprint.TablePlanFormatter;
1617

1718
import static org.hamcrest.CoreMatchers.containsString;
1819
import static org.hamcrest.CoreMatchers.equalTo;
@@ -217,8 +218,24 @@ public void cypherWithQueryDetails() throws CommandException {
217218

218219
//then
219220
String actual = linePrinter.output();
220-
assertThat( actual, containsString( "Details" ) );
221+
assertThat( actual, containsString( TablePlanFormatter.DETAILS ) );
221222
assertThat( actual, containsString( "n.age AS age" ) );
223+
assertThat( actual, not( containsString( TablePlanFormatter.IDENTIFIERS ) ) );
224+
}
225+
226+
@Test
227+
public void cypherWithoutQueryDetails() throws CommandException {
228+
// given
229+
String serverVersion = shell.getServerVersion();
230+
assumeTrue((minorVersion(serverVersion) == 0 && majorVersion(serverVersion) == 4) || majorVersion(serverVersion) < 4);
231+
232+
//when
233+
shell.execute("EXPLAIN MATCH (n) with n.age AS age RETURN age");
234+
235+
//then
236+
String actual = linePrinter.output();
237+
assertThat( actual, not( containsString( TablePlanFormatter.DETAILS ) ) );
238+
assertThat( actual, containsString( TablePlanFormatter.IDENTIFIERS ) );
222239
}
223240

224241
@Test

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/TablePlanFormatter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static org.neo4j.shell.prettyprint.OutputFormatter.NEWLINE;
2727
import static org.neo4j.shell.prettyprint.OutputFormatter.repeat;
2828

29-
class TablePlanFormatter {
29+
public class TablePlanFormatter {
3030

3131
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);
@@ -37,9 +37,9 @@ 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-
private static final String DETAILS = "Details";
42+
public static final String DETAILS = "Details";
4343
private static final String SEPARATOR = ", ";
4444
private static final Pattern DEDUP_PATTERN = Pattern.compile("\\s*(\\S+)@\\d+");
4545
public static final int MAX_DETAILS_COLUMN_WIDTH = 100;
@@ -80,7 +80,8 @@ String formatPlan(@Nonnull Plan plan) {
8080
Map<String, Integer> columns = new HashMap<>();
8181
List<Line> lines = accumulate(plan, new Root(), columns);
8282

83-
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());
8485

8586
StringBuilder result = new StringBuilder((2 + NEWLINE.length() + headers.stream().mapToInt(h -> width(h, columns)).sum()) * (lines.size() * 2 + 3));
8687

0 commit comments

Comments
 (0)