Skip to content

Commit 6f02022

Browse files
committed
PR feedback
1 parent 5c8b91f commit 6f02022

10 files changed

Lines changed: 486 additions & 352 deletions

sql/walrus_migration_0014_like_ilike_is_not_ops.sql

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ alter type realtime.equality_op add value 'isdistinct';
77

88
alter type realtime.user_defined_filter add attribute negate boolean;
99

10+
drop function if exists realtime.check_equality_op(realtime.equality_op, regtype, text, text);
11+
1012
create or replace function realtime.check_equality_op(
1113
op realtime.equality_op,
1214
type_ regtype,
@@ -70,10 +72,12 @@ begin
7072
end if;
7173

7274
execute format(
73-
'select %L::' || type_::text || ' ' || op_symbol
74-
|| ' ( %L::'
75-
|| (case when op = 'in' then type_::text || '[]' else type_::text end)
76-
|| ')', val_1, val_2
75+
'select %L::%s %s (%L::%s)',
76+
val_1,
77+
type_::text,
78+
op_symbol,
79+
val_2,
80+
case when op = 'in' then type_::text || '[]' else type_::text end
7781
) into res;
7882

7983
return case when negate then not res else res end;
@@ -87,21 +91,24 @@ create or replace function realtime.is_visible_through_filters(columns realtime.
8791
immutable
8892
as $$
8993
select
90-
coalesce(
91-
sum(
94+
filters is null
95+
or array_length(filters, 1) is null
96+
or coalesce(
97+
count(col.name) = count(1)
98+
and sum(
9299
realtime.check_equality_op(
93100
op:=f.op,
94-
type_:=col.type_oid::regtype,
101+
type_:=coalesce(col.type_oid::regtype, col.type_name::regtype),
95102
val_1:=col.value #>> '{}',
96103
val_2:=f.value,
97104
negate:=coalesce(f.negate, false)
98105
)::int
99-
) = count(1),
100-
true
106+
) filter (where col.name is not null) = count(col.name),
107+
false
101108
)
102109
from
103110
unnest(filters) f
104-
join unnest(columns) col
111+
left join unnest(columns) col
105112
on f.column_name = col.name;
106113
$$;
107114

@@ -163,6 +170,11 @@ begin
163170
if filter.value not in ('null', 'true', 'false', 'unknown') then
164171
raise exception 'invalid value for is filter: must be null, true, false, or unknown';
165172
end if;
173+
elsif filter.op in ('match'::realtime.equality_op, 'imatch'::realtime.equality_op) then
174+
if (select typcategory from pg_type where oid = col_type) <> 'S' then
175+
raise exception 'match/imatch filters require a text-compatible column, column % has type %', filter.column_name, col_type::text;
176+
end if;
177+
perform '' ~ filter.value;
166178
else
167179
perform realtime.cast(filter.value, col_type);
168180
end if;
@@ -177,7 +189,7 @@ begin
177189
end if;
178190

179191
new.filters = coalesce(
180-
array_agg(f order by f.column_name, f.op, f.value),
192+
array_agg(f order by f.column_name, f.op, f.value, f.negate),
181193
'{}'
182194
) from unnest(new.filters) f;
183195

test/expected/issue_50_delete_filters.out

Lines changed: 140 additions & 82 deletions
Large diffs are not rendered by default.

test/expected/issue_55_null_passes_filters.out

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,28 @@ select
9999
errors
100100
from
101101
walrus;
102-
rec | is_rls_enabled | subscription_ids | errors
103-
----------------------------------------------------+----------------+----------------------------------------+--------
104-
{ +| f | {f4539ebe-c779-5788-bbc1-2421ffaa8954} | {}
105-
"type": "INSERT", +| | |
106-
"table": "notes", +| | |
107-
"record": { +| | |
108-
"id": 3, +| | |
109-
"page_id": null +| | |
110-
}, +| | |
111-
"schema": "public", +| | |
112-
"columns": [ +| | |
113-
{ +| | |
114-
"name": "id", +| | |
115-
"type": "int4" +| | |
116-
}, +| | |
117-
{ +| | |
118-
"name": "page_id", +| | |
119-
"type": "int4" +| | |
120-
} +| | |
121-
], +| | |
122-
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
123-
} | | |
102+
rec | is_rls_enabled | subscription_ids | errors
103+
----------------------------------------------------+----------------+------------------+--------
104+
{ +| f | {} | {}
105+
"type": "INSERT", +| | |
106+
"table": "notes", +| | |
107+
"record": { +| | |
108+
"id": 3, +| | |
109+
"page_id": null +| | |
110+
}, +| | |
111+
"schema": "public", +| | |
112+
"columns": [ +| | |
113+
{ +| | |
114+
"name": "id", +| | |
115+
"type": "int4" +| | |
116+
}, +| | |
117+
{ +| | |
118+
"name": "page_id", +| | |
119+
"type": "int4" +| | |
120+
} +| | |
121+
], +| | |
122+
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
123+
} | | |
124124
(1 row)
125125

126126
drop table public.notes;

test/expected/test_integration_filters.out

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,48 @@ select
4949
errors
5050
from
5151
walrus;
52-
rec | is_rls_enabled | subscription_ids | errors
53-
----------------------------------------------------+----------------+------------------------------------------------------------------------------------------------------------------+--------
54-
{ +| f | {f4539ebe-c779-5788-bbc1-2421ffaa8954} | {}
55-
"type": "INSERT", +| | |
56-
"table": "notes", +| | |
57-
"record": { +| | |
58-
"id": 1, +| | |
59-
"body": "bbb" +| | |
60-
}, +| | |
61-
"schema": "public", +| | |
62-
"columns": [ +| | |
63-
{ +| | |
64-
"name": "id", +| | |
65-
"type": "int4" +| | |
66-
}, +| | |
67-
{ +| | |
68-
"name": "body", +| | |
69-
"type": "text" +| | |
70-
} +| | |
71-
], +| | |
72-
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
73-
} | | |
74-
{ +| f | {f4539ebe-c779-5788-bbc1-2421ffaa8954,5211e8ec-8c25-5c7f-9b03-6ff1eac0159e,11955172-4e1d-5836-925f-2bcb7a287b87} | {}
75-
"type": "DELETE", +| | |
76-
"table": "notes", +| | |
77-
"schema": "public", +| | |
78-
"columns": [ +| | |
79-
{ +| | |
80-
"name": "id", +| | |
81-
"type": "int4" +| | |
82-
}, +| | |
83-
{ +| | |
84-
"name": "body", +| | |
85-
"type": "text" +| | |
86-
} +| | |
87-
], +| | |
88-
"old_record": { +| | |
89-
"id": 1, +| | |
90-
"body": "bbb" +| | |
91-
}, +| | |
92-
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
93-
} | | |
52+
rec | is_rls_enabled | subscription_ids | errors
53+
----------------------------------------------------+----------------+----------------------------------------+--------
54+
{ +| f | {f4539ebe-c779-5788-bbc1-2421ffaa8954} | {}
55+
"type": "INSERT", +| | |
56+
"table": "notes", +| | |
57+
"record": { +| | |
58+
"id": 1, +| | |
59+
"body": "bbb" +| | |
60+
}, +| | |
61+
"schema": "public", +| | |
62+
"columns": [ +| | |
63+
{ +| | |
64+
"name": "id", +| | |
65+
"type": "int4" +| | |
66+
}, +| | |
67+
{ +| | |
68+
"name": "body", +| | |
69+
"type": "text" +| | |
70+
} +| | |
71+
], +| | |
72+
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
73+
} | | |
74+
{ +| f | {f4539ebe-c779-5788-bbc1-2421ffaa8954} | {}
75+
"type": "DELETE", +| | |
76+
"table": "notes", +| | |
77+
"schema": "public", +| | |
78+
"columns": [ +| | |
79+
{ +| | |
80+
"name": "id", +| | |
81+
"type": "int4" +| | |
82+
}, +| | |
83+
{ +| | |
84+
"name": "body", +| | |
85+
"type": "text" +| | |
86+
} +| | |
87+
], +| | |
88+
"old_record": { +| | |
89+
"id": 1, +| | |
90+
"body": "bbb" +| | |
91+
}, +| | |
92+
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
93+
} | | |
9494
(2 rows)
9595

9696
drop table public.notes;

0 commit comments

Comments
 (0)