Skip to content

Commit

Permalink
[core] Partitions table add buckets field
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhuoyu committed Aug 14, 2024
1 parent 16f3629 commit c15d8b4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
11 changes: 5 additions & 6 deletions docs/content/engines/starrocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ For another example, you can query partition files of the table using the follow

```sql
SELECT * FROM paimon_catalog.test_db.partition_tbl$partitions;
/*
+-----------+--------------+--------------------+------------+----------------------------+
| partition | record_count | file_size_in_bytes | file_count | last_update_time |
+-----------+--------------+--------------------+------------+----------------------------+
| [1] | 1 | 645 | 1 | 2024-01-01 00:00:00.000000 |
+-----------+--------------+--------------------+------------+----------------------------+
+---------------+---------+----------------+--------------------+--------------------+------------------------+
| partition | buckets | record_count | file_size_in_bytes| file_count| last_update_time|
+---------------+---------+----------------+--------------------+--------------------+------------------------+
| [1] | 2 | 1 | 645 | 1 | 2024-06-24 10:25:57.400|
+---------------+---------+----------------+--------------------+--------------------+------------------------+
*/
```

Expand Down
10 changes: 5 additions & 5 deletions docs/content/maintenance/system-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ You can query the partition files of the table.
SELECT * FROM my_table$partitions;

/*
+---------------+----------------+--------------------+--------------------+------------------------+
| partition | record_count | file_size_in_bytes| file_count| last_update_time|
+---------------+----------------+--------------------+--------------------+------------------------+
| [1] | 1 | 645 | 1 | 2024-06-24 10:25:57.400|
+---------------+----------------+--------------------+--------------------+------------------------+
+---------------+---------+----------------+--------------------+--------------------+------------------------+
| partition | buckets | record_count | file_size_in_bytes| file_count| last_update_time|
+---------------+---------+----------------+--------------------+--------------------+------------------------+
| [1] | 2 | 1 | 645 | 1 | 2024-06-24 10:25:57.400|
+---------------+---------+----------------+--------------------+--------------------+------------------------+
*/
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@
public class PartitionEntry {

private final BinaryRow partition;
private final long buckets;
private final long recordCount;
private final long fileSizeInBytes;
private final long fileCount;
private final long lastFileCreationTime;

public PartitionEntry(
BinaryRow partition,
long buckets,
long recordCount,
long fileSizeInBytes,
long fileCount,
long lastFileCreationTime) {
this.partition = partition;
this.buckets = buckets;
this.recordCount = recordCount;
this.fileSizeInBytes = fileSizeInBytes;
this.fileCount = fileCount;
Expand All @@ -69,9 +72,14 @@ public long lastFileCreationTime() {
return lastFileCreationTime;
}

public long buckets() {
return buckets;
}

public PartitionEntry merge(PartitionEntry entry) {
return new PartitionEntry(
partition,
buckets,
recordCount + entry.recordCount,
fileSizeInBytes + entry.fileSizeInBytes,
fileCount + entry.fileCount,
Expand All @@ -89,6 +97,7 @@ public static PartitionEntry fromManifestEntry(ManifestEntry entry) {
}
return new PartitionEntry(
entry.partition(),
entry.totalBuckets(),
recordCount,
fileSizeInBytes,
fileCount,
Expand Down Expand Up @@ -125,12 +134,13 @@ public boolean equals(Object o) {
&& fileSizeInBytes == that.fileSizeInBytes
&& fileCount == that.fileCount
&& lastFileCreationTime == that.lastFileCreationTime
&& buckets == that.buckets
&& Objects.equals(partition, that.partition);
}

@Override
public int hashCode() {
return Objects.hash(
partition, recordCount, fileSizeInBytes, fileCount, lastFileCreationTime);
partition, buckets, recordCount, fileSizeInBytes, fileCount, lastFileCreationTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public class PartitionsTable implements ReadonlyTable {
new RowType(
Arrays.asList(
new DataField(0, "partition", SerializationUtils.newStringType(true)),
new DataField(1, "record_count", new BigIntType(false)),
new DataField(2, "file_size_in_bytes", new BigIntType(false)),
new DataField(3, "file_count", new BigIntType(false)),
new DataField(4, "last_update_time", DataTypes.TIMESTAMP_MILLIS())));
new DataField(1, "buckets", new BigIntType(false)),
new DataField(2, "record_count", new BigIntType(false)),
new DataField(3, "file_size_in_bytes", new BigIntType(false)),
new DataField(4, "file_count", new BigIntType(false)),
new DataField(5, "last_update_time", DataTypes.TIMESTAMP_MILLIS())));

private final FileStoreTable storeTable;

Expand Down Expand Up @@ -203,6 +204,7 @@ private GenericRow toRow(
Arrays.toString(partitionConverter.convert(entry.partition())));
return GenericRow.of(
partitionId,
entry.buckets(),
entry.recordCount(),
entry.fileSizeInBytes(),
entry.fileCount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void before() throws Exception {
.partitionKeys("pt")
.primaryKey("pk", "pt")
.option(CoreOptions.CHANGELOG_PRODUCER.key(), "input")
.option("bucket", "1")
.option("bucket", "2")
.build();
TableSchema tableSchema =
SchemaUtils.forceCommit(new SchemaManager(fileIO, tablePath), schema);
Expand Down Expand Up @@ -96,10 +96,20 @@ public void testPartitionRecordCount() throws Exception {
public void testPartitionValue() throws Exception {
write(table, GenericRow.of(2, 1, 3), GenericRow.of(3, 1, 4));
List<InternalRow> expectedRow = new ArrayList<>();
expectedRow.add(GenericRow.of(BinaryString.fromString("[1]"), 4L, 3L));
expectedRow.add(GenericRow.of(BinaryString.fromString("[1]"), 4L, 4L));
expectedRow.add(GenericRow.of(BinaryString.fromString("[2]"), 2L, 2L));

List<InternalRow> result = read(partitionsTable, new int[][] {{0}, {1}, {3}});
List<InternalRow> result = read(partitionsTable, new int[][] {{0}, {2}, {4}});
assertThat(result).containsExactlyInAnyOrderElementsOf(expectedRow);
}

@Test
public void testPartitionBucketsValue() throws Exception {
List<InternalRow> expectedRow = new ArrayList<>();
expectedRow.add(GenericRow.of(BinaryString.fromString("[1]"), 2L));
expectedRow.add(GenericRow.of(BinaryString.fromString("[2]"), 2L));

List<InternalRow> result = read(partitionsTable, new int[][] {{0}, {1}});
assertThat(result).containsExactlyInAnyOrderElementsOf(expectedRow);
}
}

0 comments on commit c15d8b4

Please sign in to comment.