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

Commit 4c66ff3

Browse files
Only render Indentifiers column if there is no Details column
1 parent 88f54d9 commit 4c66ff3

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
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;
@@ -213,8 +214,24 @@ public void cypherWithQueryDetails() throws CommandException {
213214

214215
//then
215216
String actual = linePrinter.output();
216-
assertThat( actual, containsString( "Details" ) );
217+
assertThat( actual, containsString( TablePlanFormatter.DETAILS ) );
217218
assertThat( actual, containsString( "n.age AS age" ) );
219+
assertThat( actual, not( containsString( TablePlanFormatter.IDENTIFIERS ) ) );
220+
}
221+
222+
@Test
223+
public void cypherWithoutQueryDetails() throws CommandException {
224+
// given
225+
String serverVersion = shell.getServerVersion();
226+
assumeTrue((minorVersion(serverVersion) == 0 && majorVersion(serverVersion) == 4) || majorVersion(serverVersion) < 4);
227+
228+
//when
229+
shell.execute("EXPLAIN MATCH (n) with n.age AS age RETURN age");
230+
231+
//then
232+
String actual = linePrinter.output();
233+
assertThat( actual, not( containsString( TablePlanFormatter.DETAILS ) ) );
234+
assertThat( actual, containsString( TablePlanFormatter.IDENTIFIERS ) );
218235
}
219236

220237
@Test

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

Lines changed: 4 additions & 3 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);
@@ -40,7 +40,7 @@ class TablePlanFormatter {
4040
private static final String MEMORY = "Memory (Bytes)";
4141
private static final String IDENTIFIERS = "Identifiers";
4242
private static final String OTHER = "Other";
43-
private static final String DETAILS = "Details";
43+
public static final String DETAILS = "Details";
4444
private static final String SEPARATOR = ", ";
4545
private static final Pattern DEDUP_PATTERN = Pattern.compile("\\s*(\\S+)@\\d+");
4646
public static final int MAX_DETAILS_COLUMN_WIDTH = 100;
@@ -81,7 +81,8 @@ String formatPlan(@Nonnull Plan plan) {
8181
Map<String, Integer> columns = new HashMap<>();
8282
List<Line> lines = accumulate(plan, new Root(), columns);
8383

84-
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());
8586

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

0 commit comments

Comments
 (0)