Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ public static void main(String[] args)
.setSecurity(ALLOW_ALL)
// Uncomment to enable standard column naming (column names to be prefixed with the first letter of the table name, e.g.: o_orderkey vs orderkey)
// and standard column types (decimals vs double for some columns). This will allow running unmodified tpch queries on the cluster.
// .setTpchColumnNaming(STANDARD)
// .setTpchDecimalTypeMapping(DECIMAL)
//.setTpchColumnNaming(ColumnNaming.STANDARD)
//.setTpchDecimalTypeMapping(DecimalTypeMapping.DECIMAL)
.build();
Thread.sleep(10);
log.info("======== SERVER STARTED ========");
Expand Down
12 changes: 6 additions & 6 deletions service/trino-verifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ CREATE TABLE verifier_queries(
name VARCHAR(256),
test_catalog VARCHAR(256) NOT NULL,
test_schema VARCHAR(256) NOT NULL,
test_prequeries TEXT,
test_query TEXT NOT NULL,
test_postqueries TEXT,
test_prequeries MEDIUMTEXT,
test_query MEDIUMTEXT NOT NULL,
test_postqueries MEDIUMTEXT,
test_username VARCHAR(256) NOT NULL default 'verifier-test',
test_password VARCHAR(256),
test_session_properties_json VARCHAR(2048),
control_catalog VARCHAR(256) NOT NULL,
control_schema VARCHAR(256) NOT NULL,
control_prequeries TEXT,
control_query TEXT NOT NULL,
control_postqueries TEXT,
control_prequeries MEDIUMTEXT,
control_query MEDIUMTEXT NOT NULL,
control_postqueries MEDIUMTEXT,
control_username VARCHAR(256) NOT NULL default 'verifier-test',
control_password VARCHAR(256),
control_session_properties_json VARCHAR(2048),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import io.airlift.event.client.AbstractEventClient;
import io.airlift.json.JsonCodec;

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import java.util.List;
import java.util.Optional;
import java.util.OptionalDouble;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -58,12 +60,24 @@ protected <T> void postEvent(T event)
queryEvent.getTestSetupQueryIds().isEmpty() ? Optional.empty() : Optional.of(codec.toJson(queryEvent.getTestSetupQueryIds())),
Optional.ofNullable(queryEvent.getTestQueryId()),
queryEvent.getTestTeardownQueryIds().isEmpty() ? Optional.empty() : Optional.of(codec.toJson(queryEvent.getTestTeardownQueryIds())),
toOptionalDouble(queryEvent.getTestCpuTimeSecs()),
toOptionalDouble(queryEvent.getTestWallTimeSecs()),
Optional.ofNullable(queryEvent.getControlCatalog()),
Optional.ofNullable(queryEvent.getControlSchema()),
queryEvent.getControlSetupQueryIds().isEmpty() ? Optional.empty() : Optional.of(codec.toJson(queryEvent.getControlSetupQueryIds())),
Optional.ofNullable(queryEvent.getControlQueryId()),
queryEvent.getControlTeardownQueryIds().isEmpty() ? Optional.empty() : Optional.of(codec.toJson(queryEvent.getControlTeardownQueryIds())),
toOptionalDouble(queryEvent.getControlCpuTimeSecs()),
toOptionalDouble(queryEvent.getControlWallTimeSecs()),
Optional.ofNullable(queryEvent.getErrorMessage()));
dao.store(entity);
}

private static OptionalDouble toOptionalDouble(@Nullable Double value)
{
if (value == null) {
return OptionalDouble.empty();
}
return OptionalDouble.of(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ public enum State
private final Duration wallTime;
private final Duration cpuTime;
private final String queryId;
private final List<String> columnTypes;
private final List<List<Object>> results;

public QueryResult(State state, Exception exception, Duration wallTime, Duration cpuTime, String queryId, List<List<Object>> results)
public QueryResult(State state, Exception exception, Duration wallTime, Duration cpuTime, String queryId, List<String> columnTypes, List<List<Object>> results)
{
this.state = requireNonNull(state, "state is null");
this.exception = exception;
this.wallTime = wallTime;
this.cpuTime = cpuTime;
this.queryId = queryId;
this.columnTypes = ImmutableList.copyOf(columnTypes);
this.results = (results != null) ? ImmutableList.copyOf(results) : null;
}

Expand Down Expand Up @@ -71,6 +73,11 @@ public String getQueryId()
return queryId;
}

public List<String> getColumnTypes()
{
return columnTypes;
}

public List<List<Object>> getResults()
{
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -217,20 +218,20 @@ private boolean validate()
boolean tearDownTest = false;
try {
if (skipControl) {
controlResult = new QueryResult(State.SKIPPED, null, null, null, null, ImmutableList.of());
controlResult = new QueryResult(State.SKIPPED, null, null, null, null, ImmutableList.of(), ImmutableList.of());
}
else {
controlResult = executePreAndMainForControl();
}

// query has too many rows. Consider banning it.
if (controlResult.getState() == State.TOO_MANY_ROWS) {
testResult = new QueryResult(State.INVALID, null, null, null, null, ImmutableList.of());
testResult = new QueryResult(State.INVALID, null, null, null, null, ImmutableList.of(), ImmutableList.of());
return false;
}
// query failed in the control
if (!skipControl && controlResult.getState() != State.SUCCESS) {
testResult = new QueryResult(State.INVALID, null, null, null, null, ImmutableList.of());
testResult = new QueryResult(State.INVALID, null, null, null, null, ImmutableList.of(), ImmutableList.of());
return true;
}

Expand Down Expand Up @@ -304,11 +305,11 @@ private QueryResult tearDown(Query query, List<QueryResult> postQueryResults, Fu
QueryResult queryResult = executor.apply(postqueryString);
postQueryResults.add(queryResult);
if (queryResult.getState() != State.SUCCESS) {
return new QueryResult(State.FAILED_TO_TEARDOWN, queryResult.getException(), queryResult.getWallTime(), queryResult.getCpuTime(), queryResult.getQueryId(), ImmutableList.of());
return new QueryResult(State.FAILED_TO_TEARDOWN, queryResult.getException(), queryResult.getWallTime(), queryResult.getCpuTime(), queryResult.getQueryId(), ImmutableList.of(), ImmutableList.of());
}
}

return new QueryResult(State.SUCCESS, null, null, null, null, ImmutableList.of());
return new QueryResult(State.SUCCESS, null, null, null, null, ImmutableList.of(), ImmutableList.of());
}

private static QueryResult setup(Query query, List<QueryResult> preQueryResults, Function<String, QueryResult> executor)
Expand All @@ -321,11 +322,11 @@ private static QueryResult setup(Query query, List<QueryResult> preQueryResults,
return queryResult;
}
else if (queryResult.getState() != State.SUCCESS) {
return new QueryResult(State.FAILED_TO_SETUP, queryResult.getException(), queryResult.getWallTime(), queryResult.getCpuTime(), queryResult.getQueryId(), ImmutableList.of());
return new QueryResult(State.FAILED_TO_SETUP, queryResult.getException(), queryResult.getWallTime(), queryResult.getCpuTime(), queryResult.getQueryId(), ImmutableList.of(), ImmutableList.of());
}
}

return new QueryResult(State.SUCCESS, null, null, null, null, ImmutableList.of());
return new QueryResult(State.SUCCESS, null, null, null, null, ImmutableList.of(), ImmutableList.of());
}

private boolean checkForDeterministicAndRerunTestQueriesIfNeeded()
Expand Down Expand Up @@ -500,6 +501,7 @@ private QueryResult executeQuery(String url, String username, String password, Q

ProgressMonitor progressMonitor = new ProgressMonitor();
List<List<Object>> results;
List<String> columnTypes;
try (Statement statement = connection.createStatement()) {
Stopwatch stopwatch = Stopwatch.createStarted();
Statement limitedStatement = limiter.newProxy(statement, Statement.class, timeout.toMillis(), MILLISECONDS);
Expand All @@ -517,10 +519,13 @@ private QueryResult executeQuery(String url, String username, String password, Q
ResultSetConverter.class,
timeout.toMillis() - stopwatch.elapsed(MILLISECONDS),
MILLISECONDS);
results = converter.convert(limitedStatement.getResultSet());
ResultSet resultSet = limitedStatement.getResultSet();
results = converter.convert(resultSet);
columnTypes = getColumnTypes(resultSet);
}
else {
results = ImmutableList.of(ImmutableList.of(limitedStatement.getLargeUpdateCount()));
columnTypes = ImmutableList.of("BIGINT");
}

trinoStatement.clearProgressMonitor();
Expand All @@ -536,7 +541,7 @@ private QueryResult executeQuery(String url, String username, String password, Q
}
}

return new QueryResult(State.SUCCESS, null, nanosSince(start), queryCpuTime, queryId, results);
return new QueryResult(State.SUCCESS, null, nanosSince(start), queryCpuTime, queryId, columnTypes, results);
}
catch (SQLException e) {
Exception exception = e;
Expand All @@ -545,13 +550,13 @@ private QueryResult executeQuery(String url, String username, String password, Q
exception = (Exception) e.getCause();
}
State state = isPrestoQueryInvalid(e) ? State.INVALID : State.FAILED;
return new QueryResult(state, exception, nanosSince(start), queryCpuTime, queryId, ImmutableList.of());
return new QueryResult(state, exception, nanosSince(start), queryCpuTime, queryId, ImmutableList.of(), ImmutableList.of());
}
catch (VerifierException e) {
return new QueryResult(State.TOO_MANY_ROWS, e, nanosSince(start), queryCpuTime, queryId, ImmutableList.of());
return new QueryResult(State.TOO_MANY_ROWS, e, nanosSince(start), queryCpuTime, queryId, ImmutableList.of(), ImmutableList.of());
}
catch (UncheckedTimeoutException e) {
return new QueryResult(State.TIMEOUT, e, nanosSince(start), queryCpuTime, queryId, ImmutableList.of());
return new QueryResult(State.TIMEOUT, e, nanosSince(start), queryCpuTime, queryId, ImmutableList.of(), ImmutableList.of());
}
finally {
executor.shutdownNow();
Expand Down Expand Up @@ -600,14 +605,6 @@ private List<List<Object>> convertJdbcResultSet(ResultSet resultSet)
List<Object> row = new ArrayList<>();
for (int i = 1; i <= columnCount; i++) {
Object object = resultSet.getObject(i);
if (object instanceof BigDecimal) {
if (((BigDecimal) object).scale() <= 0) {
object = ((BigDecimal) object).longValueExact();
}
else {
object = ((BigDecimal) object).doubleValue();
}
}
if (object instanceof Array) {
object = ((Array) object).getArray();
}
Expand Down Expand Up @@ -704,12 +701,16 @@ private static Comparator<Object> columnComparator(int precision)
Number y = (Number) b;
boolean bothReal = isReal(x) && isReal(y);
boolean bothIntegral = isIntegral(x) && isIntegral(y);
if (!(bothReal || bothIntegral)) {
boolean bothDecimals = isDecimal(x) && isDecimal(y);
if (!(bothReal || bothIntegral || bothDecimals)) {
throw new TypesDoNotMatchException(format("item types do not match: %s vs %s", a.getClass().getName(), b.getClass().getName()));
}
if (isIntegral(x)) {
return Long.compare(x.longValue(), y.longValue());
}
if (isDecimal(x)) {
return ((BigDecimal) x).compareTo((BigDecimal) y);
}
return precisionCompare(x.doubleValue(), y.doubleValue(), precision);
}
if (a.getClass() != b.getClass()) {
Expand Down Expand Up @@ -790,6 +791,11 @@ private static boolean isIntegral(Number x)
return x instanceof Byte || x instanceof Short || x instanceof Integer || x instanceof Long;
}

private static boolean isDecimal(Number x)
{
return x instanceof BigDecimal;
}

//adapted from http://floating-point-gui.de/errors/comparison/
private static boolean isClose(double a, double b, double epsilon)
{
Expand Down Expand Up @@ -819,6 +825,17 @@ static int precisionCompare(double a, double b, int precision)
return isClose(a, b, Math.pow(10, -1 * (precision - 1))) ? 0 : -1;
}

private static List<String> getColumnTypes(ResultSet resultSet)
throws SQLException
{
ResultSetMetaData metadata = resultSet.getMetaData();
ImmutableList.Builder<String> builder = ImmutableList.builder();
for (int column = 1; column <= metadata.getColumnCount(); column++) {
builder.add(metadata.getColumnTypeName(column));
}
return builder.build();
}

public static class ChangedRow
implements Comparable<ChangedRow>
{
Expand Down
Loading