cql: remove expansion of "SELECT *" in DESC MATERIALIZED VIEW
This patch removes expansion of "SELECT *" in DESC MATERIALIZED VIEW. Instead of explicitly printing each column, DESC command will now just use SELECT *, if view was created with it. Also, adds a correspodning test. Fixes #21154 Closes scylladb/scylladb#21962
This commit is contained in:
committed by
Nadav Har'El
parent
c6bf9d8d11
commit
025bb379a4
@@ -1008,15 +1008,20 @@ sstring schema::get_create_statement(const schema_describe_helper& helper, bool
|
||||
return std::move(os).str();
|
||||
} else {
|
||||
os << "MATERIALIZED VIEW " << cql3::util::maybe_quote(ks_name()) << "." << cql3::util::maybe_quote(cf_name()) << " AS\n";
|
||||
os << " SELECT ";
|
||||
for (auto& cdef : all_columns()) {
|
||||
if (cdef.is_hidden_from_cql()) {
|
||||
continue;
|
||||
if (view_info()->include_all_columns()) {
|
||||
os << " SELECT *";
|
||||
}
|
||||
else {
|
||||
os << " SELECT ";
|
||||
for (auto& cdef : all_columns()) {
|
||||
if (cdef.is_hidden_from_cql()) {
|
||||
continue;
|
||||
}
|
||||
if (n++ != 0) {
|
||||
os << ", ";
|
||||
}
|
||||
os << cdef.name_as_cql_string();
|
||||
}
|
||||
if (n++ != 0) {
|
||||
os << ", ";
|
||||
}
|
||||
os << cdef.name_as_cql_string();
|
||||
}
|
||||
os << "\n FROM " << cql3::util::maybe_quote(ks_name()) << "." << cql3::util::maybe_quote(view_info()->base_name());
|
||||
os << "\n WHERE " << view_info()->where_clause();
|
||||
|
||||
@@ -1539,6 +1539,15 @@ def test_alter_table_add_select_star(cql, test_keyspace):
|
||||
cql.execute(f'INSERT INTO {base} (p,a,b,c) VALUES (0,1,2,3)')
|
||||
assert {(0,1,2,3),(1,2,3,None)} == set(cql.execute(f"SELECT p,a,b,c FROM {base}"))
|
||||
assert {(0,1,2,3),(1,2,3,None)} == set(cql.execute(f"SELECT p,a,b,c FROM {mv}"))
|
||||
|
||||
# Test that if a view is created with "SELECT *", DESC MATERIALIZED VIEW operation shows it
|
||||
# as "SELECT *" instead of expanding it (explicitly showing each column).
|
||||
# Reproduces issue #21154
|
||||
def test_desc_mv_with_select_star(cql, test_keyspace):
|
||||
with new_test_table(cql, test_keyspace, 'p int PRIMARY KEY, a int, b int') as base:
|
||||
with new_materialized_view(cql, base, '*', 'a,p', 'a is not null and p is not null') as mv:
|
||||
mv_desc_result = cql.execute(f"DESC MATERIALIZED VIEW {mv};").one()
|
||||
assert 'SELECT *' in mv_desc_result.create_statement
|
||||
|
||||
# Test that tombstones with future timestamps work correctly
|
||||
# when a write with lower timestamp arrives - in such case,
|
||||
|
||||
Reference in New Issue
Block a user