mchades commented on code in PR #4131:
URL: https://github.com/apache/gravitino/pull/4131#discussion_r1675383804
##########
catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -308,6 +311,22 @@ protected List<Index> getIndexes(Connection connection,
String databaseName, Str
}
}
+ @Override
+ protected Transform[] getTablePartitioning(
+ Connection connection, String databaseName, String tableName) throws
SQLException {
+ String showCreateTableSql = String.format("SHOW CREATE TABLE `%s`",
tableName);
+ try (Statement statement = connection.createStatement();
+ ResultSet result = statement.executeQuery(showCreateTableSql)) {
+ StringBuilder createTableSql = new StringBuilder();
+ while (result.next()) {
+ createTableSql.append(result.getString("Create Table"));
+ }
+ Optional<Transform> transform =
+ DorisUtils.extractPartitionInfoFromSql(createTableSql.toString());
Review Comment:
It seems more efficient to pass only the line containing the `PARTITION BY`
keyword to `DorisUtils.extractPartitionInfoFromSql` instead of concatenating
and splitting SQL lines.
##########
integration-test-common/src/test/java/com/datastrato/gravitino/integration/test/util/ITUtils.java:
##########
@@ -85,6 +86,7 @@ public static void assertionsTableInfo(
List<Column> columns,
Map<String, String> properties,
Index[] indexes,
+ Transform[] partitioning,
Review Comment:
we can add a new method to avoid some unnecessary changes of caller
##########
catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/utils/DorisUtils.java:
##########
@@ -65,4 +76,40 @@ public static Map<String, String>
extractPropertiesFromSql(String createTableSql
}
return properties;
}
+
+ public static Optional<Transform> extractPartitionInfoFromSql(String
createTableSql) {
+ try {
+ String[] lines = createTableSql.split("\n");
+ for (String line : lines) {
+ if (line.contains(PARTITION_BY)) {
Review Comment:
Since the syntax of the partition by statement is fixed, we can use a
regular here to make the code clear
--
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]