Uh oh!
There was an error while loading. Please reload this page.
feat(UTL_RAW): UTL_RAW.CAST_TO_RAW - #1337
Conversation
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an Oracle-compatible UTL_RAW SQL package implementing CAST_TO_RAW via UTF-8 conversion, a C header stub, build/merge/meson/Makefile wiring to include the module, and regression tests with expected outputs covering ASCII, NULL, empty, multibyte, mixed, and special-character cases. ChangesUTL_RAW Package and Tests
Sequence DiagramsequenceDiagram
participant TestSQL as Test SQL
participant UTL_RAW as UTL_RAW.CAST_TO_RAW
participant Convert as pg_catalog.convert_to
TestSQL->>UTL_RAW: SELECT UTL_RAW.CAST_TO_RAW(varchar2)
UTL_RAW->>Convert: convert_to(c::text, 'UTF8')
Convert-->>UTL_RAW: RAW result
UTL_RAW-->>TestSQL: return RAW
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c`:
- Around line 45-48: Before calling palloc to allocate result, check that the
computed size (VARHDRSZ + datalen * 2) does not exceed MaxAllocSize (or
otherwise allowable allocation threshold) and raise a controlled ereport/elog
error if it does; specifically, in the code that computes datalen and assigns
result (using VARHDRSZ, datalen, and palloc), compute the needed_size = VARHDRSZ
+ datalen * 2, verify needed_size <= MaxAllocSize (or use SizeIsValid/alloc size
helper used in the project), and call ereport(ERROR, ...) with a clear message
on overly large input when the check fails, only then call palloc(needed_size)
to assign result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aae3b8e1-469c-4f4d-9736-03306cb80cc8
📒 Files selected for processing (6)
contrib/ivorysql_ora/Makefilecontrib/ivorysql_ora/expected/utl_raw.outcontrib/ivorysql_ora/ivorysql_ora_merge_sqlscontrib/ivorysql_ora/sql/utl_raw.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c
Uh oh!
There was an error while loading. Please reload this page.
Replace the incorrect VARCHAR2+hex-string implementation with pg_catalog.convert_to(), which properly returns the string bytes as RAW binary data, matching Oracle behavior.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sql`:
- Line 25: The CAST_TO_RAW implementation currently hardcodes 'UTF8' when
calling pg_catalog.convert_to, which forces UTF-8 regardless of server encoding;
change the call in RETURN pg_catalog.convert_to(c::text, 'UTF8') to use the
active server encoding by replacing the literal with
pg_catalog.pg_encoding_to_char(pg_catalog.getdatabaseencoding()), i.e. call
pg_catalog.convert_to(c::text,
pg_catalog.pg_encoding_to_char(pg_catalog.getdatabaseencoding())) so the
conversion uses the database's encoding (look for the RETURN in CAST_TO_RAW).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2189ad86-29eb-4c3a-b48a-3f81946d5cd3
📒 Files selected for processing (4)
contrib/ivorysql_ora/Makefilecontrib/ivorysql_ora/expected/utl_raw.outcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c
✅ Files skipped from review due to trivial changes (1)
- contrib/ivorysql_ora/expected/utl_raw.out
🚧 Files skipped from review as they are similar to previous changes (1)
- contrib/ivorysql_ora/Makefile
| CREATE OR REPLACE PACKAGE BODY UTL_RAW IS | ||
| FUNCTION CAST_TO_RAW(c IN VARCHAR2) RETURN RAW IS | ||
| BEGIN | ||
| RETURN pg_catalog.convert_to(c::text, 'UTF8'); |
There was a problem hiding this comment.
Avoid hardcoding UTF8 in CAST_TO_RAW conversion.
Line 25 forces UTF-8 bytes regardless of database encoding. That can produce non-Oracle-compatible results on non-UTF8 databases. Use the active server encoding instead.
Proposed fix
- RETURN pg_catalog.convert_to(c::text, 'UTF8');+ RETURN pg_catalog.convert_to(c::text, current_setting('server_encoding'));🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sql` at line
25, The CAST_TO_RAW implementation currently hardcodes 'UTF8' when calling
pg_catalog.convert_to, which forces UTF-8 regardless of server encoding; change
the call in RETURN pg_catalog.convert_to(c::text, 'UTF8') to use the active
server encoding by replacing the literal with
pg_catalog.pg_encoding_to_char(pg_catalog.getdatabaseencoding()), i.e. call
pg_catalog.convert_to(c::text,
pg_catalog.pg_encoding_to_char(pg_catalog.getdatabaseencoding())) so the
conversion uses the database's encoding (look for the RETURN in CAST_TO_RAW).
Uh oh!
There was an error while loading. Please reload this page.
Oracle compatible feature: UTL_RAW
#1057
Summary by CodeRabbit
New Features
Tests