Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#698] feat(trino-connector) Support jdbc catalogs in trino-connector (#928)

Yuhui7c3b52031763
diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
index a71ba8b410..7269723eef 100644
--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
@@ -536,8 +536,8 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSche
@Override
public boolean purgeTable(NameIdentifier tableIdent) throws UnsupportedOperationException {
try {
- icebergTableOps.purgeTable(
- TableIdentifier.of(ArrayUtils.add(tableIdent.namespace().levels(), tableIdent.name())));
+ String schema = NameIdentifier.of(tableIdent.namespace().levels()).name();
+ icebergTableOps.purgeTable(TableIdentifier.of(schema, tableIdent.name()));
LOG.info("Purge Iceberg table {}", tableIdent.name());
return true;
} catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java
index b0ee4ae218..fb2e5a6408 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java
@@ -256,6 +256,35 @@ public class RelationalCatalog extends CatalogDTO implements TableCatalog, Suppo
}
}
+ /**
+ * Purge the table with specified identifier.
+ *
+ * @param ident The identifier of the table.
+ * @return true if the table is purged successfully, false otherwise.
+ */
+ @Override
+ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationException {
+ NameIdentifier.checkTable(ident);
+
+ Map<String, String> params = new HashMap<>();
+ params.put("purge", "true");
+ try {
+ DropResponse resp =
+ restClient.delete(
+ formatTableRequestPath(ident.namespace()) + "/" + ident.name(),
+ params,
+ DropResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.tableErrorHandler());
+ resp.validate();
+ return resp.dropped();
+
+ } catch (Exception e) {
+ LOG.warn("Failed to purge table {}", ident, e);
+ return false;
+ }
+ }
+
/**
* List all the schemas under the given catalog namespace.
*
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryIT.java
index 7b6c756302..2066f8035b 100644
--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryIT.java
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoQueryIT.java
@@ -30,9 +30,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
@@ -65,8 +67,11 @@ public class TrinoQueryIT {
private static String gravitinoUri = "http://127.0.0.1:8090";
private static String trinoUri = "http://127.0.0.1:8080";
private static String hiveMetastoreUri = "thrift://127.0.0.1:9083";
+ private static String mysqlUri = "jdbc:mysql://127.0.0.1?useSSL=false";
+ private static String postgresqlUri = "jdbc:postgresql://127.0.0.1/mydb";
private static final String metalakeName = "test";
+ private static final Set<String> testCatalogs = new HashSet<>();
private static GravitinoClient client;
private static GravitinoMetaLake metalake;
@@ -74,18 +79,18 @@ public class TrinoQueryIT {
private static AtomicInteger testCount = new AtomicInteger(0);
private static AtomicInteger totalCount = new AtomicInteger(0);
static TrinoQueryRunner trinoQueryRunner;
- private static String targetCatalog = null;
@BeforeAll
public static void setup() throws Exception {
-
try {
client = GravitinoClient.builder(gravitinoUri).build();
trinoQueryRunner = new TrinoQueryRunner();
createMetalake();
- if (targetCatalog == null || targetCatalog.equals("hive")) {
+ Set<String> catalogs = new HashSet<>(testCatalogs);
+
+ if (catalogs.isEmpty() || catalogs.contains("hive")) {
dropCatalog("hive");
HashMap<String, String> properties = new HashMap<>();
properties.put("metastore.uris", hiveMetastoreUri);
@@ -93,15 +98,39 @@ public class TrinoQueryIT {
createCatalog("hive", "hive", properties);
}
- if (targetCatalog == null || targetCatalog.equals("lakehouse-iceberg")) {
+ if (catalogs.isEmpty() || catalogs.contains("lakehouse-iceberg")) {
dropCatalog("lakehouse-iceberg");
HashMap<String, String> properties = new HashMap<>();
properties.put("uri", hiveMetastoreUri);
properties.put("catalog-backend", "hive");
properties.put("warehouse", "hdfs://localhost:9000/user/iceberg/warehouse/TrinoQueryIT");
+
createCatalog("lakehouse-iceberg", "lakehouse-iceberg", properties);
}
+ if (catalogs.isEmpty() || catalogs.contains("jdbc-mysql")) {
+ dropCatalog("jdbc-mysql");
+ HashMap<String, String> properties = new HashMap<>();
+ properties.put("gravitino.bypass.jdbc-url", mysqlUri);
+ properties.put("gravitino.bypass.jdbc-user", "root");
+ properties.put("gravitino.bypass.jdbc-password", "ds123");
+ properties.put("gravitino.bypass.driverClassName", "com.mysql.cj.jdbc.Driver");
+
+ createCatalog("jdbc-mysql", "jdbc-mysql", properties);
+ }
+
+ if (catalogs.isEmpty() || catalogs.contains("jdbc-postgresql")) {
+ dropCatalog("jdbc-postgresql");
+ HashMap<String, String> properties = new HashMap<>();
+ properties.put("jdbc-url", postgresqlUri);
+ properties.put("jdbc-user", "root");
+ properties.put("jdbc-password", "ds123");
+ properties.put("jdbc-database", "mydb");
+ properties.put("gravitino.bypass.driverClassName", "org.postgresql.Driver");
+
+ createCatalog("jdbc-postgresql", "jdbc-postgresql", properties);
+ }
+
isDockerRunning = true;
} catch (Exception e) {
LOG.error("Services are not connected", e);
@@ -152,6 +181,7 @@ public class TrinoQueryIT {
"comment",
properties);
Assertions.assertNotNull(createdCatalog);
+ testCatalogs.add(catalogName);
}
boolean catalogCreated = false;
@@ -172,6 +202,9 @@ public class TrinoQueryIT {
}
private static void dropCatalog(String catalogName) {
+ if (metalake == null) {
+ return;
+ }
boolean exists = metalake.catalogExists(NameIdentifier.of(metalakeName, catalogName));
if (!exists) {
return;
@@ -179,7 +212,7 @@ public class TrinoQueryIT {
Catalog catalog = metalake.loadCatalog(NameIdentifier.of(metalakeName, catalogName));
SupportsSchemas schemas = catalog.asSchemas();
Arrays.stream(schemas.listSchemas(Namespace.ofSchema(metalakeName, catalogName)))
- .filter(schema -> !schema.name().equals("default"))
+ .filter(schema -> !schema.name().equals("default") && schema.name().startsWith("gt_"))
.forEach(
schema -> {
try {
@@ -209,7 +242,7 @@ public class TrinoQueryIT {
});
schemas.dropSchema(
- NameIdentifier.ofSchema(metalakeName, catalogName, schema.name()), true);
+ NameIdentifier.ofSchema(metalakeName, catalogName, schema.name()), false);
} catch (Exception e) {
LOG.error("Failed to drop schema {}", schema);
}
@@ -264,6 +297,7 @@ public class TrinoQueryIT {
}
}
+ testCatalogs.stream().forEach(catalog -> dropCatalog(catalog));
Log.info("All tests completed");
executor.shutdownNow();
executor.awaitTermination(3, TimeUnit.SECONDS);
@@ -314,20 +348,18 @@ public class TrinoQueryIT {
String sql = sqlMatcher.group(1);
String expectResult = "";
if (resultMatcher.find()) {
- expectResult = resultMatcher.group(1) + "\n";
+ expectResult = resultMatcher.group(1).trim();
}
- String result = queryRunner.runQuery(sql);
+ String result = queryRunner.runQuery(sql).trim();
boolean match;
- if (Pattern.compile("^Query \\w+ failed:").matcher(result).find()) {
- match =
- Pattern.compile("^Query \\w+ failed.*: " + expectResult.trim())
- .matcher(result)
- .find();
+ if (!expectResult.isEmpty()
+ && Pattern.compile("^Query \\w+ failed:").matcher(result).find()) {
+ match = Pattern.compile("^Query \\w+ failed.*: " + expectResult).matcher(result).find();
} else {
- match = expectResult.trim().equals(result.trim());
+ match = expectResult.equals(result);
}
if (match) {
@@ -412,32 +444,39 @@ public class TrinoQueryIT {
public static void main(String[] args) {
String targetTestId = null;
try {
-
if (args.length == 1) {
// e.g.: args = hive
// run hive all the test cases
- targetCatalog = args[0];
+ String catalog = args[0];
+ testCatalogs.add(catalog);
setup();
TrinoQueryIT testRunner = new TrinoQueryIT();
- testRunner.runQueriesAndCheck(targetCatalog, targetTestId);
+ testRunner.runQueriesAndCheck(catalog, targetTestId);
} else if (args.length == 2) {
// e.g: args = hive 00001
// run hive test case 00001
- targetCatalog = args[0];
+ String catalog = args[0];
targetTestId = args[1];
+ testCatalogs.add(catalog);
setup();
TrinoQueryIT testRunner = new TrinoQueryIT();
- testRunner.runQueriesAndCheck(targetCatalog, targetTestId);
+ testRunner.runQueriesAndCheck(catalog, targetTestId);
+
} else if (args.length == 0) {
// e.g.: empty args
// run all catalogs all the test cases
setup();
TrinoQueryIT testRunner = new TrinoQueryIT();
testRunner.testSql();
+ return;
+ } else {
+ throw new IllegalArgumentException(
+ "Invalid args: " + Arrays.toString(args) + "\n" + "Usage: ./run [catalog] [testId]");
}
-
+ Log.info("All tests completed");
+ testCatalogs.stream().forEach(c -> dropCatalog(c));
} catch (Exception e) {
LOG.error("", e);
} finally {
diff --git a/integration-test/src/test/resources/trino-queries/bugs/00001_alter_table.sql b/integration-test/src/test/resources/trino-queries/bugs/00001_alter_table.sql
deleted file mode 100644
index 13af3e576b..0000000000
--- a/integration-test/src/test/resources/trino-queries/bugs/00001_alter_table.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-CREATE SCHEMA "test.hive".db1;
-
-CREATE TABLE "test.hive".db1.tb01 (
- name varchar,
- salary int
-)
-WITH (
- format = 'TEXTFILE'
-);
-
-alter table "test.hive".db1.tb01 add column city varchar comment 'aaa';
-
-show create table "test.hive".db1.tb01;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/bugs/00002_alter_table_mysql.sql b/integration-test/src/test/resources/trino-queries/bugs/00002_alter_table_mysql.sql
new file mode 100644
index 0000000000..b26d9fe682
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/bugs/00002_alter_table_mysql.sql
@@ -0,0 +1,16 @@
+CREATE SCHEMA "test.jdbc-mysql".gt_db1;
+
+CREATE TABLE "test.jdbc-mysql".gt_db1.tb01 (
+ name varchar,
+ salary int
+);
+
+alter table "test.jdbc-mysql".gt_db1.tb01 rename column name to s;
+show tables from "test.jdbc-mysql".gt_db1;
+
+comment on table "test.jdbc-mysql".gt_db1.tb01 is 'test table comments';
+show create table "test.jdbc-mysql".gt_db1.tb01;
+
+comment on column "test.jdbc-mysql".gt_db1.tb01.s is 'test column comments';
+show create table "test.jdbc-mysql".gt_db1.tb01;
+
diff --git a/integration-test/src/test/resources/trino-queries/bugs/00002_drop_table.sql b/integration-test/src/test/resources/trino-queries/bugs/00002_drop_table.sql
deleted file mode 100644
index 8a510cb41e..0000000000
--- a/integration-test/src/test/resources/trino-queries/bugs/00002_drop_table.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-CREATE SCHEMA "test.hive".db1;
-
-CREATE TABLE "test.hive".db1.tb01 (
- name varchar,
- salary int
-)
-WITH (
- format = 'TEXTFILE'
-);
-
-insert into "test.hive".db1.tb01(name, salary) values ('sam', 11);
-insert into "test.hive".db1.tb01(name, salary) values ('jerry', 13);
-
-select * from "test.hive".db1.tb01 order by name;
-
-drop table "test.hive".db1.tb01;
-drop schema "test.hive".db1;
-
-CREATE SCHEMA "test.hive".db1;
-
-CREATE TABLE "test.hive".db1.tb01 (
- name varchar,
- salary int
-)
-WITH (
- format = 'TEXTFILE'
-);
-
-select * from "test.hive".db1.tb01 order by name;
-
-
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/hive/00000_create_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/hive/00000_create_table.sql
index 3eb1f5ff67..437b0efbdb 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/hive/00000_create_table.sql
+++ b/integration-test/src/test/resources/trino-queries/catalogs/hive/00000_create_table.sql
@@ -1,6 +1,6 @@
-CREATE SCHEMA "test.hive".db1;
+CREATE SCHEMA "test.hive".gt_db1;
-CREATE TABLE "test.hive".db1.tb01 (
+CREATE TABLE "test.hive".gt_db1.tb01 (
name varchar,
salary int
)
@@ -8,6 +8,6 @@ WITH (
format = 'TEXTFILE'
);
-drop table "test.hive".db1.tb01;
+drop table "test.hive".gt_db1.tb01;
-drop schema "test.hive".db1;
\ No newline at end of file
+drop schema "test.hive".gt_db1;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/hive/00001_select_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/hive/00001_select_table.sql
index b7c1d8be80..eafff898aa 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/hive/00001_select_table.sql
+++ b/integration-test/src/test/resources/trino-queries/catalogs/hive/00001_select_table.sql
@@ -1,6 +1,6 @@
-CREATE SCHEMA "test.hive".db1;
+CREATE SCHEMA "test.hive".gt_db1;
-CREATE TABLE "test.hive".db1.tb01 (
+CREATE TABLE "test.hive".gt_db1.tb01 (
name varchar,
salary int
)
@@ -8,13 +8,13 @@ WITH (
format = 'TEXTFILE'
);
-insert into "test.hive".db1.tb01(name, salary) values ('sam', 11);
-insert into "test.hive".db1.tb01(name, salary) values ('jerry', 13);
-insert into "test.hive".db1.tb01(name, salary) values ('bob', 14), ('tom', 12);
+insert into "test.hive".gt_db1.tb01(name, salary) values ('sam', 11);
+insert into "test.hive".gt_db1.tb01(name, salary) values ('jerry', 13);
+insert into "test.hive".gt_db1.tb01(name, salary) values ('bob', 14), ('tom', 12);
-select distinct * from "test.hive".db1.tb01 order by name;
+select * from "test.hive".gt_db1.tb01 order by name;
-CREATE TABLE "test.hive".db1.tb02 (
+CREATE TABLE "test.hive".gt_db1.tb02 (
name varchar,
salary int
)
@@ -22,12 +22,12 @@ WITH (
format = 'TEXTFILE'
);
-insert into "test.hive".db1.tb02(name, salary) select distinct * from "test.hive".db1.tb01 order by name;
+insert into "test.hive".gt_db1.tb02(name, salary) select distinct * from "test.hive".gt_db1.tb01 order by name;
-select distinct * from "test.hive".db1.tb02 order by name;
+select * from "test.hive".gt_db1.tb02 order by name;
-drop table "test.hive".db1.tb02;
+drop table "test.hive".gt_db1.tb02;
-drop table "test.hive".db1.tb01;
+drop table "test.hive".gt_db1.tb01;
-drop schema "test.hive".db1;
+drop schema "test.hive".gt_db1;
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.sql
index e3ba75bad4..2a6f4f19b2 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.sql
+++ b/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.sql
@@ -1,6 +1,6 @@
-CREATE SCHEMA "test.hive".db1;
+CREATE SCHEMA "test.hive".gt_db1;
-CREATE TABLE "test.hive".db1.tb01 (
+CREATE TABLE "test.hive".gt_db1.tb01 (
name varchar,
salary int,
city int
@@ -9,27 +9,30 @@ WITH (
format = 'TEXTFILE'
);
-alter table "test.hive".db1.tb01 rename to "test.hive".db1.tb03;
-show tables from "test.hive".db1;
+alter table "test.hive".gt_db1.tb01 rename to "test.hive".gt_db1.tb03;
+show tables from "test.hive".gt_db1;
-alter table "test.hive".db1.tb03 rename to "test.hive".db1.tb01;
-show tables from "test.hive".db1;
+alter table "test.hive".gt_db1.tb03 rename to "test.hive".gt_db1.tb01;
+show tables from "test.hive".gt_db1;
-alter table "test.hive".db1.tb01 drop column city;
-show create table "test.hive".db1.tb01;
+alter table "test.hive".gt_db1.tb01 drop column city;
+show create table "test.hive".gt_db1.tb01;
-alter table "test.hive".db1.tb01 rename column name to s;
-show create table "test.hive".db1.tb01;
+alter table "test.hive".gt_db1.tb01 rename column name to s;
+show create table "test.hive".gt_db1.tb01;
-alter table "test.hive".db1.tb01 alter column s set data type varchar(256);
-show create table "test.hive".db1.tb01;
+alter table "test.hive".gt_db1.tb01 alter column s set data type varchar(256);
+show create table "test.hive".gt_db1.tb01;
-comment on table "test.hive".db1.tb01 is 'test table comments';
-show create table "test.hive".db1.tb01;
+comment on table "test.hive".gt_db1.tb01 is 'test table comments';
+show create table "test.hive".gt_db1.tb01;
-comment on column "test.hive".db1.tb01.s is 'test column comments';
-show create table "test.hive".db1.tb01;
+comment on column "test.hive".gt_db1.tb01.s is 'test column comments';
+show create table "test.hive".gt_db1.tb01;
-drop table "test.hive".db1.tb01;
+alter table "test.hive".gt_db1.tb01 add column city varchar comment 'aaa';
+show create table "test.hive".gt_db1.tb01;
-drop schema "test.hive".db1;
+drop table "test.hive".gt_db1.tb01;
+
+drop schema "test.hive".gt_db1;
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.txt
index c4bf08186e..2a9eb73ed3 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.txt
+++ b/integration-test/src/test/resources/trino-queries/catalogs/hive/00002_alter_table.txt
@@ -12,43 +12,112 @@ RENAME TABLE
DROP COLUMN
-"CREATE TABLE ""test.hive"".db1.tb01 (
+"CREATE TABLE ""test.hive"".gt_db1.tb01 (
name varchar(65535),
salary integer
)
-COMMENT ''"
+COMMENT ''
+WITH (
+ input_format = 'org.apache.hadoop.mapred.TextInputFormat',
+ location = 'hdfs://localhost:9000/user/hive/warehouse/gt_db1.db/tb01',
+ num_files = '0',
+ output_format = 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
+ serde_lib = 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
+ serde_name = 'tb01',
+ table_type = 'MANAGED_TABLE',
+ total_size = '0'
+)"
RENAME COLUMN
-"CREATE TABLE ""test.hive"".db1.tb01 (
+"CREATE TABLE ""test.hive"".gt_db1.tb01 (
s varchar(65535),
salary integer
)
-COMMENT ''"
+COMMENT ''
+WITH (
+ input_format = 'org.apache.hadoop.mapred.TextInputFormat',
+ location = 'hdfs://localhost:9000/user/hive/warehouse/gt_db1.db/tb01',
+ num_files = '0',
+ output_format = 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
+ serde_lib = 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
+ serde_name = 'tb01',
+ table_type = 'MANAGED_TABLE',
+ total_size = '0'
+)"
SET COLUMN TYPE
-"CREATE TABLE ""test.hive"".db1.tb01 (
+"CREATE TABLE ""test.hive"".gt_db1.tb01 (
s varchar(256),
salary integer
)
-COMMENT ''"
+COMMENT ''
+WITH (
+ input_format = 'org.apache.hadoop.mapred.TextInputFormat',
+ location = 'hdfs://localhost:9000/user/hive/warehouse/gt_db1.db/tb01',
+ num_files = '0',
+ output_format = 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
+ serde_lib = 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
+ serde_name = 'tb01',
+ table_type = 'MANAGED_TABLE',
+ total_size = '0'
+)"
COMMENT
-"CREATE TABLE ""test.hive"".db1.tb01 (
+"CREATE TABLE ""test.hive"".gt_db1.tb01 (
s varchar(256),
salary integer
)
-COMMENT 'test table comments'"
+COMMENT 'test table comments'
+WITH (
+ input_format = 'org.apache.hadoop.mapred.TextInputFormat',
+ location = 'hdfs://localhost:9000/user/hive/warehouse/gt_db1.db/tb01',
+ num_files = '0',
+ output_format = 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
+ serde_lib = 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
+ serde_name = 'tb01',
+ table_type = 'MANAGED_TABLE',
+ total_size = '0'
+)"
COMMENT
-"CREATE TABLE ""test.hive"".db1.tb01 (
+"CREATE TABLE ""test.hive"".gt_db1.tb01 (
s varchar(256) COMMENT 'test column comments',
salary integer
)
-COMMENT 'test table comments'"
+COMMENT 'test table comments'
+WITH (
+ input_format = 'org.apache.hadoop.mapred.TextInputFormat',
+ location = 'hdfs://localhost:9000/user/hive/warehouse/gt_db1.db/tb01',
+ num_files = '0',
+ output_format = 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
+ serde_lib = 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
+ serde_name = 'tb01',
+ table_type = 'MANAGED_TABLE',
+ total_size = '0'
+)"
+
+ADD COLUMN
+
+"CREATE TABLE ""test.hive"".gt_db1.tb01 (
+ s varchar(256) COMMENT 'test column comments',
+ salary integer,
+ city varchar(65535) COMMENT 'aaa'
+)
+COMMENT 'test table comments'
+WITH (
+ input_format = 'org.apache.hadoop.mapred.TextInputFormat',
+ location = 'hdfs://localhost:9000/user/hive/warehouse/gt_db1.db/tb01',
+ num_files = '0',
+ output_format = 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat',
+ serde_lib = 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe',
+ serde_name = 'tb01',
+ table_type = 'MANAGED_TABLE',
+ total_size = '0'
+)"
DROP TABLE
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00000_create_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00000_create_table.sql
new file mode 100644
index 0000000000..05a9d89153
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00000_create_table.sql
@@ -0,0 +1,10 @@
+CREATE SCHEMA "test.jdbc-mysql".gt_db1;
+
+CREATE TABLE "test.jdbc-mysql".gt_db1.tb01 (
+ name varchar,
+ salary int
+);
+
+drop table "test.jdbc-mysql".gt_db1.tb01;
+
+drop schema "test.jdbc-mysql".gt_db1;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00000_create_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00000_create_table.txt
new file mode 100644
index 0000000000..2862f23f23
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00000_create_table.txt
@@ -0,0 +1,7 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00001_select_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00001_select_table.sql
new file mode 100644
index 0000000000..23ee2965e5
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00001_select_table.sql
@@ -0,0 +1,27 @@
+CREATE SCHEMA "test.jdbc-mysql".gt_db1;
+
+CREATE TABLE "test.jdbc-mysql".gt_db1.tb01 (
+ name varchar,
+ salary int
+);
+
+insert into "test.jdbc-mysql".gt_db1.tb01(name, salary) values ('sam', 11);
+insert into "test.jdbc-mysql".gt_db1.tb01(name, salary) values ('jerry', 13);
+insert into "test.jdbc-mysql".gt_db1.tb01(name, salary) values ('bob', 14), ('tom', 12);
+
+select * from "test.jdbc-mysql".gt_db1.tb01 order by name;
+
+CREATE TABLE "test.jdbc-mysql".gt_db1.tb02 (
+ name varchar,
+ salary int
+);
+
+insert into "test.jdbc-mysql".gt_db1.tb02(name, salary) select distinct * from "test.jdbc-mysql".gt_db1.tb01 order by name;
+
+select * from "test.jdbc-mysql".gt_db1.tb02 order by name;
+
+drop table "test.jdbc-mysql".gt_db1.tb02;
+
+drop table "test.jdbc-mysql".gt_db1.tb01;
+
+drop schema "test.jdbc-mysql".gt_db1;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00001_select_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00001_select_table.txt
new file mode 100644
index 0000000000..f5aa32125e
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00001_select_table.txt
@@ -0,0 +1,31 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 1 row
+
+INSERT: 1 row
+
+INSERT: 2 rows
+
+"bob","14"
+"jerry","13"
+"sam","11"
+"tom","12"
+
+CREATE TABLE
+
+INSERT: 4 rows
+
+"bob","14"
+"jerry","13"
+"sam","11"
+"tom","12"
+
+DROP TABLE
+
+DROP TABLE
+
+DROP SCHEMA
+
+
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00002_alter_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00002_alter_table.sql
new file mode 100644
index 0000000000..32c0ca8914
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00002_alter_table.sql
@@ -0,0 +1,26 @@
+CREATE SCHEMA "test.jdbc-mysql".gt_db1;
+
+CREATE TABLE "test.jdbc-mysql".gt_db1.tb01 (
+ name varchar,
+ salary int,
+ city int
+);
+
+alter table "test.jdbc-mysql".gt_db1.tb01 rename to "test.jdbc-mysql".gt_db1.tb03;
+show tables from "test.jdbc-mysql".gt_db1;
+
+alter table "test.jdbc-mysql".gt_db1.tb03 rename to "test.jdbc-mysql".gt_db1.tb01;
+show tables from "test.jdbc-mysql".gt_db1;
+
+alter table "test.jdbc-mysql".gt_db1.tb01 drop column city;
+show create table "test.jdbc-mysql".gt_db1.tb01;
+
+alter table "test.jdbc-mysql".gt_db1.tb01 alter column salary set data type bigint;
+show create table "test.jdbc-mysql".gt_db1.tb01;
+
+alter table "test.jdbc-mysql".gt_db1.tb01 add column city varchar comment 'aaa';
+show create table "test.jdbc-mysql".gt_db1.tb01;
+
+drop table "test.jdbc-mysql".gt_db1.tb01;
+
+drop schema "test.jdbc-mysql".gt_db1;
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00002_alter_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00002_alter_table.txt
new file mode 100644
index 0000000000..882ea8d337
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-mysql/00002_alter_table.txt
@@ -0,0 +1,42 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+RENAME TABLE
+
+"tb03"
+
+RENAME TABLE
+
+"tb01"
+
+DROP COLUMN
+
+"CREATE TABLE ""test.jdbc-mysql"".gt_db1.tb01 (
+ name varchar,
+ salary integer
+)
+COMMENT ''"
+
+SET COLUMN TYPE
+
+"CREATE TABLE ""test.jdbc-mysql"".gt_db1.tb01 (
+ name varchar,
+ salary bigint
+)
+COMMENT ''"
+
+ADD COLUMN
+
+"CREATE TABLE ""test.jdbc-mysql"".gt_db1.tb01 (
+ name varchar,
+ salary bigint,
+ city varchar COMMENT 'aaa'
+)
+COMMENT ''"
+
+DROP TABLE
+
+DROP SCHEMA
+
+
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00000_create_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00000_create_table.sql
new file mode 100644
index 0000000000..2114f3d15d
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00000_create_table.sql
@@ -0,0 +1,10 @@
+CREATE SCHEMA "test.jdbc-postgresql".gt_db1;
+
+CREATE TABLE "test.jdbc-postgresql".gt_db1.tb01 (
+ name varchar,
+ salary int
+);
+
+drop table "test.jdbc-postgresql".gt_db1.tb01;
+
+drop schema "test.jdbc-postgresql".gt_db1;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00000_create_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00000_create_table.txt
new file mode 100644
index 0000000000..2862f23f23
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00000_create_table.txt
@@ -0,0 +1,7 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+DROP TABLE
+
+DROP SCHEMA
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00001_select_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00001_select_table.sql
new file mode 100644
index 0000000000..7e753144a1
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00001_select_table.sql
@@ -0,0 +1,27 @@
+CREATE SCHEMA "test.jdbc-postgresql".gt_db1;
+
+CREATE TABLE "test.jdbc-postgresql".gt_db1.tb01 (
+ name varchar,
+ salary int
+);
+
+insert into "test.jdbc-postgresql".gt_db1.tb01(name, salary) values ('sam', 11);
+insert into "test.jdbc-postgresql".gt_db1.tb01(name, salary) values ('jerry', 13);
+insert into "test.jdbc-postgresql".gt_db1.tb01(name, salary) values ('bob', 14), ('tom', 12);
+
+select * from "test.jdbc-postgresql".gt_db1.tb01 order by name;
+
+CREATE TABLE "test.jdbc-postgresql".gt_db1.tb02 (
+ name varchar,
+ salary int
+);
+
+insert into "test.jdbc-postgresql".gt_db1.tb02(name, salary) select distinct * from "test.jdbc-postgresql".gt_db1.tb01 order by name;
+
+select * from "test.jdbc-postgresql".gt_db1.tb02 order by name;
+
+drop table "test.jdbc-postgresql".gt_db1.tb02;
+
+drop table "test.jdbc-postgresql".gt_db1.tb01;
+
+drop schema "test.jdbc-postgresql".gt_db1;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00001_select_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00001_select_table.txt
new file mode 100644
index 0000000000..f5aa32125e
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00001_select_table.txt
@@ -0,0 +1,31 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+INSERT: 1 row
+
+INSERT: 1 row
+
+INSERT: 2 rows
+
+"bob","14"
+"jerry","13"
+"sam","11"
+"tom","12"
+
+CREATE TABLE
+
+INSERT: 4 rows
+
+"bob","14"
+"jerry","13"
+"sam","11"
+"tom","12"
+
+DROP TABLE
+
+DROP TABLE
+
+DROP SCHEMA
+
+
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00002_alter_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00002_alter_table.sql
new file mode 100644
index 0000000000..9225c3b5ff
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00002_alter_table.sql
@@ -0,0 +1,35 @@
+CREATE SCHEMA "test.jdbc-postgresql".gt_db1;
+
+CREATE TABLE "test.jdbc-postgresql".gt_db1.tb01 (
+ name varchar,
+ salary int,
+ city int
+);
+
+alter table "test.jdbc-postgresql".gt_db1.tb01 rename to "test.jdbc-postgresql".gt_db1.tb03;
+show tables from "test.jdbc-postgresql".gt_db1;
+
+alter table "test.jdbc-postgresql".gt_db1.tb03 rename to "test.jdbc-postgresql".gt_db1.tb01;
+show tables from "test.jdbc-postgresql".gt_db1;
+
+alter table "test.jdbc-postgresql".gt_db1.tb01 drop column city;
+show create table "test.jdbc-postgresql".gt_db1.tb01;
+
+alter table "test.jdbc-postgresql".gt_db1.tb01 alter column salary set data type bigint;
+show create table "test.jdbc-postgresql".gt_db1.tb01;
+
+comment on table "test.jdbc-postgresql".gt_db1.tb01 is 'test table comments';
+show create table "test.jdbc-postgresql".gt_db1.tb01;
+
+alter table "test.jdbc-postgresql".gt_db1.tb01 rename column name to s;
+show create table "test.jdbc-postgresql".gt_db1.tb01;
+
+comment on column "test.jdbc-postgresql".gt_db1.tb01.s is 'test column comments';
+show create table "test.jdbc-postgresql".gt_db1.tb01;
+
+alter table "test.jdbc-postgresql".gt_db1.tb01 add column city varchar comment 'aaa';
+show create table "test.jdbc-postgresql".gt_db1.tb01;
+
+drop table "test.jdbc-postgresql".gt_db1.tb01;
+
+drop schema "test.jdbc-postgresql".gt_db1;
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00002_alter_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00002_alter_table.txt
new file mode 100644
index 0000000000..32bdad5a98
--- /dev/null
+++ b/integration-test/src/test/resources/trino-queries/catalogs/jdbc-postgresql/00002_alter_table.txt
@@ -0,0 +1,66 @@
+CREATE SCHEMA
+
+CREATE TABLE
+
+RENAME TABLE
+
+"tb03"
+
+RENAME TABLE
+
+"tb01"
+
+DROP COLUMN
+
+"CREATE TABLE ""test.jdbc-postgresql"".gt_db1.tb01 (
+ name varchar,
+ salary integer
+)
+COMMENT ''"
+
+SET COLUMN TYPE
+
+"CREATE TABLE ""test.jdbc-postgresql"".gt_db1.tb01 (
+ name varchar,
+ salary bigint
+)
+COMMENT ''"
+
+COMMENT
+
+"CREATE TABLE ""test.jdbc-postgresql"".gt_db1.tb01 (
+ name varchar,
+ salary bigint
+)
+COMMENT 'test table comments'"
+
+RENAME COLUMN
+
+"CREATE TABLE ""test.jdbc-postgresql"".gt_db1.tb01 (
+ s varchar,
+ salary bigint
+)
+COMMENT 'test table comments'"
+
+COMMENT
+
+"CREATE TABLE ""test.jdbc-postgresql"".gt_db1.tb01 (
+ s varchar COMMENT 'test column comments',
+ salary bigint
+)
+COMMENT 'test table comments'"
+
+ADD COLUMN
+
+"CREATE TABLE ""test.jdbc-postgresql"".gt_db1.tb01 (
+ s varchar COMMENT 'test column comments',
+ salary bigint,
+ city varchar COMMENT 'aaa'
+)
+COMMENT 'test table comments'"
+
+DROP TABLE
+
+DROP SCHEMA
+
+
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00000_create_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00000_create_table.sql
index 068e76238d..aa7a3b63fc 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00000_create_table.sql
+++ b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00000_create_table.sql
@@ -1,10 +1,10 @@
-CREATE SCHEMA "test.lakehouse-iceberg".db2;
+CREATE SCHEMA "test.lakehouse-iceberg".gt_db2;
-CREATE TABLE "test.lakehouse-iceberg".db2.tb01 (
+CREATE TABLE "test.lakehouse-iceberg".gt_db2.tb01 (
name varchar,
salary int
);
-drop table "test.lakehouse-iceberg".db2.tb01;
+drop table "test.lakehouse-iceberg".gt_db2.tb01;
-drop schema "test.lakehouse-iceberg".db2;
\ No newline at end of file
+drop schema "test.lakehouse-iceberg".gt_db2;
\ No newline at end of file
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00001_select_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00001_select_table.sql
index aa937fb457..52ef793d56 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00001_select_table.sql
+++ b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00001_select_table.sql
@@ -1,28 +1,28 @@
-CREATE SCHEMA "test.lakehouse-iceberg".db2;
+CREATE SCHEMA "test.lakehouse-iceberg".gt_db2;
-CREATE TABLE "test.lakehouse-iceberg".db2.tb01 (
+CREATE TABLE "test.lakehouse-iceberg".gt_db2.tb01 (
name varchar,
salary int
);
-insert into "test.lakehouse-iceberg".db2.tb01(name, salary) values ('sam', 11);
-insert into "test.lakehouse-iceberg".db2.tb01(name, salary) values ('jerry', 13);
-insert into "test.lakehouse-iceberg".db2.tb01(name, salary) values ('bob', 14), ('tom', 12);
+insert into "test.lakehouse-iceberg".gt_db2.tb01(name, salary) values ('sam', 11);
+insert into "test.lakehouse-iceberg".gt_db2.tb01(name, salary) values ('jerry', 13);
+insert into "test.lakehouse-iceberg".gt_db2.tb01(name, salary) values ('bob', 14), ('tom', 12);
-select distinct * from "test.lakehouse-iceberg".db2.tb01 order by name;
+select * from "test.lakehouse-iceberg".gt_db2.tb01 order by name;
-CREATE TABLE "test.lakehouse-iceberg".db2.tb02 (
+CREATE TABLE "test.lakehouse-iceberg".gt_db2.tb02 (
name varchar,
salary int
);
-insert into "test.lakehouse-iceberg".db2.tb02(name, salary) select distinct * from "test.lakehouse-iceberg".db2.tb01 order by name;
+insert into "test.lakehouse-iceberg".gt_db2.tb02(name, salary) select distinct * from "test.lakehouse-iceberg".gt_db2.tb01 order by name;
-select distinct * from "test.lakehouse-iceberg".db2.tb02 order by name;
+select * from "test.lakehouse-iceberg".gt_db2.tb02 order by name;
-drop table "test.lakehouse-iceberg".db2.tb02;
+drop table "test.lakehouse-iceberg".gt_db2.tb02;
-drop table "test.lakehouse-iceberg".db2.tb01;
+drop table "test.lakehouse-iceberg".gt_db2.tb01;
-drop schema "test.lakehouse-iceberg".db2;
+drop schema "test.lakehouse-iceberg".gt_db2;
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.sql b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.sql
index 3a41a06047..cc68418787 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.sql
+++ b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.sql
@@ -1,32 +1,35 @@
-CREATE SCHEMA "test.lakehouse-iceberg".db2;
+CREATE SCHEMA "test.lakehouse-iceberg".gt_db2;
-CREATE TABLE "test.lakehouse-iceberg".db2.tb01 (
+CREATE TABLE "test.lakehouse-iceberg".gt_db2.tb01 (
name varchar,
salary int,
city int
);
-alter table "test.lakehouse-iceberg".db2.tb01 rename to "test.lakehouse-iceberg".db2.tb03;
-show tables from "test.lakehouse-iceberg".db2;
+alter table "test.lakehouse-iceberg".gt_db2.tb01 rename to "test.lakehouse-iceberg".gt_db2.tb03;
+show tables from "test.lakehouse-iceberg".gt_db2;
-alter table "test.lakehouse-iceberg".db2.tb03 rename to "test.lakehouse-iceberg".db2.tb01;
-show tables from "test.lakehouse-iceberg".db2;
+alter table "test.lakehouse-iceberg".gt_db2.tb03 rename to "test.lakehouse-iceberg".gt_db2.tb01;
+show tables from "test.lakehouse-iceberg".gt_db2;
-alter table "test.lakehouse-iceberg".db2.tb01 drop column city;
-show create table "test.lakehouse-iceberg".db2.tb01;
+alter table "test.lakehouse-iceberg".gt_db2.tb01 drop column city;
+show create table "test.lakehouse-iceberg".gt_db2.tb01;
-alter table "test.lakehouse-iceberg".db2.tb01 rename column name to s;
-show create table "test.lakehouse-iceberg".db2.tb01;
+alter table "test.lakehouse-iceberg".gt_db2.tb01 rename column name to s;
+show create table "test.lakehouse-iceberg".gt_db2.tb01;
-alter table "test.lakehouse-iceberg".db2.tb01 alter column salary set data type bigint;
-show create table "test.lakehouse-iceberg".db2.tb01;
+alter table "test.lakehouse-iceberg".gt_db2.tb01 alter column salary set data type bigint;
+show create table "test.lakehouse-iceberg".gt_db2.tb01;
-comment on table "test.lakehouse-iceberg".db2.tb01 is 'test table comments';
-show create table "test.lakehouse-iceberg".db2.tb01;
+comment on table "test.lakehouse-iceberg".gt_db2.tb01 is 'test table comments';
+show create table "test.lakehouse-iceberg".gt_db2.tb01;
-comment on column "test.lakehouse-iceberg".db2.tb01.s is 'test column comments';
-show create table "test.lakehouse-iceberg".db2.tb01;
+comment on column "test.lakehouse-iceberg".gt_db2.tb01.s is 'test column comments';
+show create table "test.lakehouse-iceberg".gt_db2.tb01;
-drop table "test.lakehouse-iceberg".db2.tb01;
+alter table "test.lakehouse-iceberg".gt_db2.tb01 add column city varchar comment 'aaa';
+show create table "test.lakehouse-iceberg".gt_db2.tb01;
-drop schema "test.lakehouse-iceberg".db2;
+drop table "test.lakehouse-iceberg".gt_db2.tb01;
+
+drop schema "test.lakehouse-iceberg".gt_db2;
diff --git a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.txt b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.txt
index 34204dd423..98c5821ec4 100644
--- a/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.txt
+++ b/integration-test/src/test/resources/trino-queries/catalogs/lakehouse-iceberg/00002_alter_table.txt
@@ -12,7 +12,7 @@ RENAME TABLE
DROP COLUMN
-"CREATE TABLE ""test.lakehouse-iceberg"".db2.tb01 (
+"CREATE TABLE ""test.lakehouse-iceberg"".gt_db2.tb01 (
name varchar,
salary integer
)
@@ -20,7 +20,7 @@ COMMENT ''"
RENAME COLUMN
-"CREATE TABLE ""test.lakehouse-iceberg"".db2.tb01 (
+"CREATE TABLE ""test.lakehouse-iceberg"".gt_db2.tb01 (
s varchar,
salary integer
)
@@ -28,7 +28,7 @@ COMMENT ''"
SET COLUMN TYPE
-"CREATE TABLE ""test.lakehouse-iceberg"".db2.tb01 (
+"CREATE TABLE ""test.lakehouse-iceberg"".gt_db2.tb01 (
s varchar,
salary bigint
)
@@ -36,7 +36,7 @@ COMMENT ''"
COMMENT
-"CREATE TABLE ""test.lakehouse-iceberg"".db2.tb01 (
+"CREATE TABLE ""test.lakehouse-iceberg"".gt_db2.tb01 (
s varchar,
salary bigint
)
@@ -44,12 +44,21 @@ COMMENT 'test table comments'"
COMMENT
-"CREATE TABLE ""test.lakehouse-iceberg"".db2.tb01 (
+"CREATE TABLE ""test.lakehouse-iceberg"".gt_db2.tb01 (
s varchar COMMENT 'test column comments',
salary bigint
)
COMMENT 'test table comments'"
+ADD COLUMN
+
+"CREATE TABLE ""test.lakehouse-iceberg"".gt_db2.tb01 (
+ s varchar COMMENT 'test column comments',
+ salary bigint,
+ city varchar COMMENT 'aaa'
+)
+COMMENT 'test table comments'"
+
DROP TABLE
DROP SCHEMA
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoConnector.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoConnector.java
index 61b07b894c..5bb4cf4098 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoConnector.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoConnector.java
@@ -15,6 +15,7 @@ import io.trino.spi.connector.ConnectorAccessControl;
import io.trino.spi.connector.ConnectorMetadata;
import io.trino.spi.connector.ConnectorPageSinkProvider;
import io.trino.spi.connector.ConnectorPageSourceProvider;
+import io.trino.spi.connector.ConnectorRecordSetProvider;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.ConnectorSplitManager;
import io.trino.spi.connector.ConnectorTransactionHandle;
@@ -107,6 +108,13 @@ public class GravitinoConnector implements Connector {
return new GravitinoDataSourceProvider(internalPageSourceProvider);
}
+ @Override
+ public ConnectorRecordSetProvider getRecordSetProvider() {
+ Connector internalConnector = catalogConnectorContext.getInternalConnector();
+ ConnectorRecordSetProvider internalRecordSetProvider = internalConnector.getRecordSetProvider();
+ return new GravitinoRecordSetProvider(internalRecordSetProvider);
+ }
+
@Override
public ConnectorPageSinkProvider getPageSinkProvider() {
Connector internalConnector = catalogConnectorContext.getInternalConnector();
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoMetadata.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoMetadata.java
index 277f9e577a..9f8b564fc0 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoMetadata.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoMetadata.java
@@ -4,6 +4,8 @@
*/
package com.datastrato.gravitino.trino.connector;
+import static com.datastrato.gravitino.trino.connector.GravitinoErrorCode.GRAVITINO_TABLE_NOT_EXISTS;
+
import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorMetadata;
import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorMetadataAdapter;
import com.datastrato.gravitino.trino.connector.metadata.GravitinoColumn;
@@ -13,6 +15,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.airlift.slice.Slice;
+import io.trino.spi.TrinoException;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ColumnMetadata;
import io.trino.spi.connector.ConnectorInsertTableHandle;
@@ -82,6 +85,12 @@ public class GravitinoMetadata implements ConnectorMetadata {
ConnectorTableHandle internalTableHandle =
internalMetadata.getTableHandle(session, tableName, startVersion, endVersion);
+
+ if (internalTableHandle == null) {
+ throw new TrinoException(
+ GRAVITINO_TABLE_NOT_EXISTS,
+ String.format("Table %s does not exist in the internal connector", tableName));
+ }
return new GravitinoTableHandle(
tableName.getSchemaName(), tableName.getTableName(), internalTableHandle);
}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoRecordSetProvider.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoRecordSetProvider.java
new file mode 100644
index 0000000000..020c034611
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/GravitinoRecordSetProvider.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.trino.connector;
+
+import io.trino.spi.connector.ColumnHandle;
+import io.trino.spi.connector.ConnectorRecordSetProvider;
+import io.trino.spi.connector.ConnectorSession;
+import io.trino.spi.connector.ConnectorSplit;
+import io.trino.spi.connector.ConnectorTableHandle;
+import io.trino.spi.connector.ConnectorTransactionHandle;
+import io.trino.spi.connector.RecordSet;
+import java.util.ArrayList;
+import java.util.List;
+
+/** This class provides a RecordSet for trino read data from internal connector. */
+public class GravitinoRecordSetProvider implements ConnectorRecordSetProvider {
+
+ ConnectorRecordSetProvider internalRecordSetProvider;
+
+ public GravitinoRecordSetProvider(ConnectorRecordSetProvider recordSetProvider) {
+ this.internalRecordSetProvider = recordSetProvider;
+ }
+
+ @Override
+ public RecordSet getRecordSet(
+ ConnectorTransactionHandle transaction,
+ ConnectorSession session,
+ ConnectorSplit split,
+ ConnectorTableHandle table,
+ List<? extends ColumnHandle> columns) {
+ if (!(table instanceof GravitinoTableHandle)) {
+ return internalRecordSetProvider.getRecordSet(transaction, session, split, table, columns);
+ }
+ GravitinoTableHandle gravitinoTableHandle = (GravitinoTableHandle) table;
+ GravitinoTransactionHandle gravitinoTransactionHandle =
+ (GravitinoTransactionHandle) transaction;
+ List<ColumnHandle> internalHandles = new ArrayList<>();
+ for (ColumnHandle column : columns) {
+ internalHandles.add(((GravitinoColumnHandle) column).getInternalColumnHandler());
+ }
+ return internalRecordSetProvider.getRecordSet(
+ gravitinoTransactionHandle.getInternalTransactionHandle(),
+ session,
+ split,
+ gravitinoTableHandle.getInternalTableHandle(),
+ internalHandles);
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorAdapter.java
index 3107e44254..d3f5050adc 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorAdapter.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorAdapter.java
@@ -22,7 +22,7 @@ public interface CatalogConnectorAdapter {
}
/** @return Return internal connector config with trino. */
- Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog);
+ Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog) throws Exception;
/** @return SchemaProperties list that used to validate schema properties. */
default List<PropertyMetadata<?>> getSchemaProperties() {
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorContext.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorContext.java
index 54db49cdb5..c0794f8766 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorContext.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorContext.java
@@ -91,7 +91,7 @@ public class CatalogConnectorContext {
return new Builder(connectorAdapter);
}
- public Map<String, Object> buildConfig(GravitinoCatalog catalog) {
+ public Map<String, Object> buildConfig(GravitinoCatalog catalog) throws Exception {
return connectorAdapter.buildInternalConnectorConfig(catalog);
}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorFactory.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorFactory.java
index ecdf03c537..db9c3b4ab0 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorFactory.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/CatalogConnectorFactory.java
@@ -12,6 +12,8 @@ import com.datastrato.gravitino.client.GravitinoMetaLake;
import com.datastrato.gravitino.trino.connector.catalog.hive.HiveConnectorAdapter;
import com.datastrato.gravitino.trino.connector.catalog.iceberg.IcebergConnectorAdapter;
import com.datastrato.gravitino.trino.connector.catalog.memory.MemoryConnectorAdapter;
+import com.datastrato.gravitino.trino.connector.catalog.mysql.MySQLConnectorAdapter;
+import com.datastrato.gravitino.trino.connector.catalog.postgresql.PostgreSQLConnectorAdapter;
import com.datastrato.gravitino.trino.connector.metadata.GravitinoCatalog;
import io.trino.spi.TrinoException;
import io.trino.spi.connector.Connector;
@@ -34,6 +36,10 @@ public class CatalogConnectorFactory {
"memory", new CatalogConnectorContext.Builder(new MemoryConnectorAdapter()));
catalogBuilders.put(
"lakehouse-iceberg", new CatalogConnectorContext.Builder(new IcebergConnectorAdapter()));
+ catalogBuilders.put(
+ "jdbc-mysql", new CatalogConnectorContext.Builder(new MySQLConnectorAdapter()));
+ catalogBuilders.put(
+ "jdbc-postgresql", new CatalogConnectorContext.Builder(new PostgreSQLConnectorAdapter()));
}
public CatalogConnectorContext loadCatalogConnector(
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveConnectorAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveConnectorAdapter.java
index 80bb3b273b..10e7f0ad54 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveConnectorAdapter.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveConnectorAdapter.java
@@ -30,13 +30,14 @@ public class HiveConnectorAdapter implements CatalogConnectorAdapter {
this.catalogConverter = new HiveCatalogPropertyConverter();
}
- public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog) {
+ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog)
+ throws Exception {
Map<String, Object> config = new HashMap<>();
config.put("catalogHandle", catalog.getName() + ":normal:default");
config.put("connectorName", "hive");
Map<String, Object> properties = new HashMap<>();
- properties.put("hive.metastore.uri", catalog.getProperties("metastore.uris", ""));
+ properties.put("hive.metastore.uri", catalog.getRequiredProperty("metastore.uris"));
Map<String, String> trinoProperty = catalogConverter.toTrinoProperties(catalog.getProperties());
// Trino only supports properties that define in catalogPropertyMeta, the name of entries in
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HivePropertyMeta.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HivePropertyMeta.java
index 0bb5a907c2..eaeb970996 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HivePropertyMeta.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HivePropertyMeta.java
@@ -39,7 +39,6 @@ public class HivePropertyMeta implements HasPropertyMeta {
"The output format class for the table",
"org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
false),
- stringProperty("transient_last_ddl_time", "Last DDL time", null, false),
stringProperty(
"serde_lib",
"The serde library class for the table",
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveTablePropertyConverter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveTablePropertyConverter.java
index 6bd4f0c460..cbb2003e69 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveTablePropertyConverter.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/hive/HiveTablePropertyConverter.java
@@ -28,7 +28,6 @@ public class HiveTablePropertyConverter implements PropertyConverter {
.put("table_type", "table-type")
.put("input_format", "input-format")
.put("output_format", "output-format")
- .put("transient_last_ddl_time", "transient_lastDdlTime")
.put("serde_lib", "serde-lib")
.put("serde_name", "serde-name")
.build());
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/iceberg/IcebergConnectorAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/iceberg/IcebergConnectorAdapter.java
index 6be3b4c0a1..2454629b9b 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/iceberg/IcebergConnectorAdapter.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/iceberg/IcebergConnectorAdapter.java
@@ -15,18 +15,17 @@ import java.util.Map;
/** Transforming Iceberg connector configuration and components into Gravitino connector. */
public class IcebergConnectorAdapter implements CatalogConnectorAdapter {
- // private final HiveTableProperties tableProperties =
-
public IcebergConnectorAdapter() {}
- public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog) {
+ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog)
+ throws Exception {
Map<String, Object> config = new HashMap<>();
config.put("catalogHandle", catalog.getName() + ":normal:default");
config.put("connectorName", "iceberg");
Map<String, Object> properties = new HashMap<>();
properties.put("iceberg.catalog.type", "hive_metastore");
- properties.put("hive.metastore.uri", catalog.getProperties("uri", ""));
+ properties.put("hive.metastore.uri", catalog.getRequiredProperty("uri"));
config.put("properties", properties);
return config;
}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLConnectorAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLConnectorAdapter.java
new file mode 100644
index 0000000000..f7682e0b49
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLConnectorAdapter.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.trino.connector.catalog.mysql;
+
+import static java.util.Collections.emptyList;
+
+import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorAdapter;
+import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorMetadataAdapter;
+import com.datastrato.gravitino.trino.connector.metadata.GravitinoCatalog;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Transforming MySQL connector configuration and components into Gravitino connector. */
+public class MySQLConnectorAdapter implements CatalogConnectorAdapter {
+
+ public MySQLConnectorAdapter() {}
+
+ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog)
+ throws Exception {
+ Map<String, Object> config = new HashMap<>();
+ config.put("catalogHandle", catalog.getName() + ":normal:default");
+ config.put("connectorName", "mysql");
+
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("connection-url", catalog.getRequiredProperty("gravitino.bypass.jdbc-url"));
+ properties.put("connection-user", catalog.getRequiredProperty("gravitino.bypass.jdbc-user"));
+ properties.put(
+ "connection-password", catalog.getRequiredProperty("gravitino.bypass.jdbc-password"));
+ config.put("properties", properties);
+ return config;
+ }
+
+ public CatalogConnectorMetadataAdapter getMetadataAdapter() {
+ // TODO yuhui Need to improve schema table and column properties
+ return new MySQLMetadataAdapter(getSchemaProperties(), getTableProperties(), emptyList());
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLDataTypeTransformer.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLDataTypeTransformer.java
new file mode 100644
index 0000000000..ab5b09bbfc
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLDataTypeTransformer.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.trino.connector.catalog.mysql;
+
+import com.datastrato.gravitino.rel.types.Type;
+import com.datastrato.gravitino.rel.types.Type.Name;
+import com.datastrato.gravitino.rel.types.Types;
+import com.datastrato.gravitino.trino.connector.util.GeneralDataTypeTransformer;
+
+/** Type transformer between MySQL and Trino */
+public class MySQLDataTypeTransformer extends GeneralDataTypeTransformer {
+
+ @Override
+ public Type getGravitinoType(io.trino.spi.type.Type type) {
+ Type gravitinoType = super.getGravitinoType(type);
+ if (gravitinoType.name() == Name.VARCHAR || gravitinoType.name() == Name.FIXEDCHAR) {
+ return Types.StringType.get();
+ }
+ return gravitinoType;
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLMetadataAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLMetadataAdapter.java
new file mode 100644
index 0000000000..546aee032f
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/mysql/MySQLMetadataAdapter.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.trino.connector.catalog.mysql;
+
+import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorMetadataAdapter;
+import io.trino.spi.session.PropertyMetadata;
+import java.util.List;
+
+/** Transforming gravitino MySQL metadata to trino. */
+public class MySQLMetadataAdapter extends CatalogConnectorMetadataAdapter {
+
+ public MySQLMetadataAdapter(
+ List<PropertyMetadata<?>> schemaProperties,
+ List<PropertyMetadata<?>> tableProperties,
+ List<PropertyMetadata<?>> columnProperties) {
+
+ super(schemaProperties, tableProperties, columnProperties, new MySQLDataTypeTransformer());
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLConnectorAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLConnectorAdapter.java
new file mode 100644
index 0000000000..a28f7f9bd8
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLConnectorAdapter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.trino.connector.catalog.postgresql;
+
+import static java.util.Collections.emptyList;
+
+import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorAdapter;
+import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorMetadataAdapter;
+import com.datastrato.gravitino.trino.connector.metadata.GravitinoCatalog;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Transforming PostgreSQL connector configuration and components into Gravitino connector. */
+public class PostgreSQLConnectorAdapter implements CatalogConnectorAdapter {
+
+ public PostgreSQLConnectorAdapter() {}
+
+ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog)
+ throws Exception {
+ Map<String, Object> config = new HashMap<>();
+ config.put("catalogHandle", catalog.getName() + ":normal:default");
+ config.put("connectorName", "postgresql");
+
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("connection-url", catalog.getRequiredProperty("jdbc-url"));
+ properties.put("connection-user", catalog.getRequiredProperty("jdbc-user"));
+ properties.put("connection-password", catalog.getRequiredProperty("jdbc-password"));
+ config.put("properties", properties);
+ return config;
+ }
+
+ public CatalogConnectorMetadataAdapter getMetadataAdapter() {
+ // TODO yuhui Need to improve schema table and column properties
+ return new PostgreSQLMetadataAdapter(getSchemaProperties(), getTableProperties(), emptyList());
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLDataTypeTransformer.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLDataTypeTransformer.java
new file mode 100644
index 0000000000..f02771b77f
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLDataTypeTransformer.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+
+package com.datastrato.gravitino.trino.connector.catalog.postgresql;
+
+import com.datastrato.gravitino.rel.types.Type;
+import com.datastrato.gravitino.rel.types.Type.Name;
+import com.datastrato.gravitino.rel.types.Types;
+import com.datastrato.gravitino.trino.connector.util.GeneralDataTypeTransformer;
+
+/** Type transformer between PostgreSQL and Trino */
+public class PostgreSQLDataTypeTransformer extends GeneralDataTypeTransformer {
+
+ @Override
+ public Type getGravitinoType(io.trino.spi.type.Type type) {
+ Type gravitinoType = super.getGravitinoType(type);
+ if (gravitinoType.name() == Name.VARCHAR || gravitinoType.name() == Name.FIXEDCHAR) {
+ return Types.StringType.get();
+ }
+ return gravitinoType;
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLMetadataAdapter.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLMetadataAdapter.java
new file mode 100644
index 0000000000..882b9f5399
--- /dev/null
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/catalog/postgresql/PostgreSQLMetadataAdapter.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2023 Datastrato.
+ * This software is licensed under the Apache License version 2.
+ */
+package com.datastrato.gravitino.trino.connector.catalog.postgresql;
+
+import com.datastrato.gravitino.trino.connector.catalog.CatalogConnectorMetadataAdapter;
+import io.trino.spi.session.PropertyMetadata;
+import java.util.List;
+
+/** Transforming gravitino PostgreSQL metadata to trino. */
+public class PostgreSQLMetadataAdapter extends CatalogConnectorMetadataAdapter {
+
+ public PostgreSQLMetadataAdapter(
+ List<PropertyMetadata<?>> schemaProperties,
+ List<PropertyMetadata<?>> tableProperties,
+ List<PropertyMetadata<?>> columnProperties) {
+
+ super(schemaProperties, tableProperties, columnProperties, new PostgreSQLDataTypeTransformer());
+ }
+}
diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java
index acd59c4d9b..fe3a52d090 100644
--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java
+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/metadata/GravitinoCatalog.java
@@ -4,8 +4,12 @@
*/
package com.datastrato.gravitino.trino.connector.metadata;
+import static com.datastrato.gravitino.trino.connector.GravitinoErrorCode.GRAVITINO_MISSING_CONFIG;
+
import com.datastrato.gravitino.Catalog;
+import io.trino.spi.TrinoException;
import java.util.Map;
+import org.apache.logging.log4j.util.Strings;
/** Help Gravitino connector access CatalogMetadata from gravitino client. */
public class GravitinoCatalog {
@@ -24,10 +28,18 @@ public class GravitinoCatalog {
return catalog.name();
}
- public String getProperties(String name, String defaultValue) {
+ public String getProperty(String name, String defaultValue) {
return catalog.properties().getOrDefault(name, defaultValue);
}
+ public String getRequiredProperty(String name) throws Exception {
+ String value = catalog.properties().getOrDefault(name, "");
+ if (Strings.isBlank(value)) {
+ throw new TrinoException(GRAVITINO_MISSING_CONFIG, "Missing required config: " + name);
+ }
+ return value;
+ }
+
public Map<String, String> getProperties() {
return catalog.properties();
}