/* * Copyright (C) 2019-present ScyllaDB */ /* * SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0 */ #pragma once #include "mutation/mutation.hh" #include "cql3/cql3_type.hh" #include "schema/schema.hh" namespace tests::data_model { static constexpr api::timestamp_type previously_removed_column_timestamp = 100; static constexpr api::timestamp_type data_timestamp = 200; static constexpr api::timestamp_type column_removal_timestamp = 300; class mutation_description { public: struct expiry_info { gc_clock::duration ttl; gc_clock::time_point expiry_point; }; struct row_marker { api::timestamp_type timestamp; std::optional expiring; row_marker(api::timestamp_type timestamp = data_timestamp); row_marker(api::timestamp_type timestamp, gc_clock::duration ttl, gc_clock::time_point expiry_point); }; using key = std::vector; struct atomic_value { bytes value; api::timestamp_type timestamp; std::optional expiring; atomic_value(bytes value, api::timestamp_type timestamp = data_timestamp); atomic_value(bytes value, api::timestamp_type timestamp, gc_clock::duration ttl, gc_clock::time_point expiry_point); }; struct collection_element { bytes key; atomic_value value; }; struct collection { tombstone tomb; std::vector elements; collection() = default; collection(std::initializer_list elements); collection(std::vector elements); }; using value = std::variant; struct cell { sstring column_name; value data_value; }; using row = std::vector; struct clustered_row { row_marker marker; row_tombstone tomb; row cells; }; struct range_tombstone { interval range; tombstone tomb; }; private: key _partition_key; tombstone _partition_tombstone; row _static_row; std::map _clustered_rows; std::vector _range_tombstones; private: static void remove_column(row& r, const sstring& name); public: explicit mutation_description(key partition_key); void set_partition_tombstone(tombstone partition_tombstone); void add_static_cell(const sstring& column, value v); void add_clustered_cell(const key& ck, const sstring& column, value v); void add_clustered_row_marker(const key& ck, row_marker marker = row_marker(data_timestamp)); void add_clustered_row_tombstone(const key& ck, row_tombstone tomb); void remove_static_column(const sstring& name); void remove_regular_column(const sstring& name); // Both overloads accept out-of-order ranges and will make sure the // range-tombstone is created with start <= end. void add_range_tombstone(const key& start, const key& end, tombstone tomb = tombstone(previously_removed_column_timestamp, gc_clock::time_point())); void add_range_tombstone(interval range, tombstone tomb = tombstone(previously_removed_column_timestamp, gc_clock::time_point())); mutation build(schema_ptr s) const; }; class table_description { public: using column = std::tuple; struct removed_column { sstring name; data_type type; api::timestamp_type removal_timestamp; }; private: std::vector _partition_key; std::vector _clustering_key; std::vector _static_columns; std::vector _regular_columns; std::vector _removed_columns; utils::chunked_vector _mutations; std::vector _change_log; private: static std::vector::iterator find_column(std::vector& columns, const sstring& name); static void add_column(std::vector& columns, const sstring& name, data_type type); void add_old_column(const sstring& name, data_type type); void remove_column(std::vector& columns, const sstring& name); static void alter_column_type(std::vector& columns, const sstring& name, data_type new_type); schema_ptr build_schema() const; utils::chunked_vector build_mutations(schema_ptr s) const; public: explicit table_description(std::vector partition_key, std::vector clustering_key); void add_static_column(const sstring& name, data_type type); void add_regular_column(const sstring& name, data_type type); void add_old_static_column(const sstring& name, data_type type); void add_old_regular_column(const sstring& name, data_type type); void remove_static_column(const sstring& name); void remove_regular_column(const sstring& name); void alter_partition_column_type(const sstring& name, data_type new_type); void alter_clustering_column_type(const sstring& name, data_type new_type); void alter_static_column_type(const sstring& name, data_type new_type); void alter_regular_column_type(const sstring& name, data_type new_type); void rename_partition_column(const sstring& from, const sstring& to); void rename_clustering_column(const sstring& from, const sstring& to); utils::chunked_vector& unordered_mutations() { return _mutations; } const utils::chunked_vector& unordered_mutations() const { return _mutations; } struct table { sstring schema_changes_log; schema_ptr schema; utils::chunked_vector mutations; }; table build() const; }; }