Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-21774][sql-client] Do not display column names when return set is emtpy in SQL Client #15213

Merged
merged 3 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[FLINK-21774][sql-client] Do not display column names when return set…
… is emtpy in SQL Client
  • Loading branch information
SteNicholas committed Mar 17, 2021
commit d236292f98ae9d87cc5f7d50160a830a3f34f30e
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ show user functions;
+---------------+
| function name |
+---------------+
| func4 |
| func3 |
| func4 |
+---------------+
2 rows in set
!ok
Expand Down Expand Up @@ -173,9 +173,9 @@ show user functions;
+---------------+
| function name |
+---------------+
| func4 |
| func11 |
| func3 |
| func4 |
+---------------+
3 rows in set
!ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,19 @@ public boolean dropTemporaryView(String path) {

@Override
public String[] listUserDefinedFunctions() {
return functionCatalog.getUserDefinedFunctions();
return sortFunctions(functionCatalog.getUserDefinedFunctions());
}

@Override
public String[] listFunctions() {
return functionCatalog.getFunctions();
return sortFunctions(functionCatalog.getFunctions());
SteNicholas marked this conversation as resolved.
Show resolved Hide resolved
}

private String[] sortFunctions(String[] functions) {
if (functions != null && functions.length > 0) {
Arrays.sort(functions);
}
return functions;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,37 @@ public static void printAsTableauForm(
String nullColumn,
boolean deriveColumnWidthByType,
boolean printRowKind) {
final List<TableColumn> columns = tableSchema.getTableColumns();
String[] columnNames = columns.stream().map(TableColumn::getName).toArray(String[]::new);
if (printRowKind) {
columnNames =
Stream.concat(Stream.of(ROW_KIND_COLUMN), Arrays.stream(columnNames))
.toArray(String[]::new);
}
if (it.hasNext()) {
SteNicholas marked this conversation as resolved.
Show resolved Hide resolved
final List<TableColumn> columns = tableSchema.getTableColumns();
String[] columnNames =
columns.stream().map(TableColumn::getName).toArray(String[]::new);
if (printRowKind) {
columnNames =
Stream.concat(Stream.of(ROW_KIND_COLUMN), Arrays.stream(columnNames))
.toArray(String[]::new);
}

final int[] colWidths;
if (deriveColumnWidthByType) {
colWidths =
columnWidthsByType(
columns,
maxColumnWidth,
nullColumn,
printRowKind ? ROW_KIND_COLUMN : null);
} else {
final List<Row> rows = new ArrayList<>();
final List<String[]> content = new ArrayList<>();
content.add(columnNames);
while (it.hasNext()) {
Row row = it.next();
rows.add(row);
content.add(rowToString(row, nullColumn, printRowKind));
final int[] colWidths;
if (deriveColumnWidthByType) {
colWidths =
columnWidthsByType(
columns,
maxColumnWidth,
nullColumn,
printRowKind ? ROW_KIND_COLUMN : null);
} else {
final List<Row> rows = new ArrayList<>();
final List<String[]> content = new ArrayList<>();
content.add(columnNames);
while (it.hasNext()) {
Row row = it.next();
rows.add(row);
content.add(rowToString(row, nullColumn, printRowKind));
}
colWidths = columnWidthsByContent(columnNames, content, maxColumnWidth);
it = rows.iterator();
}
colWidths = columnWidthsByContent(columnNames, content, maxColumnWidth);
it = rows.iterator();
}

if (it.hasNext()) {
final String borderline = PrintUtils.genBorderLine(colWidths);
// print border line
printWriter.println(borderline);
Expand Down