mxdzs0612 commented on code in PR #4427:
URL: https://github.com/apache/paimon/pull/4427#discussion_r1827129684
##########
paimon-core/src/main/java/org/apache/paimon/catalog/CachingCatalog.java:
##########
@@ -227,6 +244,47 @@ private void putTableCache(Identifier identifier, Table
table) {
tableCache.put(identifier, table);
}
+ public List<PartitionEntry> getPartitions(Identifier identifier) throws
TableNotExistException {
+ Table table = this.getTable(identifier);
+ if (enablePartitionCache(table)) {
+ List<PartitionEntry> partitions;
+ partitions = partitionCache.getIfPresent(identifier);
+ if (partitions == null || partitions.isEmpty()) {
+ partitions = this.refreshPartitions(identifier);
+ }
+ return partitions;
+ }
+ return ((FileStoreTable) table).newSnapshotReader().partitionEntries();
+ }
+
+ public List<PartitionEntry> refreshPartitions(Identifier identifier)
+ throws TableNotExistException {
+ Table table = this.getTable(identifier);
+ List<PartitionEntry> partitions =
+ ((FileStoreTable)
table).newSnapshotReader().partitionEntries();
+ if (enablePartitionCache(table)
+ &&
partitionCache.asMap().values().stream().mapToInt(List::size).sum()
+ < this.partitionMaxNum) {
+ partitionCache.put(identifier, partitions);
+ }
+ return partitions;
+ }
+
+ private boolean enablePartitionCache(Table table) {
+ return partitionCache != null
+ && table instanceof FileStoreTable
+ && !table.partitionKeys().isEmpty();
+ }
+
+ @Override
+ public void dropPartition(Identifier identifier, Map<String, String>
partitions)
+ throws TableNotExistException, PartitionNotExistException {
+ wrapped.dropPartition(identifier, partitions);
+ if (partitionCache != null) {
+ partitionCache.invalidate(identifier);
Review Comment:
Can't find a better way, any ideas?
--
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]