Skip to content

RAWTOHEX function implementation#1293

Open
bigplaice wants to merge 2 commits intoIvorySQL:masterfrom
bigplaice:rawtohex
Open

RAWTOHEX function implementation#1293
bigplaice wants to merge 2 commits intoIvorySQL:masterfrom
bigplaice:rawtohex

Conversation

@bigplaice
Copy link
Copy Markdown
Collaborator

@bigplaice bigplaice commented Apr 15, 2026

Summary by CodeRabbit

  • New Features

    • Added Oracle-compatible hex conversion for binary and text values that returns uppercase hex and treats zero-length/empty inputs as NULL.
  • Tests

    • Added tests covering conversions from various input types, hextoraw-derived inputs, and explicit null/empty cases to verify expected behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 21824df5-3c18-4391-a202-c76ca96b3e91

📥 Commits

Reviewing files that changed from the base of the PR and between 06a29b0 and 430c917.

📒 Files selected for processing (1)
  • contrib/ivorysql_ora/expected/ora_raw_long.out
🚧 Files skipped from review as they are similar to previous changes (1)
  • contrib/ivorysql_ora/expected/ora_raw_long.out

📝 Walkthrough

Walkthrough

Adds Oracle-compatible sys.rawtohex function overloads for bytea and text, plus SQL tests and updated expected output exercising hex conversion and null/empty handling.

Changes

Cohort / File(s) Summary
Function Implementation
contrib/ivorysql_ora/src/builtin_functions/builtin_functions--1.0.sql
Added two sys.rawtohex overloads: sys.rawtohex(bytea) RETURNS varchar2 and sys.rawtohex(text) RETURNS varchar2. Implementations use encode(..., 'hex') with upper(...) and return NULL for zero-length inputs.
Tests & Expected Output
contrib/ivorysql_ora/sql/ora_raw_long.sql, contrib/ivorysql_ora/expected/ora_raw_long.out
Appended a -- rawtohex test block exercising sys.rawtohex with bytea, raw, text, varchar2, sys.hextoraw(...) inputs and null/empty cases; updated expected output accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hopping bytes into bright hex light,
I nibble at bits through day and night,
encode, upper—my tiny craft,
Nulls I skip on my soft path,
A rabbit's cheer for functions done right 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: implementation of the RAWTOHEX function, which is the primary subject of all modifications across the three files (function definition, SQL tests, and expected output).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bigplaice
Copy link
Copy Markdown
Collaborator Author

For issue 1094:
#1094

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
contrib/ivorysql_ora/sql/ora_raw_long.sql (1)

47-55: Consider adding 1–2 edge assertions to strengthen rawtohex coverage.

Current tests are solid; adding a lowercase-hex input and an escaped-text input would better guard output normalization and text conversion behavior.

♻️ Suggested test additions
 -- rawtohex
 SELECT sys.rawtohex('\xDEADBEEF'::bytea);
+SELECT sys.rawtohex('\xdeadbeef'::bytea);
 SELECT sys.rawtohex('\xFF'::raw);
 SELECT sys.rawtohex('hello'::text);
+SELECT sys.rawtohex(E'a\\b'::text);
 SELECT sys.rawtohex('hello'::varchar2);
 SELECT sys.rawtohex(sys.hextoraw('DEADBEEF'));
 SELECT sys.rawtohex(NULL) IS NULL;
 SELECT sys.rawtohex('') IS NULL;
 SELECT sys.rawtohex('\x'::bytea) IS NULL;

As per coding guidelines, **/sql/*.sql: “Test SQL files. Ensure comprehensive coverage of features.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contrib/ivorysql_ora/sql/ora_raw_long.sql` around lines 47 - 55, Tests for
rawtohex lack a lowercase hex input and an escaped-text input to validate
normalization and text conversion; add assertions invoking sys.rawtohex with a
lowercase hex via sys.hextoraw('deadbeef') and with an escaped textual bytea
like sys.rawtohex(E'\\xDEADBEEF'::bytea) (or another escaped-text variant) and
assert expected normalized uppercase hex results (and NULL behavior where
applicable) to the existing rawtohex tests alongside the existing sys.hextoraw
and bytea/text cases.
contrib/ivorysql_ora/src/builtin_functions/builtin_functions--1.0.sql (1)

964-970: Reduce overload drift by delegating text to the bytea overload.

Both overloads implement the same null/empty logic; delegating keeps behavior centralized and easier to maintain.

♻️ Suggested refactor
 CREATE OR REPLACE FUNCTION sys.rawtohex(text)
 RETURNS varchar2
-AS $$ SELECT CASE WHEN pg_catalog.octet_length($1) > 0 THEN upper(pg_catalog.encode($1::bytea, 'hex'))::varchar2 END; $$ 
+AS $$ SELECT sys.rawtohex($1::bytea); $$
 LANGUAGE SQL
 PARALLEL SAFE
 STRICT
 IMMUTABLE;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contrib/ivorysql_ora/src/builtin_functions/builtin_functions--1.0.sql` around
lines 964 - 970, Replace the duplicated logic in sys.rawtohex(text) by
delegating to the existing bytea overload: change the function body to simply
SELECT sys.rawtohex($1::bytea); so the text overload casts its input to bytea
and reuses sys.rawtohex(bytea) (keeping the same function signature, LANGUAGE
SQL, PARALLEL SAFE, STRICT, IMMUTABLE attributes) to centralize null/empty
handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@contrib/ivorysql_ora/sql/ora_raw_long.sql`:
- Around line 47-55: Tests for rawtohex lack a lowercase hex input and an
escaped-text input to validate normalization and text conversion; add assertions
invoking sys.rawtohex with a lowercase hex via sys.hextoraw('deadbeef') and with
an escaped textual bytea like sys.rawtohex(E'\\xDEADBEEF'::bytea) (or another
escaped-text variant) and assert expected normalized uppercase hex results (and
NULL behavior where applicable) to the existing rawtohex tests alongside the
existing sys.hextoraw and bytea/text cases.

In `@contrib/ivorysql_ora/src/builtin_functions/builtin_functions--1.0.sql`:
- Around line 964-970: Replace the duplicated logic in sys.rawtohex(text) by
delegating to the existing bytea overload: change the function body to simply
SELECT sys.rawtohex($1::bytea); so the text overload casts its input to bytea
and reuses sys.rawtohex(bytea) (keeping the same function signature, LANGUAGE
SQL, PARALLEL SAFE, STRICT, IMMUTABLE attributes) to centralize null/empty
handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1958b8fa-d05c-48fa-80ec-6d0d3085b975

📥 Commits

Reviewing files that changed from the base of the PR and between 97b5b0c and 06a29b0.

📒 Files selected for processing (3)
  • contrib/ivorysql_ora/expected/ora_raw_long.out
  • contrib/ivorysql_ora/sql/ora_raw_long.sql
  • contrib/ivorysql_ora/src/builtin_functions/builtin_functions--1.0.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant