File tree Expand file tree Collapse file tree 3 files changed +36
-15
lines changed Expand file tree Collapse file tree 3 files changed +36
-15
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,28 @@ DROP CAST IF EXISTS (text AS ore_64_8_v1_term);
156156CREATE CAST (text AS ore_64_8_v1_term)
157157 WITH FUNCTION _cs_text_to_ore_64_8_v1_term_v1_0(text ) AS IMPLICIT;
158158
159+ DROP FUNCTION IF EXISTS jsonb_array_to_ore_64_8_v1(val jsonb);
160+
161+ -- Casts a jsonb array of hex-encoded strings to the `ore_64_8_v1` composite type.
162+ -- In other words, this function takes the ORE index format sent through in the
163+ -- EQL payload from Proxy and decodes it as the composite type that we use for
164+ -- ORE operations on the Postgres side.
165+ CREATE FUNCTION jsonb_array_to_ore_64_8_v1 (val jsonb)
166+ RETURNS ore_64_8_v1 AS $$
167+ DECLARE
168+ terms_arr ore_64_8_v1_term[];
169+ BEGIN
170+ IF jsonb_typeof(val) = ' null' THEN
171+ RETURN NULL ;
172+ END IF;
173+
174+ SELECT array_agg(ROW(decode(value::text , ' hex' ))::ore_64_8_v1_term)
175+ INTO terms_arr
176+ FROM jsonb_array_elements_text(val) AS value;
177+
178+ RETURN ROW(terms_arr)::ore_64_8_v1;
179+ END;
180+ $$ LANGUAGE plpgsql;
159181
160182-- extracts ore index from an encrypted column
161183DROP FUNCTION IF EXISTS cs_ore_64_8_v1_v0_0(val jsonb);
@@ -166,7 +188,7 @@ CREATE FUNCTION cs_ore_64_8_v1_v0_0(val jsonb)
166188AS $$
167189 BEGIN
168190 IF val ? ' o' THEN
169- RETURN (val- >> ' o' )::ore_64_8_v1 ;
191+ RETURN jsonb_array_to_ore_64_8_v1 (val- > ' o' );
170192 END IF;
171193 RAISE ' Expected an ore index (o) value in json: %' , val;
172194 END;
Original file line number Diff line number Diff line change 66 ASSERT (SELECT EXISTS (SELECT cs_unique_v1(' {"u": "u"}' ::jsonb)));
77 ASSERT (SELECT EXISTS (SELECT cs_match_v1(' {"m": []}' ::jsonb)));
88 ASSERT (SELECT EXISTS (SELECT cs_ste_vec_v1(' {"sv": [[]]}' ::jsonb)));
9- ASSERT (SELECT EXISTS (SELECT cs_ore_64_8_v1(' {"o": "()" }' ::jsonb)));
9+ ASSERT (SELECT EXISTS (SELECT cs_ore_64_8_v1(' {"o": [] }' ::jsonb)));
1010
1111 END;
1212$$ LANGUAGE plpgsql;
1313
1414DO $$
1515 BEGIN
1616 -- sanity check
17- PERFORM cs_ore_64_8_v1(' {"o": "()" }' ::jsonb);
17+ PERFORM cs_ore_64_8_v1(' {"o": [] }' ::jsonb);
1818
1919 BEGIN
2020 PERFORM cs_ore_64_8_v1(' {}' ::jsonb);
7676 END;
7777 END;
7878$$ LANGUAGE plpgsql;
79-
You can’t perform that action at this time.
0 commit comments