Skip to content

Commit ffbcde3

Browse files
committed
PR feedback
1 parent 5c8b91f commit ffbcde3

7 files changed

Lines changed: 391 additions & 360 deletions

sql/walrus_migration_0014_like_ilike_is_not_ops.sql

Lines changed: 15 additions & 7 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,7 +91,9 @@ create or replace function realtime.is_visible_through_filters(columns realtime.
8791
immutable
8892
as $$
8993
select
90-
coalesce(
94+
filters is null
95+
or array_length(filters, 1) is null
96+
or coalesce(
9197
sum(
9298
realtime.check_equality_op(
9399
op:=f.op,
@@ -97,7 +103,7 @@ as $$
97103
negate:=coalesce(f.negate, false)
98104
)::int
99105
) = count(1),
100-
true
106+
false
101107
)
102108
from
103109
unnest(filters) f
@@ -163,6 +169,8 @@ begin
163169
if filter.value not in ('null', 'true', 'false', 'unknown') then
164170
raise exception 'invalid value for is filter: must be null, true, false, or unknown';
165171
end if;
172+
elsif filter.op in ('match'::realtime.equality_op, 'imatch'::realtime.equality_op) then
173+
perform '' ~ filter.value;
166174
else
167175
perform realtime.cast(filter.value, col_type);
168176
end if;
@@ -177,7 +185,7 @@ begin
177185
end if;
178186

179187
new.filters = coalesce(
180-
array_agg(f order by f.column_name, f.op, f.value),
188+
array_agg(f order by f.column_name, f.op, f.value, f.negate),
181189
'{}'
182190
) from unnest(new.filters) f;
183191

test/expected/issue_50_delete_filters.out

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.
Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
select 1 from pg_create_logical_replication_slot('realtime', 'wal2json', false);
2-
?column?
2+
?column?
33
----------
44
1
55
(1 row)
@@ -19,9 +19,9 @@ select
1919
),
2020
array[('page_id', 'eq', '5', null)::realtime.user_defined_filter];
2121
select clear_wal();
22-
clear_wal
22+
clear_wal
2323
-----------
24-
24+
2525
(1 row)
2626

2727
-- Expect 0 subscriptions: filters do not match: 5 <> 1
@@ -33,28 +33,28 @@ select
3333
errors
3434
from
3535
walrus;
36-
rec | is_rls_enabled | subscription_ids | errors
36+
rec | is_rls_enabled | subscription_ids | errors
3737
----------------------------------------------------+----------------+------------------+--------
3838
{ +| f | {} | {}
39-
"type": "INSERT", +| | |
40-
"table": "notes", +| | |
41-
"record": { +| | |
42-
"id": 1, +| | |
43-
"page_id": 1 +| | |
44-
}, +| | |
45-
"schema": "public", +| | |
46-
"columns": [ +| | |
47-
{ +| | |
48-
"name": "id", +| | |
49-
"type": "int4" +| | |
50-
}, +| | |
51-
{ +| | |
52-
"name": "page_id", +| | |
53-
"type": "int4" +| | |
54-
} +| | |
55-
], +| | |
56-
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
57-
} | | |
39+
"type": "INSERT", +| | |
40+
"table": "notes", +| | |
41+
"record": { +| | |
42+
"id": 1, +| | |
43+
"page_id": 1 +| | |
44+
}, +| | |
45+
"schema": "public", +| | |
46+
"columns": [ +| | |
47+
{ +| | |
48+
"name": "id", +| | |
49+
"type": "int4" +| | |
50+
}, +| | |
51+
{ +| | |
52+
"name": "page_id", +| | |
53+
"type": "int4" +| | |
54+
} +| | |
55+
], +| | |
56+
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
57+
} | | |
5858
(1 row)
5959

6060
-- Expect 1 subscription: filters do match 5 = 5
@@ -66,28 +66,28 @@ select
6666
errors
6767
from
6868
walrus;
69-
rec | is_rls_enabled | subscription_ids | errors
69+
rec | is_rls_enabled | subscription_ids | errors
7070
----------------------------------------------------+----------------+----------------------------------------+--------
7171
{ +| f | {f4539ebe-c779-5788-bbc1-2421ffaa8954} | {}
72-
"type": "INSERT", +| | |
73-
"table": "notes", +| | |
74-
"record": { +| | |
75-
"id": 2, +| | |
76-
"page_id": 5 +| | |
77-
}, +| | |
78-
"schema": "public", +| | |
79-
"columns": [ +| | |
80-
{ +| | |
81-
"name": "id", +| | |
82-
"type": "int4" +| | |
83-
}, +| | |
84-
{ +| | |
85-
"name": "page_id", +| | |
86-
"type": "int4" +| | |
87-
} +| | |
88-
], +| | |
89-
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
90-
} | | |
72+
"type": "INSERT", +| | |
73+
"table": "notes", +| | |
74+
"record": { +| | |
75+
"id": 2, +| | |
76+
"page_id": 5 +| | |
77+
}, +| | |
78+
"schema": "public", +| | |
79+
"columns": [ +| | |
80+
{ +| | |
81+
"name": "id", +| | |
82+
"type": "int4" +| | |
83+
}, +| | |
84+
{ +| | |
85+
"name": "page_id", +| | |
86+
"type": "int4" +| | |
87+
} +| | |
88+
], +| | |
89+
"commit_timestamp": "2000-01-01T08:01:01.000Z"+| | |
90+
} | | |
9191
(1 row)
9292

9393
-- Expect 0 subscriptions: filters do match 5 <> null
@@ -99,35 +99,35 @@ 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;
127127
select pg_drop_replication_slot('realtime');
128-
pg_drop_replication_slot
128+
pg_drop_replication_slot
129129
--------------------------
130-
130+
131131
(1 row)
132132

133133
truncate table realtime.subscription;

0 commit comments

Comments
 (0)