@Test public void withNoDetails() { Plan plan = mock(Plan.class); Map<String, Value> args = Collections.singletonMap( "EstimatedRows", new FloatValue(55)); when(plan.arguments()).thenReturn(args); when(plan.operatorType()).thenReturn("Projection"); assertThat(tablePlanFormatter.formatPlan( plan ), is(String.join(NEWLINE, "+-------------+----------------+", "| Operator | Estimated Rows |", "+-------------+----------------+", "| +Projection | 55 |", "+-------------+----------------+", ""))); }
@Nonnull String formatPlan(@Nonnull Plan plan) { Map<String, Integer> columns = new HashMap<>(); List<TableRow> tableRows = accumulate(plan, new Root(), columns); List<String> headers = HEADERS.stream().filter(header -> columns.containsKey(header) && !(header.equals(IDENTIFIERS) && columns.containsKey(DETAILS))).collect(Collectors.toList()); StringBuilder result = new StringBuilder((2 + NEWLINE.length() + headers.stream().mapToInt(h -> width(h, columns)).sum()) * (tableRows.size() * 2 + 3)); List<TableRow> allTableRows = new ArrayList<>(); Map<String,Cell> headerMap = headers.stream().map(header -> Pair.of(header, new LeftJustifiedCell(header))).collect(toMap(p -> p._1, p -> p._2)); allTableRows.add(new TableRow(OPERATOR, headerMap, Optional.empty())); allTableRows.addAll( tableRows ); for (int rowIndex = 0; rowIndex < allTableRows.size(); rowIndex++) { TableRow tableRow = allTableRows.get( rowIndex); divider(headers, tableRow, result, columns); for (int rowLineIndex = 0; rowLineIndex < tableRow.height; rowLineIndex++) { for (String header : headers) { Cell cell = tableRow.get(header); String defaultText = ""; if (header.equals(OPERATOR) && rowIndex + 1 < allTableRows.size()) { defaultText = allTableRows.get(rowIndex + 1).connection.orElse("").replace('\\', ' '); } result.append( "| " ); int columnWidth = width(header, columns); cell.writePaddedLine(rowLineIndex, defaultText, columnWidth, result); result.append( " " ); } result.append("|").append(NEWLINE); } } divider(headers, null, result, columns); return result.toString(); }
TablePlanFormatter { @Nonnull String formatPlan(@Nonnull Plan plan) { Map<String, Integer> columns = new HashMap<>(); List<TableRow> tableRows = accumulate(plan, new Root(), columns); List<String> headers = HEADERS.stream().filter(header -> columns.containsKey(header) && !(header.equals(IDENTIFIERS) && columns.containsKey(DETAILS))).collect(Collectors.toList()); StringBuilder result = new StringBuilder((2 + NEWLINE.length() + headers.stream().mapToInt(h -> width(h, columns)).sum()) * (tableRows.size() * 2 + 3)); List<TableRow> allTableRows = new ArrayList<>(); Map<String,Cell> headerMap = headers.stream().map(header -> Pair.of(header, new LeftJustifiedCell(header))).collect(toMap(p -> p._1, p -> p._2)); allTableRows.add(new TableRow(OPERATOR, headerMap, Optional.empty())); allTableRows.addAll( tableRows ); for (int rowIndex = 0; rowIndex < allTableRows.size(); rowIndex++) { TableRow tableRow = allTableRows.get( rowIndex); divider(headers, tableRow, result, columns); for (int rowLineIndex = 0; rowLineIndex < tableRow.height; rowLineIndex++) { for (String header : headers) { Cell cell = tableRow.get(header); String defaultText = ""; if (header.equals(OPERATOR) && rowIndex + 1 < allTableRows.size()) { defaultText = allTableRows.get(rowIndex + 1).connection.orElse("").replace('\\', ' '); } result.append( "| " ); int columnWidth = width(header, columns); cell.writePaddedLine(rowLineIndex, defaultText, columnWidth, result); result.append( " " ); } result.append("|").append(NEWLINE); } } divider(headers, null, result, columns); return result.toString(); } }
TablePlanFormatter { @Nonnull String formatPlan(@Nonnull Plan plan) { Map<String, Integer> columns = new HashMap<>(); List<TableRow> tableRows = accumulate(plan, new Root(), columns); List<String> headers = HEADERS.stream().filter(header -> columns.containsKey(header) && !(header.equals(IDENTIFIERS) && columns.containsKey(DETAILS))).collect(Collectors.toList()); StringBuilder result = new StringBuilder((2 + NEWLINE.length() + headers.stream().mapToInt(h -> width(h, columns)).sum()) * (tableRows.size() * 2 + 3)); List<TableRow> allTableRows = new ArrayList<>(); Map<String,Cell> headerMap = headers.stream().map(header -> Pair.of(header, new LeftJustifiedCell(header))).collect(toMap(p -> p._1, p -> p._2)); allTableRows.add(new TableRow(OPERATOR, headerMap, Optional.empty())); allTableRows.addAll( tableRows ); for (int rowIndex = 0; rowIndex < allTableRows.size(); rowIndex++) { TableRow tableRow = allTableRows.get( rowIndex); divider(headers, tableRow, result, columns); for (int rowLineIndex = 0; rowLineIndex < tableRow.height; rowLineIndex++) { for (String header : headers) { Cell cell = tableRow.get(header); String defaultText = ""; if (header.equals(OPERATOR) && rowIndex + 1 < allTableRows.size()) { defaultText = allTableRows.get(rowIndex + 1).connection.orElse("").replace('\\', ' '); } result.append( "| " ); int columnWidth = width(header, columns); cell.writePaddedLine(rowLineIndex, defaultText, columnWidth, result); result.append( " " ); } result.append("|").append(NEWLINE); } } divider(headers, null, result, columns); return result.toString(); }  }
TablePlanFormatter { @Nonnull String formatPlan(@Nonnull Plan plan) { Map<String, Integer> columns = new HashMap<>(); List<TableRow> tableRows = accumulate(plan, new Root(), columns); List<String> headers = HEADERS.stream().filter(header -> columns.containsKey(header) && !(header.equals(IDENTIFIERS) && columns.containsKey(DETAILS))).collect(Collectors.toList()); StringBuilder result = new StringBuilder((2 + NEWLINE.length() + headers.stream().mapToInt(h -> width(h, columns)).sum()) * (tableRows.size() * 2 + 3)); List<TableRow> allTableRows = new ArrayList<>(); Map<String,Cell> headerMap = headers.stream().map(header -> Pair.of(header, new LeftJustifiedCell(header))).collect(toMap(p -> p._1, p -> p._2)); allTableRows.add(new TableRow(OPERATOR, headerMap, Optional.empty())); allTableRows.addAll( tableRows ); for (int rowIndex = 0; rowIndex < allTableRows.size(); rowIndex++) { TableRow tableRow = allTableRows.get( rowIndex); divider(headers, tableRow, result, columns); for (int rowLineIndex = 0; rowLineIndex < tableRow.height; rowLineIndex++) { for (String header : headers) { Cell cell = tableRow.get(header); String defaultText = ""; if (header.equals(OPERATOR) && rowIndex + 1 < allTableRows.size()) { defaultText = allTableRows.get(rowIndex + 1).connection.orElse("").replace('\\', ' '); } result.append( "| " ); int columnWidth = width(header, columns); cell.writePaddedLine(rowLineIndex, defaultText, columnWidth, result); result.append( " " ); } result.append("|").append(NEWLINE); } } divider(headers, null, result, columns); return result.toString(); }   }
TablePlanFormatter { @Nonnull String formatPlan(@Nonnull Plan plan) { Map<String, Integer> columns = new HashMap<>(); List<TableRow> tableRows = accumulate(plan, new Root(), columns); List<String> headers = HEADERS.stream().filter(header -> columns.containsKey(header) && !(header.equals(IDENTIFIERS) && columns.containsKey(DETAILS))).collect(Collectors.toList()); StringBuilder result = new StringBuilder((2 + NEWLINE.length() + headers.stream().mapToInt(h -> width(h, columns)).sum()) * (tableRows.size() * 2 + 3)); List<TableRow> allTableRows = new ArrayList<>(); Map<String,Cell> headerMap = headers.stream().map(header -> Pair.of(header, new LeftJustifiedCell(header))).collect(toMap(p -> p._1, p -> p._2)); allTableRows.add(new TableRow(OPERATOR, headerMap, Optional.empty())); allTableRows.addAll( tableRows ); for (int rowIndex = 0; rowIndex < allTableRows.size(); rowIndex++) { TableRow tableRow = allTableRows.get( rowIndex); divider(headers, tableRow, result, columns); for (int rowLineIndex = 0; rowLineIndex < tableRow.height; rowLineIndex++) { for (String header : headers) { Cell cell = tableRow.get(header); String defaultText = ""; if (header.equals(OPERATOR) && rowIndex + 1 < allTableRows.size()) { defaultText = allTableRows.get(rowIndex + 1).connection.orElse("").replace('\\', ' '); } result.append( "| " ); int columnWidth = width(header, columns); cell.writePaddedLine(rowLineIndex, defaultText, columnWidth, result); result.append( " " ); } result.append("|").append(NEWLINE); } } divider(headers, null, result, columns); return result.toString(); }   static final String IDENTIFIERS; static final String DETAILS; static final int MAX_DETAILS_COLUMN_WIDTH; static final Value ZERO_VALUE; }