Skip to content

Commit

Permalink
Merge branch 'trinodb:master' into truera-main
Browse files Browse the repository at this point in the history
  • Loading branch information
reetika-roy authored Sep 13, 2023
2 parents 8ae2e7e + bd6a4dc commit 6665336
Show file tree
Hide file tree
Showing 3,571 changed files with 118,267 additions and 90,165 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/actions/update-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ runs:
steps:
- uses: actions/github-script@v6
id: update-check-run
if: always() && inputs.check_name != '' && inputs.conclusion != ''
if: inputs.check_name != '' && inputs.conclusion != ''
env:
number: ${{ inputs.pull_request_number }}
check_name: ${{ inputs.check_name }}
Expand Down
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<!-- Mark the appropriate option with an (x). Propose a release note if you can. -->
## Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

```markdown
Expand Down
211 changes: 94 additions & 117 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: 'temurin' # use same JDK distro as in Trino docker images
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
- ":trino-tests"
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # checkout all commits, as the build result depends on `git describe` equivalent
- uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/milestone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Get milestone from pom.xml
run: |
.github/bin/retry ./mvnw -v
Expand Down
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion .idea/icon.svg

This file was deleted.

6 changes: 6 additions & 0 deletions .mvn/modernizer/violations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<comment>Table type is nullable in Glue model, which is too easy to forget about. Prefer GlueToTrinoConverter.getTableType</comment>
</violation>

<violation>
<name>com/amazonaws/services/glue/model/Column.getParameters:()Ljava/util/Map;</name>
<version>1.1</version>
<comment>Column parameters map is nullable in Glue model, which is too easy to forget about. Prefer GlueToTrinoConverter.getColumnParameters</comment>
</violation>

<violation>
<name>com/amazonaws/services/glue/model/Table.getParameters:()Ljava/util/Map;</name>
<version>1.1</version>
Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
35 changes: 32 additions & 3 deletions client/trino-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<parent>
<groupId>io.trino</groupId>
<artifactId>trino-root</artifactId>
<version>422-SNAPSHOT</version>
<version>427-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>trino-cli</artifactId>
<name>trino-cli</name>

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
Expand Down Expand Up @@ -65,7 +64,7 @@

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-parser</artifactId>
<artifactId>trino-grammar</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -131,6 +130,18 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand All @@ -140,6 +151,24 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<!-- allow both JUnit and TestNG -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${dep.plugin.surefire.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
158 changes: 34 additions & 124 deletions client/trino-cli/src/main/java/io/trino/cli/AlignedTablePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,21 @@
*/
package io.trino.cli;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import io.trino.client.Column;
import io.trino.client.Row;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.repeat;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.partition;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.io.BaseEncoding.base16;
import static io.trino.cli.FormatUtils.formatValue;
import static io.trino.client.ClientStandardTypes.BIGINT;
import static io.trino.client.ClientStandardTypes.DECIMAL;
import static io.trino.client.ClientStandardTypes.DOUBLE;
Expand All @@ -43,7 +38,6 @@
import static java.lang.Math.max;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static org.jline.utils.AttributedString.stripAnsi;
import static org.jline.utils.WCWidth.wcwidth;

Expand All @@ -53,15 +47,12 @@ public class AlignedTablePrinter
private static final Set<String> NUMERIC_TYPES = ImmutableSet.of(TINYINT, SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, DECIMAL);

private static final Splitter LINE_SPLITTER = Splitter.on('\n');
private static final Splitter HEX_SPLITTER = Splitter.fixedLength(2);
private static final Joiner HEX_BYTE_JOINER = Joiner.on(' ');
private static final Joiner HEX_LINE_JOINER = Joiner.on('\n');

private final List<String> fieldNames;
private final List<Boolean> numericFields;
private final Writer writer;

private boolean headerOutput;
private boolean headerRendered;
private long rowCount;

public AlignedTablePrinter(List<Column> columns, Writer writer)
Expand Down Expand Up @@ -93,34 +84,34 @@ public void printRows(List<List<?>> rows, boolean complete)
rowCount += rows.size();
int columns = fieldNames.size();

int[] maxWidth = new int[columns];
int[] columnWidth = new int[columns];
for (int i = 0; i < columns; i++) {
maxWidth[i] = max(1, consoleWidth(fieldNames.get(i)));
columnWidth[i] = max(1, consoleWidth(fieldNames.get(i)));
}

for (List<?> row : rows) {
for (int i = 0; i < row.size(); i++) {
String s = formatValue(row.get(i));
maxWidth[i] = max(maxWidth[i], maxLineLength(s));
String value = formatValue(row.get(i));
columnWidth[i] = max(columnWidth[i], maxLineLength(value));
}
}

if (!headerOutput) {
headerOutput = true;
if (!headerRendered) {
headerRendered = true;

for (int i = 0; i < columns; i++) {
if (i > 0) {
writer.append('|');
}
String name = fieldNames.get(i);
writer.append(center(name, maxWidth[i], 1));
writer.append(center(fieldNames.get(i), columnWidth[i], 1));
}
writer.append('\n');

for (int i = 0; i < columns; i++) {
if (i > 0) {
writer.append('+');
}
writer.append(repeat("-", maxWidth[i] + 2));
writer.append(repeat("-", columnWidth[i] + 2));
}
writer.append('\n');
}
Expand All @@ -129,8 +120,8 @@ public void printRows(List<List<?>> rows, boolean complete)
List<List<String>> columnLines = new ArrayList<>(columns);
int maxLines = 1;
for (int i = 0; i < columns; i++) {
String s = formatValue(row.get(i));
ImmutableList<String> lines = ImmutableList.copyOf(LINE_SPLITTER.split(s));
String value = formatValue(row.get(i));
ImmutableList<String> lines = ImmutableList.copyOf(LINE_SPLITTER.split(value));
columnLines.add(lines);
maxLines = max(maxLines, lines.size());
}
Expand All @@ -141,9 +132,9 @@ public void printRows(List<List<?>> rows, boolean complete)
writer.append('|');
}
List<String> lines = columnLines.get(column);
String s = (line < lines.size()) ? lines.get(line) : "";
String value = (line < lines.size()) ? lines.get(line) : "";
boolean numeric = numericFields.get(column);
String out = align(s, maxWidth[column], 1, numeric);
String out = align(value, columnWidth[column], 1, numeric);
if ((!complete || (rowCount > 1)) && ((line + 1) < lines.size())) {
out = out.substring(0, out.length() - 1) + "+";
}
Expand All @@ -156,121 +147,40 @@ public void printRows(List<List<?>> rows, boolean complete)
writer.flush();
}

static String formatValue(Object o)
{
if (o == null) {
return "NULL";
}

if (o instanceof Map) {
return formatMap((Map<?, ?>) o);
}

if (o instanceof List) {
return formatList((List<?>) o);
}

if (o instanceof Row) {
return formatRow(((Row) o));
}

if (o instanceof byte[]) {
return formatHexDump((byte[]) o, 16);
}

return o.toString();
}

private static String formatHexDump(byte[] bytes, int bytesPerLine)
{
// hex pairs: ["61", "62", "63"]
Iterable<String> hexPairs = createHexPairs(bytes);

// hex lines: [["61", "62", "63], [...]]
Iterable<List<String>> hexLines = partition(hexPairs, bytesPerLine);

// lines: ["61 62 63", ...]
Iterable<String> lines = transform(hexLines, HEX_BYTE_JOINER::join);

// joined: "61 62 63\n..."
return HEX_LINE_JOINER.join(lines);
}

static String formatHexDump(byte[] bytes)
{
return HEX_BYTE_JOINER.join(createHexPairs(bytes));
}

private static Iterable<String> createHexPairs(byte[] bytes)
{
// hex dump: "616263"
String hexDump = base16().lowerCase().encode(bytes);

// hex pairs: ["61", "62", "63"]
return HEX_SPLITTER.split(hexDump);
}

static String formatList(List<? extends Object> list)
{
return list.stream()
.map(AlignedTablePrinter::formatValue)
.collect(joining(", ", "[", "]"));
}

static String formatMap(Map<? extends Object, ? extends Object> map)
{
return map.entrySet().stream()
.map(entry -> format("%s=%s", formatValue(entry.getKey()), formatValue(entry.getValue())))
.collect(joining(", ", "{", "}"));
}

static String formatRow(Row row)
{
return row.getFields().stream()
.map(field -> {
String formattedValue = formatValue(field.getValue());
if (field.getName().isPresent()) {
return format("%s=%s", formatValue(field.getName().get()), formattedValue);
}
return formattedValue;
})
.collect(joining(", ", "{", "}"));
}

private static String center(String s, int maxWidth, int padding)
private static String center(String value, int maxWidth, int padding)
{
int width = consoleWidth(s);
checkState(width <= maxWidth, "string width is greater than max width");
int width = consoleWidth(value);
checkState(width <= maxWidth, format("Variable width %d is greater than column width %d", width, maxWidth));
int left = (maxWidth - width) / 2;
int right = maxWidth - (left + width);
return repeat(" ", left + padding) + s + repeat(" ", right + padding);
return repeat(" ", left + padding) + value + repeat(" ", right + padding);
}

private static String align(String s, int maxWidth, int padding, boolean right)
private static String align(String value, int maxWidth, int padding, boolean right)
{
int width = consoleWidth(s);
checkState(width <= maxWidth, "string width is greater than max width");
String large = repeat(" ", (maxWidth - width) + padding);
int width = consoleWidth(value);
checkState(width <= maxWidth, format("Variable width %d is greater than column width %d", width, maxWidth));
String large = repeat(" ", maxWidth - width + padding);
String small = repeat(" ", padding);
return right ? (large + s + small) : (small + s + large);
return right ? (large + value + small) : (small + value + large);
}

static int maxLineLength(String s)
static int maxLineLength(String value)
{
int n = 0;
for (String line : LINE_SPLITTER.split(s)) {
n = max(n, consoleWidth(line));
int result = 0;
for (String line : LINE_SPLITTER.split(value)) {
result = max(result, consoleWidth(line));
}
return n;
return result;
}

static int consoleWidth(String s)
static int consoleWidth(String value)
{
CharSequence plain = stripAnsi(s);
int n = 0;
CharSequence plain = stripAnsi(value);
int result = 0;
for (int i = 0; i < plain.length(); i++) {
n += max(wcwidth(plain.charAt(i)), 0);
result += max(wcwidth(plain.charAt(i)), 0);
}
return n;
return result;
}
}
Loading

0 comments on commit 6665336

Please sign in to comment.