Repository: apache/gravitino (Java)

Issue:
[Bug report] Test cases in  jdbc-mysql/00008_alter_catalog.sql failed on distributed Trino environment
### Version

main branch

### Describe what's wrong

<img width="1465" alt="image" src="https://github.com/datastrato/gravitino/assets/154112360/e323c4d9-71e6-42f7-acff-5f347bb67fab">


### Error message and/or stacktrace

2024-05-30 15:41:17 ERROR [pool-2-thread-1] TrinoQueryIT:225 - Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

Failed to execute test org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
java.lang.RuntimeException: Failed to execute test org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

        at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.waitForCompleted(TrinoQueryIT.java:342)
        at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.testSql(TrinoQueryIT.java:329)
        at com.datastrato.gravitino.integration.test.trino.TrinoQueryTestTool.main(TrinoQueryTestTool.java:175)
Caused by: java.util.concurrent.ExecutionException: org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.


### How to reproduce

1. Set up Trino distributed environment 
2. Run jdbc-mysql test set:
```
 ./gradlew :integration-test:TrinoTest '-PappArgs="--auto=none --test_set=jdbc-mysql --tester_id=00008 --postgresql_uri=jdbc:postgresql://pg-16-postgresql.relational-catalog:5432 --mysql_uri=jdbc:mysql://my-8-mysql.relational-catalog:3306 --hdfs_uri=hdfs://hadoop-hdfs-namenode.hadoop:8020 --hive_uri=thrift://hadoop-metastore.hadoop:9083 --gravitino_uri=http://a20b1e50807a547e1bf8187651d92e86-1205661208.ap-northeast-1.elb.amazonaws.com:8090 --trino_uri=http://af93449fcaf1a4c0e81068b736a36db4-1625278435.ap-northeast-1.elb.amazonaws.com:8080"'
```

### Additional context

_No response_


Discussion: @danhuawang It's still in the current version of gravitino-trino-connector 
> @danhuawang It's still in the current version of gravitino-trino-connector

Yes, the issue still exists in the latest version of gravitino-trino-connector.
```
2024-06-12 10:58:53 ERROR [pool-2-thread-1] TrinoQueryIT:225 - Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
java.lang.RuntimeException: Failed to execute test org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

Failed to execute test org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

	at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.waitForCompleted(TrinoQueryIT.java:342)
	at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.testSql(TrinoQueryIT.java:329)
	at com.datastrato.gravitino.integration.test.trino.TrinoQueryTestTool.main(TrinoQueryTestTool.java:175)
Caused by: java.util.concurrent.ExecutionException: org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.waitForCompleted(TrinoQueryIT.java:339)
	... 2 more
Caused by: org.opentest4j.AssertionFailedError: Execute sql in the tester jdbc-mysql/00008_alter_catalog.sql under catalog mysql failed.
Sql:
select * from gravitino.system.catalog where name = 'gt_mysql_xxx1';
Expect:
"gt_mysql_xxx1","jdbc-mysql","{""jdbc-url"":""jdbc:mysql://%/?useSSL=false"",""jdbc-user"":""trino"",""jdbc-password"":""ds123"",""jdbc-driver"":""com.mysql.cj.jdbc.Driver""}"
Actual:

	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)
	at org.junit.jupiter.api.Assertions.fail(Assertions.java:134)
	at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.executeSqlFileWithCheckResult(TrinoQueryIT.java:226)
	at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.runOneTestSetWithCatalog(TrinoQueryIT.java:116)
	at com.datastrato.gravitino.integration.test.trino.TrinoQueryIT.lambda$runOneTestset$5(TrinoQueryIT.java:364)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
```




Fix (patch):
diff --git a/trino-connector/src/main/java/org/apache/gravitino/trino/connector/system/table/GravitinoSystemTableCatalog.java b/trino-connector/src/main/java/org/apache/gravitino/trino/connector/system/table/GravitinoSystemTableCatalog.java
index 06d80f59f76..6d540d21d28 100644
--- a/trino-connector/src/main/java/org/apache/gravitino/trino/connector/system/table/GravitinoSystemTableCatalog.java
+++ b/trino-connector/src/main/java/org/apache/gravitino/trino/connector/system/table/GravitinoSystemTableCatalog.java
@@ -29,7 +29,11 @@
 import io.trino.spi.connector.ColumnMetadata;
 import io.trino.spi.connector.ConnectorTableMetadata;
 import io.trino.spi.connector.SchemaTableName;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.TreeMap;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.client.GravitinoMetalake;
 import org.apache.gravitino.trino.connector.GravitinoErrorCode;
 import org.apache.gravitino.trino.connector.catalog.CatalogConnectorManager;
 import org.apache.gravitino.trino.connector.metadata.GravitinoCatalog;
@@ -56,21 +60,36 @@ public GravitinoSystemTableCatalog(CatalogConnectorManager catalogConnectorManag
 
   @Override
   public Page loadPageData() {
-    List<GravitinoCatalog> catalogs = catalogConnectorManager.getCatalogs();
-    int size = catalogs.size();
+    List<GravitinoCatalog> gravitinoCatalogs = new ArrayList<>();
+    // retrieve catalogs form the Gravitino server with the configuration metalakes,
+    // the catalogConnectorManager does not manager catalogs in worker nodes
+    catalogConnectorManager
+        .getUsedMetalakes()
+        .forEach(
+            (metalakeName) -> {
+              GravitinoMetalake metalake = catalogConnectorManager.getMetalake(metalakeName);
+              Catalog[] catalogs = metalake.listCatalogsInfo();
+              for (Catalog catalog : catalogs) {
+                if (catalog.type() == Catalog.Type.RELATIONAL) {
+                  gravitinoCatalogs.add(new GravitinoCatalog(metalakeName, catalog));
+                }
+              }
+            });
+    int size = gravitinoCatalogs.size();
 
     BlockBuilder nameColumnBuilder = VARCHAR.createBlockBuilder(null, size);
     BlockBuilder providerColumnBuilder = VARCHAR.createBlockBuilder(null, size);
     BlockBuilder propertyColumnBuilder = VARCHAR.createBlockBuilder(null, size);
 
-    for (GravitinoCatalog catalog : catalogs) {
+    for (GravitinoCatalog catalog : gravitinoCatalogs) {
       Preconditions.checkNotNull(catalog, "catalog should not be null");
 
       VARCHAR.writeString(nameColumnBuilder, catalog.getName());
       VARCHAR.writeString(providerColumnBuilder, catalog.getProvider());
       try {
         VARCHAR.writeString(
-            propertyColumnBuilder, new ObjectMapper().writeValueAsString(catalog.getProperties()));
+            propertyColumnBuilder,
+            new ObjectMapper().writeValueAsString(new TreeMap<>(catalog.getProperties())));
       } catch (JsonProcessingException e) {
         throw new TrinoException(
             GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT, "Invalid property format", e); //