Skip to content

feat(UTL_RAW): UTL_RAW.CAST_TO_RAW - #1337

Merged
gaoxueyu merged 5 commits into
IvorySQL:masterfrom
hs-liuxh:ora/utl_raw
May 29, 2026
Merged

feat(UTL_RAW): UTL_RAW.CAST_TO_RAW#1337
gaoxueyu merged 5 commits into
IvorySQL:masterfrom
hs-liuxh:ora/utl_raw

Conversation

@hs-liuxh

@hs-liuxhhs-liuxh commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Oracle compatible feature: UTL_RAW

#1057

Summary by CodeRabbit

  • New Features

    • Added an Oracle-compatible UTL_RAW package exposing CAST_TO_RAW and endian constants for converting text to RAW/hex.
  • Tests

    • Added regression tests covering normal, empty, NULL, multibyte, mixed, and special-character inputs (including endian check).
    • Included the UTL_RAW test suite in install-time regression checks so it runs during installcheck/debug.

Review Change Stack

@coderabbitai

coderabbitaiBot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf56ab38-3482-4d5e-b39f-f472a8070864

📥 Commits

Reviewing files that changed from the base of the PR and between b4f980d and c4922fc.

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

📝 Walkthrough

Walkthrough

Adds 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.

Changes

UTL_RAW Package and Tests

Layer / File(s)Summary
SQL package spec and body
contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sql
Adds UTL_RAW package spec with endianness constants and CAST_TO_RAW(c IN VARCHAR2) RETURN RAW, and package body that returns pg_catalog.convert_to(c::text, 'UTF8').
C module header/stub
contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c
Adds license/header and comments; no PostgreSQL C functions are implemented in this file.
Build wiring, SQL tests, and expected outputs
contrib/ivorysql_ora/ivorysql_ora_merge_sqls, contrib/ivorysql_ora/meson.build, contrib/ivorysql_ora/Makefile, contrib/ivorysql_ora/sql/utl_raw.sql, contrib/ivorysql_ora/expected/utl_raw.out
Registers src/builtin_packages/utl_raw/utl_raw in merge list, adds utl_raw.c to Meson sources and adds utl_raw to ORA_REGRESS, and provides SQL tests plus expected output for various CAST_TO_RAW inputs.

Sequence Diagram

sequenceDiagram
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Suggested reviewers

  • bigplaice
  • jiaoshuntian

Poem

I nibble bytes from near and far,
I turn your text to shiny char,
UTF-8 hops through every claw,
Hex carrots gleam — UTL_RAW hurrah! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title accurately summarizes the main change: implementing UTL_RAW.CAST_TO_RAW, an Oracle-compatible feature. It is concise, specific, and directly reflects the changeset's primary objective.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.

✏️ 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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 35e086c and 4822d52.

📒 Files selected for processing (6)
  • contrib/ivorysql_ora/Makefile
  • contrib/ivorysql_ora/expected/utl_raw.out
  • contrib/ivorysql_ora/ivorysql_ora_merge_sqls
  • contrib/ivorysql_ora/sql/utl_raw.sql
  • contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sql
  • contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c

Comment threadcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c Outdated
hs-liuxhand others added 2 commits May 18, 2026 10:08
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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55f4796 and c68748a.

📒 Files selected for processing (4)
  • contrib/ivorysql_ora/Makefile
  • contrib/ivorysql_ora/expected/utl_raw.out
  • contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sql
  • contrib/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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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).

@gaoxueyu
gaoxueyu merged commit 852ee63 into IvorySQL:masterMay 29, 2026
8 checks passed
Sign up for freeto 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.

3 participants

@hs-liuxh@gaoxueyu@jiaoshuntian