Skip to content

Commit

Permalink
Merge pull request #4 from def-/pr-enable-window-functions
Browse files Browse the repository at this point in the history
Enable window functions
  • Loading branch information
def- authored Oct 27, 2023
2 parents f8c2894 + b70b15f commit cfe1e81
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
3 changes: 3 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,7 @@ grep -v "is not of expected type ColumnType" | # https://github.com/MaterializeI
grep -v "coalesce could not convert type time" | # https://github.com/MaterializeInc/materialize/issues/20082
grep -v "dimension values must not be null" |
grep -v "arrays must not contain null values" |
grep -v "window functions are not allowed in table function arguments" |
grep -v "window functions are not allowed in OR argument" |
grep -v "window functions are not allowed in AND argument" |
sort | uniq -c | sort -n
9 changes: 5 additions & 4 deletions expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ using impedance::matched;
shared_ptr<value_expr> value_expr::factory(prod *p, sqltype *type_constraint, bool can_return_set)
{
try {
// ERROR: aggregate window functions not yet supported
//if (1 == d20() && p->level < d6() && window_function::allowed(p))
// return make_shared<window_function>(p, type_constraint);
if (1 == d20() && p->level < d6() && window_function::allowed(p))
return make_shared<window_function>(p, type_constraint);
if (1 == d42() && p->level < d6() && type_constraint && type_constraint->name.rfind("list", 0) != 0 && type_constraint->name.rfind("map", 0) != 0 && type_constraint->name.rfind("record", 0) != 0 && type_constraint->name.rfind("any", 0) != 0)
return make_shared<coalesce>(p, type_constraint);
else if (1 == d42() && p->level < d6() && type_constraint && type_constraint->name.rfind("list", 0) != 0 && type_constraint->name.rfind("map", 0) != 0 && type_constraint->name.rfind("record", 0) != 0 && type_constraint->name.rfind("any", 0) != 0)
Expand Down Expand Up @@ -557,7 +556,9 @@ window_function::window_function(prod *p, sqltype *type_constraint)
: value_expr(p)
{
match();
aggregate = make_shared<funcall>(this, type_constraint, true);
//bool agg = d6() > 1;
bool agg = true;
aggregate = make_shared<funcall>(this, type_constraint, true, agg);
type = aggregate->type;
partition_by.push_back(make_shared<column_reference>(this));
while(d6() > 4)
Expand Down
7 changes: 4 additions & 3 deletions grammar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ shared_ptr<prod> statement_factory(struct scope *s, long max_joins, struct prod
return make_shared<insert_stmt>(parent, s);
else if (d42() < 3)
return make_shared<delete_returning>(parent, s);
else if (d42() < 3)
return make_shared<upsert_stmt>(parent, s);
// no constraints supported currently
//else if (d42() < 3)
// return make_shared<upsert_stmt>(parent, s);
else if (d42() < 3)
return make_shared<update_returning>(parent, s);
else if (d6() > 4)
Expand Down Expand Up @@ -800,7 +801,7 @@ void explain_stmt::out(std::ostream &out) {
if (for_supported) {
out << "for ";
}
if(with_supported && d6() > 3) {
if(with_supported && d6() == 1) {
out << "create materialized view mv as ";
}
out << *q;
Expand Down
13 changes: 8 additions & 5 deletions postgres.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
q = "select conname from pg_class t "
"join pg_constraint c on (t.oid = c.conrelid) "
"where contype in ('f', 'u', 'p') ";
q += " and relnamespace = " " (select oid from pg_namespace where nspname = " + w.quote(t->schema) + ")";
q += " and relnamespace = (select oid from pg_namespace where nspname = " + w.quote(t->schema) + ")";
q += " and relname = " + w.quote(t->name);

for (auto row : w.exec(q)) {
Expand Down Expand Up @@ -336,23 +336,26 @@ schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
" mz_schemas.name AS nspname, "
" mz_functions.oid, "
" ret_type.oid AS prorettype, "
" mz_functions.name AS proname "
" mz_functions.name AS proname, "
" mz_functions.returns_set "
"FROM mz_catalog.mz_functions "
"JOIN mz_catalog.mz_schemas "
"ON mz_functions.schema_id = mz_schemas.id "
"JOIN mz_catalog.mz_types AS ret_type "
"ON mz_functions.return_type_id = ret_type.id "
"WHERE mz_functions.name not in ('pg_event_trigger_table_rewrite_reason', 'percentile_cont', 'dense_rank', 'cume_dist', 'rank', 'test_rank', 'percent_rank', 'percentile_disc', 'mode', 'test_percentile_disc') "
"AND mz_functions.name !~ '^ri_fkey_' "
"AND NOT (mz_functions.name in ('sum', 'avg') AND ret_type.oid = 1186) " // https://github.com/MaterializeInc/materialize/issues/18043
"AND NOT (mz_functions.name in ('sum', 'avg', 'avg_internal_v1') AND ret_type.oid = 1186) " // https://github.com/MaterializeInc/materialize/issues/18043
"AND mz_functions.name <> 'array_agg' " // https://github.com/MaterializeInc/materialize/issues/18044
"AND NOT (mz_functions.name = 'string_agg' AND ret_type.oid = 17) " // string_agg on BYTEA not yet supported
"AND NOT mz_functions.name in ('mz_all', 'mz_any') " // https://github.com/MaterializeInc/materialize/issues/18057
"AND " + procedure_is_aggregate + " AND NOT " + procedure_is_window);
for (auto row : r) {
routine proc(row[0].as<string>(),
row[1].as<string>(),
oid2type[row[2].as<OID>()],
row[3].as<string>());
oid2type[row[2].as<long>()],
row[3].as<string>(),
row[4].as<bool>());
register_aggregate(proc);
}

Expand Down

0 comments on commit cfe1e81

Please sign in to comment.