Skip to content

Commit 2c727eb

Browse files
committed
feat: -> and ->> variants with eql_v2_enctrypted selector
1 parent 6699a9a commit 2c727eb

File tree

4 files changed

+93
-15
lines changed

4 files changed

+93
-15
lines changed

src/operators/->.sql

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55

66

77
--
8-
-- The -> operator returns an encrypted matching the selector
8+
-- The -> operator returns an encrypted matching the provided selector
9+
--
910
-- Encyprted JSON is represented as an array of `eql_v2_encrypted`.
10-
-- Each `eql_v2_encrypted` value has a selector, ciphertext, and an index term of
11-
-- - blake3
12-
-- - ore_cllw_u64_8
13-
-- - ore_cllw_var_8
11+
-- Each `eql_v2_encrypted` value has a selector, ciphertext, and an index term
1412
--
1513
-- {
1614
-- "sv": [ {"c": "", "s": "", "b3": "" } ]
1715
-- }
1816
--
19-
20-
2117
CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector text)
2218
RETURNS eql_v2_encrypted
2319
IMMUTABLE STRICT PARALLEL SAFE
@@ -43,10 +39,35 @@ AS $$
4339
END;
4440
$$ LANGUAGE plpgsql;
4541

42+
CREATE OPERATOR ->(
43+
FUNCTION=eql_v2."->",
44+
LEFTARG=eql_v2_encrypted,
45+
RIGHTARG=text
46+
);
47+
4648

47-
--
49+
---------------------------------------------------
4850

4951

52+
CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector eql_v2_encrypted)
53+
RETURNS eql_v2_encrypted
54+
IMMUTABLE STRICT PARALLEL SAFE
55+
AS $$
56+
BEGIN
57+
RETURN eql_v2."->"(e, eql_v2.selector(selector));
58+
END;
59+
$$ LANGUAGE plpgsql;
60+
61+
62+
63+
CREATE OPERATOR ->(
64+
FUNCTION=eql_v2."->",
65+
LEFTARG=eql_v2_encrypted,
66+
RIGHTARG=eql_v2_encrypted
67+
);
68+
69+
70+
---------------------------------------------------
5071

5172

5273
CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector integer)
@@ -76,11 +97,7 @@ AS $$
7697
$$ LANGUAGE plpgsql;
7798

7899

79-
CREATE OPERATOR ->(
80-
FUNCTION=eql_v2."->",
81-
LEFTARG=eql_v2_encrypted,
82-
RIGHTARG=text
83-
);
100+
84101

85102

86103
CREATE OPERATOR ->(

src/operators/->>.sql

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ AS $$
1111
DECLARE
1212
found eql_v2_encrypted;
1313
BEGIN
14-
1514
found = eql_v2."->"(e, selector);
16-
1715
RETURN eql_v2.ciphertext(found);
1816
END;
1917
$$ LANGUAGE plpgsql;
@@ -26,3 +24,22 @@ CREATE OPERATOR ->> (
2624
);
2725

2826

27+
28+
---------------------------------------------------
29+
30+
31+
CREATE FUNCTION eql_v2."->>"(e eql_v2_encrypted, selector eql_v2_encrypted)
32+
RETURNS text
33+
IMMUTABLE STRICT PARALLEL SAFE
34+
AS $$
35+
BEGIN
36+
RETURN eql_v2."->>"(e, eql_v2.selector(selector));
37+
END;
38+
$$ LANGUAGE plpgsql;
39+
40+
41+
CREATE OPERATOR ->> (
42+
FUNCTION=eql_v2."->>",
43+
LEFTARG=eql_v2_encrypted,
44+
RIGHTARG=eql_v2_encrypted
45+
);

src/operators/->>_test.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
SELECT create_table_with_encrypted();
44
SELECT seed_encrypted_json();
55

6+
67
--
78
-- The ->> operator returns ciphertext matching the selector
89
DO $$
@@ -43,3 +44,24 @@ DO $$
4344
END;
4445
$$ LANGUAGE plpgsql;
4546

47+
48+
--
49+
-- The ->> operator accepts an eql_v2_encrypted as the selector
50+
--
51+
DO $$
52+
DECLARE
53+
term text;
54+
BEGIN
55+
term := '{"s": "bca213de9ccce676fa849ff9c4807963"}';
56+
57+
PERFORM assert_result(
58+
'Selector ->> returns at least one eql_v2_encrypted',
59+
format('SELECT e->>%L::jsonb::eql_v2_encrypted FROM encrypted;', term));
60+
61+
PERFORM assert_count(
62+
'Selector ->> returns all eql_v2_encrypted',
63+
format('SELECT e->>%L::jsonb::eql_v2_encrypted FROM encrypted;', term),
64+
3);
65+
END;
66+
$$ LANGUAGE plpgsql;
67+

src/operators/->_test.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ SELECT create_table_with_encrypted();
55
SELECT seed_encrypted_json();
66

77

8+
89
--
910
-- The -> operator returns an encrypted matching the selector
1011
DO $$
@@ -34,6 +35,27 @@ $$ LANGUAGE plpgsql;
3435

3536

3637

38+
--
39+
-- The -> operator accepts an eql_v2_encrypted as the selector
40+
--
41+
DO $$
42+
DECLARE
43+
term text;
44+
BEGIN
45+
term := '{"s": "bca213de9ccce676fa849ff9c4807963"}';
46+
47+
PERFORM assert_result(
48+
'Selector -> returns at least one eql_v2_encrypted',
49+
format('SELECT e->%L::jsonb::eql_v2_encrypted FROM encrypted;', term));
50+
51+
PERFORM assert_count(
52+
'Selector -> returns all eql_v2_encrypted',
53+
format('SELECT e->%L::jsonb::eql_v2_encrypted FROM encrypted;', term),
54+
3);
55+
END;
56+
$$ LANGUAGE plpgsql;
57+
58+
3759
--
3860
-- encrypted returned from -> operator expression called via eql_v2.ciphertext
3961
--

0 commit comments

Comments
 (0)