Skip to content

fix(ore): return null when comparing null ore values #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 14 additions & 3 deletions sql/000-ore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,24 @@ RETURNS integer AS $$
DECLARE
cmp_result integer;
BEGIN
IF (array_length(a, 1) = 0 OR a IS NULL) AND (array_length(b, 1) = 0 OR b IS NULL) THEN

-- NULLs are NULL
IF a IS NULL OR b IS NULL THEN
RETURN NULL;
END IF;

-- empty a and b
IF cardinality(a) = 0 AND cardinality(b) = 0 THEN
RETURN 0;
END IF;
IF array_length(a, 1) = 0 OR a IS NULL THEN

-- empty a and some b
IF (cardinality(a) = 0) AND cardinality(b) > 0 THEN
RETURN -1;
END IF;
IF array_length(b, 1) = 0 OR a IS NULL THEN

-- some a and empty b
IF cardinality(a) > 0 AND (cardinality(b) = 0) THEN
RETURN 1;
END IF;

Expand Down
6 changes: 4 additions & 2 deletions tests/operators-ore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ CREATE TABLE users

TRUNCATE TABLE users;


TRUNCATE TABLE users;
INSERT INTO users (name_encrypted) VALUES (NULL);

-- User with "LOW" value
INSERT INTO users (name_encrypted) VALUES (
Expand Down Expand Up @@ -57,6 +56,9 @@ DO $$
-- SANITY CHECK
ASSERT (SELECT EXISTS (SELECT id FROM users WHERE cs_ore_64_8_v1(name_encrypted) < cs_ore_64_8_v1(ore_json)));

-- NULL VALUES SHOULD BE IGNORED
ASSERT (SELECT (SELECT COUNT(*) FROM (SELECT id FROM users WHERE cs_ore_64_8_v1(name_encrypted) < cs_ore_64_8_v1(ore_json)) as count) = 1);

ASSERT (SELECT EXISTS (
SELECT id FROM users WHERE name_encrypted < ore_cs_encrypted::jsonb
));
Expand Down