TimothyDing commented on code in PR #10068:
URL: https://github.com/apache/gravitino/pull/10068#discussion_r2898495093


##########
catalogs-contrib/catalog-jdbc-hologres/src/main/java/org/apache/gravitino/catalog/hologres/operation/HologresTableOperations.java:
##########
@@ -34,17 +68,123 @@
  * <p>Hologres is PostgreSQL-compatible, so most table operations follow 
PostgreSQL conventions.
  * However, Hologres has specific features like table properties (orientation, 
distribution_key,
  * etc.) that are handled through the WITH clause in CREATE TABLE statements.
- *
- * <p>TODO: Full implementation will be added in a follow-up PR.
  */
 public class HologresTableOperations extends JdbcTableOperations
     implements RequireDatabaseOperation {
 
-  public static final String HOLO_QUOTE = "\"";
+  public static final String NEW_LINE = "\n";
+  public static final String ALTER_TABLE = "ALTER TABLE ";
+  public static final String ALTER_COLUMN = "ALTER COLUMN ";
+  public static final String IS = " IS '";
+  public static final String COLUMN_COMMENT = "COMMENT ON COLUMN ";
+  public static final String TABLE_COMMENT = "COMMENT ON TABLE ";
+
+  private static final String HOLOGRES_NOT_SUPPORT_NESTED_COLUMN_MSG =
+      "Hologres does not support nested column names.";
+
+  /** Properties that are handled separately or read-only, excluded from the 
WITH clause. */
+  private static final Set<String> EXCLUDED_TABLE_PROPERTIES =
+      ImmutableSet.of("distribution_key", "is_logical_partitioned_table", 
"primary_key");
+
+  /** Properties that are meaningful for users, filtering out internal system 
properties. */
+  private static final Set<String> USER_RELEVANT_PROPERTIES =
+      ImmutableSet.of(
+          "orientation",
+          "clustering_key",
+          "segment_key",
+          "bitmap_columns",
+          "dictionary_encoding_columns",
+          "time_to_live_in_seconds",
+          "table_group",
+          "storage_format",
+          "binlog.level",
+          "binlog.ttl",
+          "is_logical_partitioned_table",
+          "partition_expiration_time",
+          "partition_keep_hot_window",
+          "partition_require_filter",
+          "partition_generate_binlog_window");
+
+  private String database;
+  private HologresSchemaOperations schemaOperations;
+
+  @Override
+  protected String quoteIdentifier(String identifier) {
+    return "\"" + identifier + "\"";
+  }
+
+  @Override
+  public void initialize(
+      DataSource dataSource,
+      JdbcExceptionConverter exceptionMapper,
+      JdbcTypeConverter jdbcTypeConverter,
+      JdbcColumnDefaultValueConverter jdbcColumnDefaultValueConverter,
+      Map<String, String> conf) {
+    super.initialize(
+        dataSource, exceptionMapper, jdbcTypeConverter, 
jdbcColumnDefaultValueConverter, conf);
+    database = new JdbcConfig(conf).getJdbcDatabase();
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(database),
+        "The `jdbc-database` configuration item is mandatory in Hologres.");
+  }
 
   @Override
   public void setDatabaseOperation(DatabaseOperation databaseOperation) {
-    // Will be implemented in a follow-up PR.
+    this.schemaOperations = (HologresSchemaOperations) databaseOperation;
+  }
+
+  @Override
+  public List<String> listTables(String schemaName) throws 
NoSuchSchemaException {
+    try (Connection connection = getConnection(schemaName)) {
+      if (!schemaOperations.schemaExists(connection, schemaName)) {
+        throw new NoSuchSchemaException("No such schema: %s", schemaName);
+      }
+      final List<String> names = Lists.newArrayList();
+      try (ResultSet tables = getTables(connection)) {
+        while (tables.next()) {
+          if (Objects.equals(tables.getString("TABLE_SCHEM"), schemaName)) {
+            names.add(tables.getString("TABLE_NAME"));
+          }
+        }
+      }
+      LOG.info("Finished listing tables size {} for schema name {} ", 
names.size(), schemaName);
+      return names;
+    } catch (final SQLException se) {
+      throw this.exceptionMapper.toGravitinoException(se);
+    }
+  }
+
+  @Override
+  protected JdbcTable.Builder getTableBuilder(
+      ResultSet tablesResult, String databaseName, String tableName) throws 
SQLException {
+    boolean found = false;
+    JdbcTable.Builder builder = null;
+    while (tablesResult.next() && !found) {
+      String tableNameInResult = tablesResult.getString("TABLE_NAME");
+      String tableSchemaInResultLowerCase = 
tablesResult.getString("TABLE_SCHEM");

Review Comment:
   fix in fb5f29057eb1f582123a8e3b5e6dbe070a2ed064



##########
catalogs-contrib/catalog-jdbc-hologres/src/main/java/org/apache/gravitino/catalog/hologres/operation/HologresTableOperations.java:
##########
@@ -34,17 +68,123 @@
  * <p>Hologres is PostgreSQL-compatible, so most table operations follow 
PostgreSQL conventions.
  * However, Hologres has specific features like table properties (orientation, 
distribution_key,
  * etc.) that are handled through the WITH clause in CREATE TABLE statements.
- *
- * <p>TODO: Full implementation will be added in a follow-up PR.
  */
 public class HologresTableOperations extends JdbcTableOperations
     implements RequireDatabaseOperation {
 
-  public static final String HOLO_QUOTE = "\"";
+  public static final String NEW_LINE = "\n";
+  public static final String ALTER_TABLE = "ALTER TABLE ";
+  public static final String ALTER_COLUMN = "ALTER COLUMN ";
+  public static final String IS = " IS '";
+  public static final String COLUMN_COMMENT = "COMMENT ON COLUMN ";
+  public static final String TABLE_COMMENT = "COMMENT ON TABLE ";
+
+  private static final String HOLOGRES_NOT_SUPPORT_NESTED_COLUMN_MSG =
+      "Hologres does not support nested column names.";
+
+  /** Properties that are handled separately or read-only, excluded from the 
WITH clause. */
+  private static final Set<String> EXCLUDED_TABLE_PROPERTIES =
+      ImmutableSet.of("distribution_key", "is_logical_partitioned_table", 
"primary_key");
+
+  /** Properties that are meaningful for users, filtering out internal system 
properties. */
+  private static final Set<String> USER_RELEVANT_PROPERTIES =
+      ImmutableSet.of(
+          "orientation",
+          "clustering_key",
+          "segment_key",
+          "bitmap_columns",
+          "dictionary_encoding_columns",
+          "time_to_live_in_seconds",
+          "table_group",
+          "storage_format",
+          "binlog.level",
+          "binlog.ttl",
+          "is_logical_partitioned_table",
+          "partition_expiration_time",
+          "partition_keep_hot_window",
+          "partition_require_filter",
+          "partition_generate_binlog_window");
+
+  private String database;
+  private HologresSchemaOperations schemaOperations;
+
+  @Override
+  protected String quoteIdentifier(String identifier) {
+    return "\"" + identifier + "\"";
+  }
+
+  @Override
+  public void initialize(
+      DataSource dataSource,
+      JdbcExceptionConverter exceptionMapper,
+      JdbcTypeConverter jdbcTypeConverter,
+      JdbcColumnDefaultValueConverter jdbcColumnDefaultValueConverter,
+      Map<String, String> conf) {
+    super.initialize(
+        dataSource, exceptionMapper, jdbcTypeConverter, 
jdbcColumnDefaultValueConverter, conf);
+    database = new JdbcConfig(conf).getJdbcDatabase();
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(database),
+        "The `jdbc-database` configuration item is mandatory in Hologres.");
+  }
 
   @Override
   public void setDatabaseOperation(DatabaseOperation databaseOperation) {
-    // Will be implemented in a follow-up PR.
+    this.schemaOperations = (HologresSchemaOperations) databaseOperation;
+  }
+
+  @Override
+  public List<String> listTables(String schemaName) throws 
NoSuchSchemaException {
+    try (Connection connection = getConnection(schemaName)) {
+      if (!schemaOperations.schemaExists(connection, schemaName)) {
+        throw new NoSuchSchemaException("No such schema: %s", schemaName);
+      }
+      final List<String> names = Lists.newArrayList();
+      try (ResultSet tables = getTables(connection)) {
+        while (tables.next()) {
+          if (Objects.equals(tables.getString("TABLE_SCHEM"), schemaName)) {
+            names.add(tables.getString("TABLE_NAME"));
+          }
+        }
+      }
+      LOG.info("Finished listing tables size {} for schema name {} ", 
names.size(), schemaName);

Review Comment:
   fix in fb5f29057eb1f582123a8e3b5e6dbe070a2ed064



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to