yuqi1129 commented on code in PR #7791:
URL: https://github.com/apache/gravitino/pull/7791#discussion_r2242002437
##########
catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/operations/StarRocksTablePartitionOperations.java:
##########
@@ -53,26 +78,162 @@ public StarRocksTablePartitionOperations(
@Override
public String[] listPartitionNames() {
- throw new NotImplementedException("To be implemented in the future");
+ try (Connection connection = getConnection(loadedTable.databaseName())) {
+ String showPartitionsSql = String.format("SHOW PARTITIONS FROM `%s`",
loadedTable.name());
+ try (Statement statement = connection.createStatement();
+ ResultSet result = statement.executeQuery(showPartitionsSql)) {
+ ImmutableList.Builder<String> partitionNames = ImmutableList.builder();
+ while (result.next()) {
+ partitionNames.add(result.getString("PartitionName"));
+ }
+ return partitionNames.build().toArray(new String[0]);
+ }
+ } catch (SQLException e) {
+ throw exceptionConverter.toGravitinoException(e);
+ }
}
@Override
public Partition[] listPartitions() {
- throw new NotImplementedException("To be implemented in the future");
+ try (Connection connection = getConnection(loadedTable.databaseName())) {
+ Transform partitionInfo = loadedTable.partitioning()[0];
+ Map<String, Type> columnTypes = getColumnType(connection);
+ String showPartitionsSql = String.format("SHOW PARTITIONS FROM `%s`",
loadedTable.name());
+ try (Statement statement = connection.createStatement();
+ ResultSet result = statement.executeQuery(showPartitionsSql)) {
+ ImmutableList.Builder<Partition> partitions = ImmutableList.builder();
+ while (result.next()) {
+ partitions.add(
+ StarRocksUtils.fromStarRocksPartition(
+ loadedTable.name(), result, partitionInfo, columnTypes));
+ }
+ return partitions.build().toArray(new Partition[0]);
+ }
+ } catch (SQLException e) {
+ throw exceptionConverter.toGravitinoException(e);
+ }
}
@Override
public Partition getPartition(String partitionName) throws
NoSuchPartitionException {
- throw new NotImplementedException("To be implemented in the future");
+ try (Connection connection = getConnection(loadedTable.databaseName())) {
+ Transform partitionInfo = loadedTable.partitioning()[0];
+ Map<String, Type> columnTypes = getColumnType(connection);
+ String showPartitionsSql =
+ String.format(
+ "SHOW PARTITIONS FROM `%s` WHERE PartitionName = \"%s\"",
+ loadedTable.name(), partitionName);
+ try (Statement statement = connection.createStatement();
+ ResultSet result = statement.executeQuery(showPartitionsSql)) {
+ if (result.next()) {
+ return StarRocksUtils.fromStarRocksPartition(
+ loadedTable.name(), result, partitionInfo, columnTypes);
+ }
+ }
+ } catch (SQLException e) {
+ throw exceptionConverter.toGravitinoException(e);
+ }
+ throw new NoSuchPartitionException("Partition %s does not exist",
partitionName);
}
@Override
public Partition addPartition(Partition partition) throws
PartitionAlreadyExistsException {
- throw new NotImplementedException("To be implemented in the future");
+ try (Connection connection = getConnection(loadedTable.databaseName())) {
+ Transform partitionInfo = loadedTable.partitioning()[0];
+
+ String addPartitionSqlFormat = "ALTER TABLE `%s` ADD %s";
+ String partitionSqlFragment;
+ Partition added;
+
+ if (partition instanceof RangePartition) {
+ Preconditions.checkArgument(
+ partitionInfo instanceof Transforms.RangeTransform,
+ "Table %s is non-range-partitioned, but trying to add a range
partition",
+ loadedTable.name());
+
+ RangePartition rangePartition = (RangePartition) partition;
+ partitionSqlFragment =
StarRocksUtils.generatePartitionSqlFragment(rangePartition);
+
+ // The partition properties actually cannot be passed into Doris, we
just return an empty
Review Comment:
> The document commit:
[b54bfcc](https://github.com/apache/gravitino/commit/b54bfccf02f787e9164f4c7fb977ef4c393f9730)
Where is the link to the PR?
--
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]