12#if !defined(SIGNET_ENABLE_COMMERCIAL) || !SIGNET_ENABLE_COMMERCIAL
13#error "signet/ai/row_lineage.hpp requires SIGNET_ENABLE_COMMERCIAL=ON (AGPL-3.0 commercial tier). See LICENSE_COMMERCIAL."
62 int32_t initial_version = 1)
63 : origin_file_(origin_file)
64 , version_(initial_version) {
71 auto gate = commercial::require_feature(
"RowLineageTracker");
79 lineage.
row_id = next_row_id_++;
86 std::vector<uint8_t> chain_input;
87 chain_input.reserve(prev_hash_hex_.size() + row_size);
88 chain_input.insert(chain_input.end(), prev_hash_hex_.begin(), prev_hash_hex_.end());
89 chain_input.insert(chain_input.end(), row_data, row_data + row_size);
91 prev_hash_hex_ = hash_to_hex_impl(hash);
97 [[nodiscard]] int64_t
current_row_id() const noexcept {
return next_row_id_; }
106 void reset(
const std::string& origin_file, int32_t version = 1) {
107 origin_file_ = origin_file;
112 std::string origin_file_;
113 int32_t version_ = 1;
114 int64_t next_row_id_ = 0;
115 std::string prev_hash_hex_ = std::string(64,
'0');
118 static std::string hash_to_hex_impl(
const std::array<uint8_t, 32>& hash) {
119 static constexpr char hex[] =
"0123456789abcdef";
120 std::string result(64,
'\0');
121 for (
size_t i = 0; i < 32; ++i) {
122 result[2*i] = hex[hash[i] >> 4];
123 result[2*i + 1] = hex[hash[i] & 0x0F];
Per-row lineage tracking inspired by Iceberg V3-style data governance.
RowLineageTracker(const std::string &origin_file="", int32_t initial_version=1)
Construct a tracker for the given origin file and initial version.
int64_t current_row_id() const noexcept
Get current row counter (next row_id to be assigned).
RowLineage next(const uint8_t *row_data, size_t row_size)
Generate lineage for the next row.
void reset(const std::string &origin_file, int32_t version=1)
Reset the origin file and version for a new batch.
std::array< uint8_t, 32 > sha256(const uint8_t *data, size_t size)
Compute SHA-256 hash of arbitrary-length input.
SHA-256 hash function (NIST FIPS 180-4).
Lineage metadata for a single row.
int32_t row_version
Mutation version counter.
std::string row_origin_file
Source file/batch identifier.
std::string row_prev_hash
SHA-256 hex of the previous row's serialized data.
int64_t row_id
Monotonic row identifier (0-based, never resets)