Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/encrypted/casts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
--

CREATE FUNCTION eql_v2.to_encrypted(data jsonb)
RETURNS public.eql_v2_encrypted AS $$
RETURNS public.eql_v2_encrypted
IMMUTABLE STRICT PARALLEL SAFE
AS $$
BEGIN
IF data IS NULL THEN
RETURN NULL;
Expand All @@ -17,6 +19,7 @@ BEGIN
END;
$$ LANGUAGE plpgsql;


--
-- Cast jsonb to eql_v2.encrypted
--
Expand All @@ -30,16 +33,19 @@ CREATE CAST (jsonb AS public.eql_v2_encrypted)
--

CREATE FUNCTION eql_v2.to_encrypted(data text)
RETURNS public.eql_v2_encrypted AS $$
RETURNS public.eql_v2_encrypted
IMMUTABLE STRICT PARALLEL SAFE
AS $$
BEGIN
IF data IS NULL THEN
RETURN NULL;
END IF;

RETURN ROW(data::jsonb)::public.eql_v2_encrypted;
RETURN eql_v2.to_encrypted(data::jsonb);
END;
$$ LANGUAGE plpgsql;


--
-- Cast text to eql_v2.encrypted
--
Expand Down
40 changes: 40 additions & 0 deletions src/operators/operator_class_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,49 @@ DO $$
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"abc\"}")');
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"def\"}")');
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"ghi\"}")');
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"jkl\"}")');
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"mno\"}")');

-- Literal row type type thing
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = ''("{\"hm\": \"abc\"}")'';' into result;

IF position('Index Only Scan using encrypted' in result) > 0 THEN
ASSERT true;
ELSE
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
END IF;

-- Cast to jsonb to eql_v2_encrypted
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = ''{"hm": "abc"}''::jsonb::eql_v2_encrypted;' into result;

IF position('Index Only Scan using encrypted' in result) > 0 THEN
ASSERT true;
ELSE
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
END IF;

-- Cast to text to eql_v2_encrypted
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = ''{"hm": "abc"}''::text::eql_v2_encrypted;' into result;

IF position('Index Only Scan using encrypted' in result) > 0 THEN
ASSERT true;
ELSE
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
END IF;

-- Use to_encrypted with jsonb
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = eql_v2.to_encrypted(''{"hm": "abc"}''::jsonb);' into result;

IF position('Index Only Scan using encrypted' in result) > 0 THEN
ASSERT true;
ELSE
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
END IF;

-- Use to_encrypted with text
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = eql_v2.to_encrypted(''{"hm": "abc"}'');' into result;


IF position('Index Only Scan using encrypted' in result) > 0 THEN
ASSERT true;
ELSE
Expand Down
1 change: 0 additions & 1 deletion src/operators/order_by.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- REQUIRE: src/encrypted/types.sql
-- REQUIRE: src/ore_block_u64_8_256/types.sql
-- REQUIRE: src/ore_block_u64_8_256/functions.sql
-- REQUIRE: src/ore_block_u64_8_256/operators.sql
-- REQUIRE: src/ore_cllw_u64_8/types.sql
-- REQUIRE: src/ore_cllw_u64_8/functions.sql

Expand Down