From cda95bc3e191c060ba7bd3768264eb508c8d40e1 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Fri, 6 Oct 2023 12:39:32 +0000 Subject: [PATCH] Implement COMMENT ON queries Depends on https://github.com/MaterializeInc/materialize/pull/22019 --- grammar.cc | 33 +++++++++++++++++++++++++++++---- grammar.hh | 10 ++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/grammar.cc b/grammar.cc index 7accae8..178f0fb 100644 --- a/grammar.cc +++ b/grammar.cc @@ -384,6 +384,29 @@ delete_returning::delete_returning(prod *p, struct scope *s, table *victim) select_list = make_shared(this); } +comment_stmt::comment_stmt(prod *p, struct scope *s, table *v) + : modifying_stmt(p, s, v) +{ + match(); + if(d6() < 4) { + victim_column = make_shared(random_pick(victim->columns())); + } +} + +void comment_stmt::out(std::ostream &out) +{ + out << "comment on "; + + if(victim_column) { + out << "column " << victim->ident() << "." << victim_column->name; + } else { + out << "table " << victim->ident(); + } + + string comment = scope->stmt_uid("comment"); + out << " is '" << comment << "'"; +} + insert_stmt::insert_stmt(prod *p, struct scope *s, table *v) : modifying_stmt(p, s, v) { @@ -484,13 +507,15 @@ shared_ptr statement_factory(struct scope *s, long max_joins, struct prod // Syntax: ERROR: Unexpected keyword MERGE at the beginning of a statement //if (d42() == 1) // return make_shared(parent, s); - if (d42() == 1) + if (d42() < 3) + return make_shared(parent, s); + else if (d42() < 3) return make_shared(parent, s); - else if (d42() == 1) + else if (d42() < 3) return make_shared(parent, s); - else if (d42() == 1) + else if (d42() < 3) return make_shared(parent, s); - else if (d42() == 1) + else if (d42() < 3) return make_shared(parent, s); else if (d6() > 4) return make_shared(parent, s); diff --git a/grammar.hh b/grammar.hh index ccc49fe..821cf67 100644 --- a/grammar.hh +++ b/grammar.hh @@ -206,6 +206,16 @@ struct delete_returning : delete_stmt { } }; +struct comment_stmt : modifying_stmt { + shared_ptr victim_column; + comment_stmt(prod *p, struct scope *s, table *victim = 0); + virtual ~comment_stmt() { } + virtual void out(std::ostream &out); + virtual void accept(prod_visitor *v) { + v->visit(this); + } +}; + struct insert_stmt : modifying_stmt { vector > value_exprs; insert_stmt(prod *p, struct scope *s, table *victim = 0);