diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java index d9940de4573..64e49723a6e 100644 --- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java +++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryIT.java @@ -55,15 +55,15 @@ public class TrinoQueryIT extends TrinoQueryITBase { private static final Logger LOG = LoggerFactory.getLogger(TrinoQueryIT.class); - static String testsetsDir = ""; - AtomicInteger passCount = new AtomicInteger(0); - AtomicInteger totalCount = new AtomicInteger(0); - static boolean exitOnFailed = true; + protected static String testsetsDir; + protected AtomicInteger passCount = new AtomicInteger(0); + protected AtomicInteger totalCount = new AtomicInteger(0); + protected static boolean exitOnFailed = true; // key: tester name, value: tester result - private static Map allTestStatus = new TreeMap<>(); + private static final Map allTestStatus = new TreeMap<>(); - private static int testParallelism = 2; + private static final int testParallelism = 2; static Map queryParams = new HashMap<>(); @@ -275,8 +275,8 @@ void executeSqlFileWithCheckResult( * actual result matches the query failed result. 3. The expected result is a regular expression, * and the actual result matches the regular expression. * - * @param expectResult - * @param result + * @param expectResult the expected result + * @param result the actual result * @return false if the expected result is empty or the actual result does not match the expected. * For {@literal } case, return true if the actual result is empty. For {@literal * } case, replace the placeholder with "^Query \\w+ failed.*: " and do match. @@ -338,7 +338,7 @@ static boolean match(String expectResult, String result) { @Test public void testSql() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(testParallelism); - CompletionService completionService = new ExecutorCompletionService<>(executor); + CompletionService completionService = new ExecutorCompletionService<>(executor); String[] testSetNames = Arrays.stream(TrinoQueryITBase.listDirectory(testsetsDir)) @@ -357,7 +357,7 @@ public void testSql() throws Exception { public void testSql(String testSetDirName, String catalog, String testerPrefix) throws Exception { ExecutorService executor = Executors.newFixedThreadPool(testParallelism); - CompletionService completionService = new ExecutorCompletionService<>(executor); + CompletionService completionService = new ExecutorCompletionService<>(executor); totalCount.addAndGet(getTesterCount(testSetDirName, catalog, testerPrefix)); List> futures = @@ -369,7 +369,7 @@ public void testSql(String testSetDirName, String catalog, String testerPrefix) private void waitForCompleted( ExecutorService executor, - CompletionService completionService, + CompletionService completionService, List> allFutures) { for (int i = 0; i < allFutures.size(); i++) { try { @@ -405,7 +405,7 @@ public String generateTestStatus() { } public List> runOneTestset( - CompletionService completionService, + CompletionService completionService, String testSetDirName, String catalog, String testerFilter) diff --git a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryRunner.java b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryRunner.java index 0e794e45ab5..7c3001a731e 100644 --- a/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryRunner.java +++ b/trino-connector/integration-test/src/test/java/org/apache/gravitino/trino/connector/integration/test/TrinoQueryRunner.java @@ -42,9 +42,9 @@ class TrinoQueryRunner { private static final Logger LOG = LoggerFactory.getLogger(TrinoQueryRunner.class); - private QueryRunner queryRunner; - private Terminal terminal; - private URI uri; + private final QueryRunner queryRunner; + private final Terminal terminal; + private final URI uri; TrinoQueryRunner(String trinoUri) throws Exception { this.uri = new URI(trinoUri); @@ -92,10 +92,11 @@ String runQuery(String query) { String runQueryOnce(String query) { Query queryResult = queryRunner.startQuery(query); StringOutputStream outputStream = new StringOutputStream(); + StringOutputStream errorStream = new StringOutputStream(); queryResult.renderOutput( this.terminal, new PrintStream(outputStream), - new PrintStream(outputStream), + new PrintStream(errorStream), CSV, Optional.of(""), false); @@ -109,17 +110,19 @@ String runQueryOnce(String query) { session = builder.build(); queryRunner.setSession(session); } - return outputStream.toString(); + + // Avoid the IDE capturing the error message as failure + String err_message = errorStream.toString().replace("\nCaused by:", "\n-Caused by:"); + String out_message = outputStream.toString(); + return err_message + out_message; } - boolean stop() { + void stop() { try { queryRunner.close(); terminal.close(); - return true; } catch (Exception e) { LOG.error("Failed to stop query runner", e); - return false; } } } diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.sql b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.sql index b3af09a6580..e8058cde4ef 100644 --- a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.sql +++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.sql @@ -37,6 +37,8 @@ show create table gt_mysql.gt_db1.tb01; alter table gt_mysql.gt_db1.tb01 add column address varchar(200) not null comment 'address of users'; show create table gt_mysql.gt_db1.tb01; +COMMENT ON COLUMN gt_mysql.gt_db1.tb01.city IS NULL; + drop table gt_mysql.gt_db1.tb01; drop schema gt_mysql.gt_db1; diff --git a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.txt b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.txt index 3aa3144935c..b3b5366b9a6 100644 --- a/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.txt +++ b/trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00002_alter_table.txt @@ -104,6 +104,8 @@ WITH ( engine = 'InnoDB' )" + "newComment" field is required and cannot be empty + DROP TABLE DROP SCHEMA diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoErrorCode.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoErrorCode.java index 5741e4427bd..e47675d4574 100644 --- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoErrorCode.java +++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoErrorCode.java @@ -23,6 +23,7 @@ import io.trino.spi.ErrorCode; import io.trino.spi.ErrorCodeSupplier; import io.trino.spi.ErrorType; +import java.util.List; public enum GravitinoErrorCode implements ErrorCodeSupplier { GRAVITINO_UNSUPPORTED_TRINO_VERSION(0, EXTERNAL), @@ -64,4 +65,9 @@ public enum GravitinoErrorCode implements ErrorCodeSupplier { public ErrorCode toErrorCode() { return errorCode; } + + public static String toSimpleErrorMessage(Exception e) { + List lines = e.getMessage().lines().toList(); + return lines.size() > 1 ? lines.get(0) + lines.get(1) : lines.get(0); + } } diff --git a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java index 759a4de0889..3bb61f977e5 100644 --- a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java +++ b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/CatalogConnectorMetadata.java @@ -190,8 +190,7 @@ private void applyAlter(SchemaTableName tableName, TableChange... change) { // TODO yuhui need improve get the error message. From IllegalArgumentException. // At present, the IllegalArgumentException cannot get the error information clearly from the // Gravitino server. - String message = - e.getMessage().lines().toList().get(0) + e.getMessage().lines().toList().get(1); + String message = GravitinoErrorCode.toSimpleErrorMessage(e); throw new TrinoException(GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT, message, e); } }