/* * Copyright (C) 2019 ScyllaDB */ /* * This file is part of Scylla. * * Scylla is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Scylla is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Scylla. If not, see . */ #pragma once #include "mutation.hh" #include "cql3/cql3_type.hh" #include "schema.hh" namespace tests::data_model { static constexpr const api::timestamp_type previously_removed_column_timestamp = 100; static constexpr const api::timestamp_type data_timestamp = 200; static constexpr const api::timestamp_type column_removal_timestamp = 300; class mutation_description { public: using key = std::vector; struct collection_element { bytes key; bytes value; }; using collection = std::vector; using atomic_value = bytes; using value = std::variant; struct expiry_info { gc_clock::duration ttl; gc_clock::time_point expiry_point; }; struct cell { sstring column_name; value data_value; std::optional expiring; }; using row = std::vector; struct clustered_row { api::timestamp_type marker; row cells; }; struct range_tombstone { key first; key last; }; private: key _partition_key; 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 add_static_cell(const sstring& column, value v); void add_static_expiring_cell(const sstring& column, atomic_value v, gc_clock::duration ttl, gc_clock::time_point expiry_point); void add_clustered_cell(const key& ck, const sstring& column, value v); void add_clustered_expiring_cell(const key& ck, const sstring& column, atomic_value v, gc_clock::duration ttl, gc_clock::time_point expiry_point); void add_clustered_row_marker(const key& ck, api::timestamp_type timestamp = data_timestamp); void remove_static_column(const sstring& name); void remove_regular_column(const sstring& name); void add_range_tombstone(const key& start, const key& end); 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; std::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; std::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); std::vector& unordered_mutations() { return _mutations; } const std::vector& unordered_mutations() const { return _mutations; } struct table { sstring schema_changes_log; schema_ptr schema; std::vector mutations; }; table build() const; }; }