Skip to content

Commit 9092d1b

Browse files
authored
feat: introduce table scan, split and plan (#99)
1 parent 9b27b92 commit 9092d1b

21 files changed

Lines changed: 2347 additions & 0 deletions
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <cstddef>
23+
#include <cstdint>
24+
#include <memory>
25+
#include <optional>
26+
#include <string>
27+
#include <vector>
28+
29+
#include "paimon/data/timestamp.h"
30+
#include "paimon/memory/memory_pool.h"
31+
#include "paimon/result.h"
32+
#include "paimon/table/source/split.h"
33+
#include "paimon/visibility.h"
34+
35+
namespace paimon {
36+
class MemoryPool;
37+
38+
/// Input data split for reading operation. Needed by most batch computation engines.
39+
class PAIMON_EXPORT DataSplit : public Split {
40+
public:
41+
/// Metadata structure for simple data files.
42+
///
43+
/// Contains essential information about a data file including its location,
44+
/// size, row count, sequence numbers, schema information, and timestamps.
45+
/// This structure is used to track file metadata without loading the actual file content.
46+
struct SimpleDataFileMeta {
47+
SimpleDataFileMeta(const std::string& _file_path, int64_t _file_size, int64_t _row_count,
48+
int64_t _min_sequence_number, int64_t _max_sequence_number,
49+
int64_t _schema_id, int32_t _level, const Timestamp& _creation_time,
50+
const std::optional<int64_t>& _delete_row_count)
51+
: file_path(_file_path),
52+
file_size(_file_size),
53+
row_count(_row_count),
54+
min_sequence_number(_min_sequence_number),
55+
max_sequence_number(_max_sequence_number),
56+
schema_id(_schema_id),
57+
level(_level),
58+
creation_time(_creation_time),
59+
delete_row_count(_delete_row_count) {}
60+
61+
/// Absolute path of the data file.
62+
///
63+
/// If external path is enabled, `file_path` indicates the actual location in the external
64+
/// storage system.
65+
std::string file_path;
66+
int64_t file_size;
67+
int64_t row_count;
68+
int64_t min_sequence_number;
69+
int64_t max_sequence_number;
70+
int64_t schema_id;
71+
int32_t level;
72+
Timestamp creation_time;
73+
std::optional<int64_t> delete_row_count;
74+
75+
bool operator==(const SimpleDataFileMeta& other) const;
76+
77+
std::string ToString() const;
78+
};
79+
80+
/// Get the list of metadata for all data files in this split.
81+
/// @note This method will be removed in future versions and is only used for append tables.
82+
virtual std::vector<SimpleDataFileMeta> GetFileList() const = 0;
83+
};
84+
} // namespace paimon

include/paimon/table/source/plan.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <memory>
23+
#include <optional>
24+
#include <vector>
25+
26+
#include "paimon/table/source/split.h"
27+
28+
namespace paimon {
29+
/// %Result plan of this `TableScan`.
30+
class PAIMON_EXPORT Plan {
31+
public:
32+
virtual ~Plan() = default;
33+
/// %Result splits.
34+
virtual const std::vector<std::shared_ptr<Split>>& Splits() const = 0;
35+
/// Snapshot id of this plan, return `std::nullopt` if the table is empty.
36+
virtual std::optional<int64_t> SnapshotId() const = 0;
37+
};
38+
} // namespace paimon
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <cstddef>
23+
#include <cstdint>
24+
#include <memory>
25+
#include <optional>
26+
#include <string>
27+
#include <vector>
28+
29+
#include "paimon/memory/memory_pool.h"
30+
#include "paimon/result.h"
31+
#include "paimon/visibility.h"
32+
33+
namespace paimon {
34+
class MemoryPool;
35+
36+
/// An input split for reading operation. Needed by most batch computation engines. Support
37+
/// Serialize and Deserialize, compatible with java version.
38+
/// This split can be either a `DataSplit` (for direct data file reads) or an `IndexedSplit`
39+
/// (for reads leveraging global indexes).
40+
class PAIMON_EXPORT Split {
41+
public:
42+
virtual ~Split() = default;
43+
44+
/// Deserialize a `Split` from a binary buffer.
45+
///
46+
/// Creates a `Split` instance from its serialized binary representation.
47+
/// This is typically used in distributed computing scenarios where splits
48+
/// are transmitted between different nodes or processes.
49+
///
50+
/// @param buffer Const pointer to the binary data containing the serialized `Split`.
51+
/// @param length Size of the buffer in bytes.
52+
/// @param pool Memory pool for allocating objects during deserialization.
53+
/// @return Result containing the deserialized `Split` or an error status.
54+
static Result<std::shared_ptr<Split>> Deserialize(const char* buffer, size_t length,
55+
const std::shared_ptr<MemoryPool>& pool);
56+
57+
/// Serialize a `Split` to a binary string.
58+
///
59+
/// Converts a `Split` instance to its binary representation for storage
60+
/// or transmission. The serialized data can later be deserialized using
61+
/// the Deserialize method.
62+
///
63+
/// @param split The `Split` instance to serialize.
64+
/// @param pool Memory pool for allocating temporary objects during serialization.
65+
/// @return Result containing the serialized binary data as a string or an error status.
66+
static Result<std::string> Serialize(const std::shared_ptr<Split>& split,
67+
const std::shared_ptr<MemoryPool>& pool);
68+
};
69+
} // namespace paimon
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
#include <string>
22+
23+
#include "paimon/result.h"
24+
#include "paimon/visibility.h"
25+
26+
namespace paimon {
27+
/// Specifies the startup mode for log consumer.
28+
class PAIMON_EXPORT StartupMode {
29+
public:
30+
/// Determines actual startup mode according to other table properties. If "scan.snapshot-id" is
31+
/// set the actual startup mode will be "from-snapshot", otherwise the actual startup mode will
32+
/// be "latest-full".
33+
static const StartupMode Default();
34+
35+
/// For streaming sources, produces the latest snapshot on the table upon first startup, and
36+
/// continue to read the latest changes. For batch sources, just produce the latest snapshot but
37+
/// does not read new changes.
38+
static const StartupMode LatestFull();
39+
40+
/// For streaming sources, continuously reads latest changes without producing a snapshot at the
41+
/// beginning. For batch sources, behaves the same as the "latest-full" startup mode.
42+
static const StartupMode Latest();
43+
44+
/// For streaming sources, continuously reads changes starting from snapshot specified by
45+
/// "scan.snapshot-id", without producing a snapshot at the beginning. For batch sources,
46+
/// produces a snapshot specified by "scan.snapshot-id" but does not read new changes.
47+
static const StartupMode FromSnapshot();
48+
49+
/// For streaming sources, produces from snapshot specified by "scan.snapshot-id" on the table
50+
/// upon first startup, and continuously reads changes. For batch sources, produces a snapshot
51+
/// specified by "scan.snapshot-id" but does not read new changes
52+
static const StartupMode FromSnapshotFull();
53+
54+
/// Starts from a timestamp specified by either "scan.timestamp-millis" or
55+
/// "scan.timestamp". For batch sources, produces the latest snapshot whose
56+
/// timestamp is <= the specified timestamp. For streaming sources, continuously
57+
/// reads changes starting from the first snapshot at or after the timestamp.
58+
static const StartupMode FromTimestamp();
59+
60+
public:
61+
std::string ToString() const;
62+
bool operator==(const StartupMode& other) const;
63+
static Result<StartupMode> FromString(const std::string& str);
64+
65+
private:
66+
explicit StartupMode(const std::string& value) : value_(value) {}
67+
68+
private:
69+
std::string value_;
70+
};
71+
} // namespace paimon
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <memory>
23+
#include <vector>
24+
25+
#include "paimon/executor.h"
26+
#include "paimon/memory/memory_pool.h"
27+
#include "paimon/read_context.h"
28+
#include "paimon/reader/batch_reader.h"
29+
#include "paimon/result.h"
30+
#include "paimon/table/source/split.h"
31+
#include "paimon/visibility.h"
32+
33+
namespace paimon {
34+
class MemoryPool;
35+
class ReadContext;
36+
37+
/// Given a `Split` or a list of `Split`, generate a reader for batch reading.
38+
class PAIMON_EXPORT TableRead {
39+
public:
40+
virtual ~TableRead() = default;
41+
42+
/// Create an instance of `TableRead`.
43+
///
44+
/// @param context A unique pointer to the `ReadContext` used for read operations.
45+
/// @return A Result containing a unique pointer to the `TableRead` instance.
46+
static Result<std::unique_ptr<TableRead>> Create(std::unique_ptr<ReadContext> context);
47+
48+
/// Creates a `BatchReader` instance for reading data.
49+
///
50+
/// This method creates a BatchReader that will be responsible for reading data from the
51+
/// provided splits.
52+
///
53+
/// @param splits A vector of shared pointers to `Split` instances representing the
54+
/// data to be read.
55+
/// @return A Result containing a unique pointer to the `BatchReader` instance.
56+
/// @note `BatchReader`s created by the same `TableRead` are not thread-safe for
57+
/// concurrent reading.
58+
virtual Result<std::unique_ptr<BatchReader>> CreateReader(
59+
const std::vector<std::shared_ptr<Split>>& splits);
60+
61+
/// Creates a `BatchReader` instance for a single split.
62+
///
63+
/// @param split A shared pointer to the `Split` instance that defines the data to be
64+
/// read.
65+
/// @return A Result containing a unique pointer to the `BatchReader` instance.
66+
virtual Result<std::unique_ptr<BatchReader>> CreateReader(
67+
const std::shared_ptr<Split>& split) = 0;
68+
69+
protected:
70+
explicit TableRead(const std::shared_ptr<MemoryPool>& memory_pool);
71+
72+
std::shared_ptr<MemoryPool> GetMemoryPool() const {
73+
return pool_;
74+
}
75+
76+
private:
77+
std::shared_ptr<MemoryPool> pool_;
78+
};
79+
} // namespace paimon
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <memory>
23+
24+
#include "paimon/result.h"
25+
#include "paimon/table/source/plan.h"
26+
#include "paimon/type_fwd.h"
27+
#include "paimon/visibility.h"
28+
29+
namespace paimon {
30+
class ScanContext;
31+
32+
/// A scanner interface for reading table's meta and create a plan.
33+
class PAIMON_EXPORT TableScan {
34+
public:
35+
/// Create an instance of `TableScan`.
36+
///
37+
/// @param context A unique pointer to the `ScanContext` used for scan operations.
38+
/// @return A Result containing a unique pointer to the `TableScan` instance.
39+
static Result<std::unique_ptr<TableScan>> Create(std::unique_ptr<ScanContext> context);
40+
41+
virtual ~TableScan() = default;
42+
43+
/// Create a scan plan.
44+
///
45+
/// @return A Result containing a shared pointer to the created `Plan` or an error status.
46+
virtual Result<std::shared_ptr<Plan>> CreatePlan() = 0;
47+
};
48+
} // namespace paimon

0 commit comments

Comments
 (0)