Skip to content

Commit 57a5a9d

Browse files
authored
Merge branch 'main' into spill-pr1
2 parents 18e2454 + 3c94e82 commit 57a5a9d

91 files changed

Lines changed: 5765 additions & 2989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2026-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <map>
20+
#include <memory>
21+
#include <string>
22+
#include <vector>
23+
24+
#include "paimon/result.h"
25+
26+
namespace paimon {
27+
28+
class CommitMessage;
29+
class FileSystem;
30+
class MemoryPool;
31+
32+
/// Compact coordinator for append-only unaware-bucket tables.
33+
///
34+
/// This coordinator scans the latest snapshot for small files, groups them by partition,
35+
/// and generates compaction tasks using a bin-packing algorithm. It then synchronously
36+
/// executes all tasks and returns the resulting commit messages.
37+
///
38+
/// @note This implementation does not support deletion vectors or streaming mode.
39+
/// It only scans the current latest snapshot (batch mode).
40+
class PAIMON_EXPORT AppendCompactCoordinator {
41+
public:
42+
AppendCompactCoordinator() = delete;
43+
~AppendCompactCoordinator() = delete;
44+
/// Run the compaction coordinator.
45+
///
46+
/// Scans the latest snapshot for small files across the specified partitions,
47+
/// generates compact tasks via bin-packing, executes them synchronously,
48+
/// and returns the resulting commit messages.
49+
///
50+
/// @param table_path The root path of the table.
51+
/// @param options User-defined options (will be merged with schema options).
52+
/// @param partitions Partition filters; each element is a partition spec as key-value pairs.
53+
/// Empty vector means all partitions.
54+
/// @param file_system The file system to use. If nullptr, will be created from options.
55+
/// @param pool The memory pool to use. If nullptr, will use default pool.
56+
/// @return Result containing a vector of commit messages from compaction tasks.
57+
static Result<std::vector<std::shared_ptr<CommitMessage>>> Run(
58+
const std::string& table_path, const std::map<std::string, std::string>& options,
59+
const std::vector<std::map<std::string, std::string>>& partitions,
60+
const std::shared_ptr<FileSystem>& file_system, const std::shared_ptr<MemoryPool>& pool);
61+
};
62+
63+
} // namespace paimon

include/paimon/catalog/catalog.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "paimon/catalog/identifier.h"
2828
#include "paimon/result.h"
29+
#include "paimon/snapshot/snapshot_info.h"
2930
#include "paimon/status.h"
3031
#include "paimon/type_fwd.h"
3132
#include "paimon/visibility.h"
@@ -188,6 +189,15 @@ class PAIMON_EXPORT Catalog {
188189
/// @param identifier The identifier (database and table name) of the table to load.
189190
/// @return A result containing table schema if the table exists, or an error status on failure.
190191
virtual Result<std::shared_ptr<Schema>> LoadTableSchema(const Identifier& identifier) const = 0;
192+
193+
/// Lists all snapshots of the specified table, ordered by snapshot id.
194+
///
195+
/// @param identifier The identifier (database and table name) of the table.
196+
/// @param branch Branch name; empty string means the main branch.
197+
/// @return A result containing a vector of SnapshotInfo ordered by
198+
/// snapshot id ascending, or an error status.
199+
virtual Result<std::vector<SnapshotInfo>> ListSnapshots(
200+
const Identifier& identifier, const std::string& branch = "") const = 0;
191201
};
192202

193203
} // namespace paimon

include/paimon/defs.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -434,24 +434,6 @@ struct PAIMON_EXPORT Options {
434434
/// "lookup.cache-max-disk-size" - Max disk size for lookup cache, you can use this option
435435
/// to limit the use of local disks. Default value is unlimited (INT64_MAX).
436436
static const char LOOKUP_CACHE_MAX_DISK_SIZE[];
437-
/// "btree-index.compression" - The compression algorithm to use for BTreeIndex.
438-
/// Default value is "none".
439-
static const char BTREE_INDEX_COMPRESSION[];
440-
/// "btree-index.compression-level" - The compression level of the compression algorithm.
441-
/// Default value is 1.
442-
static const char BTREE_INDEX_COMPRESSION_LEVEL[];
443-
/// "btree-index.block-size" - The block size to use for BTreeIndex.
444-
/// Default value is 64 KB.
445-
static const char BTREE_INDEX_BLOCK_SIZE[];
446-
/// "btree-index.cache-size" - The cache size to use for BTreeIndex.
447-
/// Default value is 128 MB.
448-
static const char BTREE_INDEX_CACHE_SIZE[];
449-
/// "btree-index.high-priority-pool-ratio" - The high priority pool ratio to use for BTreeIndex.
450-
/// Default value is 0.1.
451-
static const char BTREE_INDEX_HIGH_PRIORITY_POOL_RATIO[];
452-
/// "btree-index.records-per-range" - The expected number of records per BTree Index File.
453-
/// Default value is 1000000.
454-
static const char BTREE_INDEX_RECORDS_PER_RANGE[];
455437
};
456438

457439
static constexpr int64_t BATCH_WRITE_COMMIT_IDENTIFIER = std::numeric_limits<int64_t>::max();

include/paimon/file_index/file_index_reader.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ class PAIMON_EXPORT FileIndexReader : public FunctionVisitor<std::shared_ptr<Fil
6262
Result<std::shared_ptr<FileIndexResult>> VisitContains(const Literal& literal) override;
6363

6464
Result<std::shared_ptr<FileIndexResult>> VisitLike(const Literal& literal) override;
65-
66-
Result<std::shared_ptr<FileIndexResult>> VisitAnd(
67-
const std::vector<Result<std::shared_ptr<FileIndexResult>>>& children) override;
68-
69-
Result<std::shared_ptr<FileIndexResult>> VisitOr(
70-
const std::vector<Result<std::shared_ptr<FileIndexResult>>>& children) override;
7165
};
7266

7367
} // namespace paimon

include/paimon/global_index/global_index_reader.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ class PAIMON_EXPORT GlobalIndexReader : public FunctionVisitor<std::shared_ptr<G
4848
virtual Result<std::shared_ptr<GlobalIndexResult>> VisitFullTextSearch(
4949
const std::shared_ptr<FullTextSearch>& full_text_search) = 0;
5050

51-
/// VisitAnd performs logical AND across multiple child results.
52-
/// Default implementation returns "not supported" error.
53-
Result<std::shared_ptr<GlobalIndexResult>> VisitAnd(
54-
const std::vector<Result<std::shared_ptr<GlobalIndexResult>>>& children) override {
55-
return Status::NotImplemented("AND operations not supported by this index type");
56-
}
57-
58-
/// VisitOr performs logical OR across multiple child results.
59-
/// Default implementation returns "not supported" error.
60-
Result<std::shared_ptr<GlobalIndexResult>> VisitOr(
61-
const std::vector<Result<std::shared_ptr<GlobalIndexResult>>>& children) override {
62-
return Status::NotImplemented("OR operations not supported by this index type");
63-
}
64-
6551
/// @return true if the reader is thread-safe; false otherwise.
6652
virtual bool IsThreadSafe() const = 0;
6753

include/paimon/predicate/function_visitor.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,41 +74,5 @@ class PAIMON_EXPORT FunctionVisitor {
7474

7575
/// Evaluates whether string values like the given string.
7676
virtual Result<T> VisitLike(const Literal& literal) = 0;
77-
78-
/// Evaluates the BETWEEN predicate with the given lower and upper bounds.
79-
virtual Result<T> VisitBetween(const Literal& from, const Literal& to) {
80-
// Default implementation: BETWEEN is equivalent to >= AND <=
81-
auto lower_result = VisitGreaterOrEqual(from);
82-
if (!lower_result.ok()) {
83-
return lower_result.status();
84-
}
85-
auto upper_result = VisitLessOrEqual(to);
86-
if (!upper_result.ok()) {
87-
return upper_result.status();
88-
}
89-
return VisitAnd({std::move(lower_result).value(), std::move(upper_result).value()});
90-
}
91-
92-
/// Evaluates the NOT BETWEEN predicate with the given lower and upper bounds.
93-
virtual Result<T> VisitNotBetween(const Literal& from, const Literal& to) {
94-
// Default implementation: NOT BETWEEN is equivalent to < OR >
95-
auto lower_result = VisitLessThan(from);
96-
if (!lower_result.ok()) {
97-
return lower_result.status();
98-
}
99-
auto upper_result = VisitGreaterThan(to);
100-
if (!upper_result.ok()) {
101-
return upper_result.status();
102-
}
103-
return VisitOr({std::move(lower_result).value(), std::move(upper_result).value()});
104-
}
105-
106-
// ----------------- Compound functions ------------------------
107-
108-
/// Evaluates the AND predicate across multiple child results.
109-
virtual Result<T> VisitAnd(const std::vector<Result<T>>& children) = 0;
110-
111-
/// Evaluates the OR predicate across multiple child results.
112-
virtual Result<T> VisitOr(const std::vector<Result<T>>& children) = 0;
11377
};
11478
} // namespace paimon

include/paimon/predicate/literal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class PAIMON_EXPORT Literal {
106106

107107
namespace std {
108108
template <>
109-
struct hash<paimon::Literal> {
109+
struct hash<::paimon::Literal> {
110110
size_t operator()(const paimon::Literal& literal) const {
111111
return literal.HashCode();
112112
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2026-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <cstdint>
20+
#include <optional>
21+
#include <string>
22+
23+
#include "paimon/visibility.h"
24+
25+
namespace paimon {
26+
27+
/// Plain snapshot metadata returned by Catalog::ListSnapshots().
28+
struct PAIMON_EXPORT SnapshotInfo {
29+
/// Commit kind exposed through the public Catalog API.
30+
enum class PAIMON_EXPORT CommitKind : int8_t {
31+
APPEND,
32+
COMPACT,
33+
OVERWRITE,
34+
ANALYZE,
35+
UNKNOWN,
36+
};
37+
38+
/// Convert a CommitKind to its canonical string representation.
39+
static std::string CommitKindToString(CommitKind kind);
40+
41+
int64_t snapshot_id;
42+
int64_t schema_id;
43+
std::string commit_user;
44+
CommitKind commit_kind;
45+
int64_t time_millis;
46+
std::optional<int64_t> total_record_count;
47+
std::optional<int64_t> delta_record_count;
48+
std::optional<int64_t> watermark;
49+
};
50+
51+
} // namespace paimon

src/paimon/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ set(PAIMON_CORE_SRCS
151151
core/mergetree/spill_writer.cpp
152152
core/append/append_only_writer.cpp
153153
core/append/bucketed_append_compact_manager.cpp
154+
core/bucket/bucket_select_converter.cpp
155+
core/append/append_compact_task.cpp
156+
core/append/append_compact_coordinator.cpp
154157
core/bucket/hive_bucket_function.cpp
155158
core/bucket/mod_bucket_function.cpp
156159
core/bucket/bucket_id_calculator.cpp
@@ -284,6 +287,7 @@ set(PAIMON_CORE_SRCS
284287
core/schema/schema_validation.cpp
285288
core/schema/table_schema.cpp
286289
core/snapshot.cpp
290+
core/snapshot_info.cpp
287291
core/stats/simple_stats_collector.cpp
288292
core/stats/simple_stats_converter.cpp
289293
core/stats/simple_stats.cpp
@@ -412,8 +416,7 @@ if(PAIMON_BUILD_TESTS)
412416
common/global_index/bitmap/bitmap_global_index_test.cpp
413417
common/global_index/btree/btree_index_meta_test.cpp
414418
common/global_index/btree/btree_file_footer_test.cpp
415-
common/global_index/btree/btree_global_indexer_test.cpp
416-
common/global_index/btree/btree_global_index_writer_test.cpp
419+
common/global_index/btree/key_serializer_test.cpp
417420
common/global_index/btree/btree_global_index_integration_test.cpp
418421
common/global_index/btree/btree_compatibility_test.cpp
419422
common/global_index/rangebitmap/range_bitmap_global_index_test.cpp
@@ -527,7 +530,9 @@ if(PAIMON_BUILD_TESTS)
527530
add_paimon_test(core_test
528531
SOURCES
529532
core/append/append_only_writer_test.cpp
533+
core/append/append_compact_coordinator_test.cpp
530534
core/append/bucketed_append_compact_manager_test.cpp
535+
core/bucket/bucket_select_converter_test.cpp
531536
core/bucket/default_bucket_function_test.cpp
532537
core/bucket/hive_bucket_function_test.cpp
533538
core/bucket/bucket_id_calculator_test.cpp

src/paimon/common/data/binary_row.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <cstdint>
2020

21+
#include "fmt/format.h"
2122
#include "paimon/common/data/binary_data_read_utils.h"
2223
#include "paimon/common/memory/memory_segment.h"
2324
#include "paimon/common/memory/memory_segment_utils.h"
@@ -300,4 +301,8 @@ int32_t BinaryRow::HashCode() const {
300301
return MemorySegmentUtils::HashByWords({segment_}, offset_, size_in_bytes_, nullptr);
301302
}
302303

304+
std::string BinaryRow::ToString() const {
305+
return fmt::format("BinaryRow@{:#x}", static_cast<uint32_t>(HashCode()));
306+
}
307+
303308
} // namespace paimon

0 commit comments

Comments
 (0)