World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1449] fix(jdbc-postgres): audit info is empty (#1716)
FANNG81b624a5557d
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.javaindex c873a26005..0d05f91990 100644--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java@@ -208,12 +208,11 @@ public class JdbcCatalogOperations implements CatalogOperations, SupportsSchemas}Map<String, String> properties =load.properties() == null ? Maps.newHashMap() : Maps.newHashMap(load.properties());- StringIdentifier.newPropertiesWithId(id, properties);return new JdbcSchema.Builder().withAuditInfo(load.auditInfo()).withName(load.name()).withComment(StringIdentifier.removeIdFromComment(load.comment()))- .withProperties(properties)+ .withProperties(StringIdentifier.newPropertiesWithId(id, properties)).build();}diff --git a/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java b/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.javaindex d9b90d5f90..b35213ad77 100644--- a/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java+++ b/catalogs/catalog-jdbc-postgresql/src/main/java/com/datastrato/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java@@ -39,6 +39,9 @@ public class PostgreSqlSchemaOperations extends JdbcDatabaseOperations {}});+ private static final String GET_SCHEMA_COMMENT_SQL_FORMAT =+ "SELECT obj_description('%s'::regnamespace) as comment";+private String database;@Override@@ -61,8 +64,10 @@ public class PostgreSqlSchemaOperations extends JdbcDatabaseOperations {throw new NoSuchSchemaException("No such schema: " + schema);}String schemaName = resultSet.getString(1);+ String comment = getSchemaComment(schema, connection);return new JdbcSchema.Builder().withName(schemaName)+ .withComment(comment).withAuditInfo(AuditInfo.EMPTY).withProperties(Collections.emptyMap()).build();@@ -135,4 +140,20 @@ public class PostgreSqlSchemaOperations extends JdbcDatabaseOperations {protected boolean isSystemDatabase(String dbName) {return SYS_PG_DATABASE_NAMES.contains(dbName.toLowerCase(Locale.ROOT));}++ private String getShowSchemaCommentSql(String schema) {+ return String.format(GET_SCHEMA_COMMENT_SQL_FORMAT, schema);+ }++ private String getSchemaComment(String schema, Connection connection) throws SQLException {+ try (PreparedStatement preparedStatement =+ connection.prepareStatement(getShowSchemaCommentSql(schema))) {+ try (ResultSet resultSet = preparedStatement.executeQuery()) {+ if (resultSet.next()) {+ return resultSet.getString("comment");+ }+ }+ }+ return null;+ }}diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/jdbc/postgresql/CatalogPostgreSqlIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/jdbc/postgresql/CatalogPostgreSqlIT.javaindex 673767f3bc..fc25464260 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/jdbc/postgresql/CatalogPostgreSqlIT.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/jdbc/postgresql/CatalogPostgreSqlIT.java@@ -43,6 +43,7 @@ import java.util.Map;import java.util.Optional;import java.util.Set;import java.util.stream.Collectors;+import org.datanucleus.util.StringUtils;import org.junit.jupiter.api.AfterAll;import org.junit.jupiter.api.AfterEach;import org.junit.jupiter.api.Assertions;@@ -526,4 +527,29 @@ public class CatalogPostgreSqlIT extends AbstractIT {catalog.asTableCatalog().dropTable(tableIdentifier);});}++ @Test+ void testCreateAndLoadSchema() {+ String testSchemaName = "test";+ NameIdentifier ident = NameIdentifier.of(metalakeName, catalogName, testSchemaName);++ Schema schema = catalog.asSchemas().createSchema(ident, "comment", null);+ Assertions.assertEquals("anonymous", schema.auditInfo().creator());+ Assertions.assertEquals("comment", schema.comment());+ schema = catalog.asSchemas().loadSchema(ident);+ Assertions.assertEquals("anonymous", schema.auditInfo().creator());+ Assertions.assertEquals("comment", schema.comment());++ // test null comment+ testSchemaName = "test2";+ ident = NameIdentifier.of(metalakeName, catalogName, testSchemaName);++ schema = catalog.asSchemas().createSchema(ident, null, null);+ Assertions.assertEquals("anonymous", schema.auditInfo().creator());+ // todo: Gravitino put id to comment, makes comment is empty string not null.+ Assertions.assertTrue(StringUtils.isEmpty(schema.comment()));+ schema = catalog.asSchemas().loadSchema(ident);+ Assertions.assertEquals("anonymous", schema.auditInfo().creator());+ Assertions.assertTrue(StringUtils.isEmpty(schema.comment()));+ }}