Skip to content

Commit

Permalink
[FLINK-22245][sql-client] Use PrintUtils.MAX_COLUMN_WIDTH as default …
Browse files Browse the repository at this point in the history
…max column width in client result views

This closes apache#15580
  • Loading branch information
fsk119 committed Apr 14, 2021
1 parent dd71937 commit a66487d
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected int computeColumnWidth(int idx) {
if (idx == 0) {
return 3;
} else {
return MAX_COLUMN_WIDTH;
return PrintUtils.MAX_COLUMN_WIDTH;
}
}

Expand Down Expand Up @@ -284,7 +284,7 @@ protected List<AttributedString> computeMainHeaderLines() {
s -> {
schemaHeader.append(' ');
schemaHeader.style(AttributedStyle.DEFAULT.underline());
normalizeColumn(schemaHeader, s, MAX_COLUMN_WIDTH);
normalizeColumn(schemaHeader, s, PrintUtils.MAX_COLUMN_WIDTH);
schemaHeader.style(AttributedStyle.DEFAULT);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
/** Abstract CLI view for showing results (either as changelog or table). */
public abstract class CliResultView<O extends Enum<O>> extends CliView<O, Void> {

protected static final int MAX_COLUMN_WIDTH = 25;

protected static final int NO_ROW_SELECTED = -1;

protected static final List<Tuple2<String, Long>> REFRESH_INTERVALS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected String[] getRow(String[] resultRow) {

@Override
protected int computeColumnWidth(int idx) {
return MAX_COLUMN_WIDTH;
return PrintUtils.MAX_COLUMN_WIDTH;
}

@Override
Expand Down Expand Up @@ -271,7 +271,7 @@ protected List<AttributedString> computeMainHeaderLines() {
s -> {
schemaHeader.append(' ');
schemaHeader.style(AttributedStyle.DEFAULT.underline());
normalizeColumn(schemaHeader, s, MAX_COLUMN_WIDTH);
normalizeColumn(schemaHeader, s, PrintUtils.MAX_COLUMN_WIDTH);
schemaHeader.style(AttributedStyle.DEFAULT);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
/** Print result in tableau mode. */
public class CliTableauResultView implements AutoCloseable {

private static final int DEFAULT_COLUMN_WIDTH = 20;

private final Terminal terminal;
private final Executor sqlExecutor;
private final String sessionId;
Expand Down Expand Up @@ -129,14 +127,14 @@ private void printResults(AtomicInteger receivedRowCount, boolean isStreamingMod
colWidths =
PrintUtils.columnWidthsByType(
columns,
DEFAULT_COLUMN_WIDTH,
PrintUtils.MAX_COLUMN_WIDTH,
PrintUtils.NULL_COLUMN,
PrintUtils.ROW_KIND_COLUMN);
} else {
fieldNames = columns.stream().map(Column::getName).toArray(String[]::new);
colWidths =
PrintUtils.columnWidthsByType(
columns, DEFAULT_COLUMN_WIDTH, PrintUtils.NULL_COLUMN, null);
columns, PrintUtils.MAX_COLUMN_WIDTH, PrintUtils.NULL_COLUMN, null);
}

String borderline = PrintUtils.genBorderLine(colWidths);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ SET sql-client.execution.result-mode = tableau;

# test the SELECT query can run successfully, even result is empty
select * from hivecatalog.`default`.param_types_table;
+--------------+----------------------+----------------------+
| dec | ch | vch |
+--------------+----------------------+----------------------+
+--------------+--------------------------------+--------------------------------+
| dec | ch | vch |
+--------------+--------------------------------+--------------------------------+
Received a total of 0 row
!ok

Expand Down
12 changes: 6 additions & 6 deletions flink-table/flink-sql-client/src/test/resources/sql/function.q
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ SET sql-client.execution.result-mode=tableau;

# run a query to verify the registered UDF works
SELECT id, func1(str) FROM (VALUES (1, 'Hello World'), (2, 'Hi')) as T(id, str);
+----+-------------+----------------------+
| op | id | EXPR$1 |
+----+-------------+----------------------+
| +I | 1 | hello world |
| +I | 2 | hi |
+----+-------------+----------------------+
+----+-------------+--------------------------------+
| op | id | EXPR$1 |
+----+-------------+--------------------------------+
| +I | 1 | hello world |
| +I | 2 | hi |
+----+-------------+--------------------------------+
Received a total of 2 rows
!ok

Expand Down
44 changes: 22 additions & 22 deletions flink-table/flink-sql-client/src/test/resources/sql/insert.q
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ INSERT INTO StreamingTable SELECT * FROM (VALUES (1, 'Hello World'), (2, 'Hi'),
!info

SELECT * FROM StreamingTable;
+----+-------------+----------------------+
| op | id | str |
+----+-------------+----------------------+
| +I | 1 | Hello World |
| +I | 2 | Hi |
| +I | 2 | Hi |
| +I | 3 | Hello |
| +I | 3 | World |
| +I | 4 | ADD |
| +I | 5 | LINE |
+----+-------------+----------------------+
+----+-------------+--------------------------------+
| op | id | str |
+----+-------------+--------------------------------+
| +I | 1 | Hello World |
| +I | 2 | Hi |
| +I | 2 | Hi |
| +I | 3 | Hello |
| +I | 3 | World |
| +I | 4 | ADD |
| +I | 5 | LINE |
+----+-------------+--------------------------------+
Received a total of 7 rows
!ok

Expand Down Expand Up @@ -89,16 +89,16 @@ INSERT INTO BatchTable SELECT * FROM (VALUES (1, 'Hello World'), (2, 'Hi'), (2,
!info

SELECT * FROM BatchTable;
+-------------+----------------------+
| id | str |
+-------------+----------------------+
| 1 | Hello World |
| 2 | Hi |
| 2 | Hi |
| 3 | Hello |
| 3 | World |
| 4 | ADD |
| 5 | LINE |
+-------------+----------------------+
+-------------+--------------------------------+
| id | str |
+-------------+--------------------------------+
| 1 | Hello World |
| 2 | Hi |
| 2 | Hi |
| 3 | Hello |
| 3 | World |
| 4 | ADD |
| 5 | LINE |
+-------------+--------------------------------+
Received a total of 7 rows
!ok
10 changes: 5 additions & 5 deletions flink-table/flink-sql-client/src/test/resources/sql/module.q
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ SHOW FULL MODULES;

# use hive built-in function after loading hive module
SELECT SUBSTRING_INDEX('www.apache.org', '.', 2) FROM (VALUES (1, 'Hello World')) AS T(id, str);
+----+----------------------+
| op | EXPR$0 |
+----+----------------------+
| +I | www.apache |
+----+----------------------+
+----+--------------------------------+
| op | EXPR$0 |
+----+--------------------------------+
| +I | www.apache |
+----+--------------------------------+
Received a total of 1 row
!ok

Expand Down
23 changes: 13 additions & 10 deletions flink-table/flink-sql-client/src/test/resources/sql/select.q
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ java.lang.IllegalArgumentException: testing elements of values source shouldn't
# (we can't test changelog mode and table mode in IT case)
# ==========================================================================

SELECT id, COUNT(*) as cnt, COUNT(DISTINCT str) as uv
FROM (VALUES (1, 'Hello World'), (2, 'Hi'), (2, 'Hi')) as T(id, str)
SELECT id, COUNT(*) as cnt, COUNT(DISTINCT str) as uv, max(ts) as max_ts
FROM (VALUES
(1, 'Hello World', TIMESTAMP '2021-04-13 20:12:11.123456789'),
(2, 'Hi', TIMESTAMP '2021-04-13 19:12:11.123456789'),
(2, 'Hi', TIMESTAMP '2021-04-13 21:12:11.123456789')) as T(id, str, ts)
GROUP BY id;
+----+-------------+----------------------+----------------------+
| op | id | cnt | uv |
+----+-------------+----------------------+----------------------+
| +I | 1 | 1 | 1 |
| +I | 2 | 1 | 1 |
| -U | 2 | 1 | 1 |
| +U | 2 | 2 | 1 |
+----+-------------+----------------------+----------------------+
+----+-------------+----------------------+----------------------+-------------------------------+
| op | id | cnt | uv | max_ts |
+----+-------------+----------------------+----------------------+-------------------------------+
| +I | 1 | 1 | 1 | 2021-04-13T20:12:11.123456789 |
| +I | 2 | 1 | 1 | 2021-04-13T19:12:11.123456789 |
| -U | 2 | 1 | 1 | 2021-04-13T19:12:11.123456789 |
| +U | 2 | 2 | 1 | 2021-04-13T21:12:11.123456789 |
+----+-------------+----------------------+----------------------+-------------------------------+
Received a total of 4 rows
!ok

Expand Down
44 changes: 22 additions & 22 deletions flink-table/flink-sql-client/src/test/resources/sql/statement_set.q
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ org.apache.flink.table.client.gateway.SqlExecutionException: No Statement Set to
!error

SELECT * FROM StreamingTable;
+----+-------------+----------------------+
| op | id | str |
+----+-------------+----------------------+
| +I | 1 | Hello World |
| +I | 2 | Hi |
| +I | 2 | Hi |
| +I | 3 | Hello |
| +I | 3 | World |
| +I | 4 | ADD |
| +I | 5 | LINE |
+----+-------------+----------------------+
+----+-------------+--------------------------------+
| op | id | str |
+----+-------------+--------------------------------+
| +I | 1 | Hello World |
| +I | 2 | Hi |
| +I | 2 | Hi |
| +I | 3 | Hello |
| +I | 3 | World |
| +I | 4 | ADD |
| +I | 5 | LINE |
+----+-------------+--------------------------------+
Received a total of 7 rows
!ok

Expand Down Expand Up @@ -144,17 +144,17 @@ END;
!info

SELECT * FROM BatchTable;
+-------------+----------------------+
| id | str |
+-------------+----------------------+
| 1 | Hello World |
| 2 | Hi |
| 2 | Hi |
| 3 | Hello |
| 3 | World |
| 4 | ADD |
| 5 | LINE |
+-------------+----------------------+
+-------------+--------------------------------+
| id | str |
+-------------+--------------------------------+
| 1 | Hello World |
| 2 | Hi |
| 2 | Hi |
| 3 | Hello |
| 3 | World |
| 4 | ADD |
| 5 | LINE |
+-------------+--------------------------------+
Received a total of 7 rows
!ok

Expand Down

0 comments on commit a66487d

Please sign in to comment.