Loading schemas of views and indexes was not supported, with either `--schema-file`, or when loading schema from schema sstables. This PR addresses both: * When loading schema from CQL (file), `CREATE MATERIALIZED VIEW` and `CREATE INDEX` statements are now also processed correctly. * When loading schema from schema tables, `system_schema.views` is also processed, when the table has no corresponding entry in `system_schema.tables`. Tests are also added. Fixes: #16492 Closes scylladb/scylladb#16517 * github.com:scylladb/scylladb: test/cql-pytest: test_tools.py: add schema-loading tests for MV/SI test/cql-pytest: test_tools.py: extract some fixture logic to functions test/cql-pytest: test_tools.py: extract common schema-loading facilities into base-class tools/schema_loader: load_schema_from_schema_tables(): add support for MV/SI schemas tools/schema_loader: load_one_schema_from_file(): add support for view/index schemas test/boost/schema_loader_test: add test for mvs and indexes tools/schema_loader: load_schemas(): implement parsing views/indexes from CQL replica/database: extract existing_index_names and get_available_index_name tools/schema_loader: make real_db.tables the only source of truth on existing tables tools/schema_loader: table(): store const keyspace& tools/schema_loader: make database,keyspace,table non-movable cql3/statements/create_index_statement: build_index_schema(): include index metadata in returned value cql3/statements/create_index_statement: make build_index_schema() public cql3/statements/create_index_statement: relax some method's dependence on qp cql3/statements/create_view_statement: make prepare_view() public
68 lines
2.1 KiB
C++
68 lines
2.1 KiB
C++
/*
|
|
* Copyright (C) 2016-present ScyllaDB
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "cql3/statements/schema_altering_statement.hh"
|
|
#include "cql3/statements/cf_properties.hh"
|
|
#include "cql3/cf_name.hh"
|
|
#include "cql3/expr/expression.hh"
|
|
|
|
#include <seastar/core/shared_ptr.hh>
|
|
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace cql3 {
|
|
|
|
class query_processor;
|
|
class relation;
|
|
|
|
namespace selection {
|
|
class raw_selector;
|
|
} // namespace selection
|
|
|
|
namespace statements {
|
|
|
|
/** A <code>CREATE MATERIALIZED VIEW</code> parsed from a CQL query statement. */
|
|
class create_view_statement : public schema_altering_statement {
|
|
private:
|
|
mutable cf_name _base_name;
|
|
std::vector<::shared_ptr<selection::raw_selector>> _select_clause;
|
|
expr::expression _where_clause;
|
|
std::vector<::shared_ptr<cql3::column_identifier::raw>> _partition_keys;
|
|
std::vector<::shared_ptr<cql3::column_identifier::raw>> _clustering_keys;
|
|
cf_properties _properties;
|
|
bool _if_not_exists;
|
|
|
|
public:
|
|
create_view_statement(
|
|
cf_name view_name,
|
|
cf_name base_name,
|
|
std::vector<::shared_ptr<selection::raw_selector>> select_clause,
|
|
expr::expression where_clause,
|
|
std::vector<::shared_ptr<cql3::column_identifier::raw>> partition_keys,
|
|
std::vector<::shared_ptr<cql3::column_identifier::raw>> clustering_keys,
|
|
bool if_not_exists);
|
|
|
|
std::pair<view_ptr, cql3::cql_warnings_vec> prepare_view(data_dictionary::database db) const;
|
|
|
|
auto& properties() {
|
|
return _properties;
|
|
}
|
|
|
|
// Functions we need to override to subclass schema_altering_statement
|
|
virtual future<> check_access(query_processor& qp, const service::client_state& state) const override;
|
|
future<std::tuple<::shared_ptr<cql_transport::event::schema_change>, std::vector<mutation>, cql3::cql_warnings_vec>> prepare_schema_mutations(query_processor& qp, api::timestamp_type) const override;
|
|
|
|
virtual std::unique_ptr<prepared_statement> prepare(data_dictionary::database db, cql_stats& stats) override;
|
|
|
|
// FIXME: continue here. See create_table_statement.hh and CreateViewStatement.java
|
|
};
|
|
|
|
}
|
|
}
|