Skip to content

Commit 0a902b0

Browse files
committed
feat(spec): an Oracle RAW(16) uuid column backs a reference field exactly again
The SQL driver now binds a RAW(16) comparand, written value and by-id key through HEXTORAW, so the oracle uuid demotion narrows to the text pairing alone: lookup, master_detail and user answer exact; text stays lossy because its pattern operators match the column's hex text. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jULf9M1RFFq4dq9ioH
1 parent 9e1f1f9 commit 0a902b0

5 files changed

Lines changed: 67 additions & 27 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec): an Oracle `RAW(16)` uuid column backs a `lookup`, `master_detail` or `user` field exactly again; its `text` pairing stays lossy
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: semantic
9+
10+
`isCompatible(rawType, fieldType, 'oracle')` now answers `true` instead of `'lossy'` for a `RAW(16)` column against `lookup`, `master_detail` and `user`. The SQL driver binds a comparison value, a written value and a by-id key for a `RAW(16)` column as `HEXTORAW(?)`, so a reference field over a `SYS_GUID()` key is filtered, written and resolved by the uuid string it reads. Before that bind existed, every pairing over the column was judged `'lossy'`.
11+
12+
What a caller sees:
13+
14+
- **Draft and validation.** A field of those three types over a `RAW(16)` column is no longer reported as a `type_mismatch` warning by object validation.
15+
- **`text` is unchanged.** A `text` field over a `RAW(16)` column still answers `'lossy'`, and a draft still marks such a column for review. Its pattern operators (`$contains`, `$startsWith`, `$like` and the rest) are sent as text patterns, and Oracle compares them with the column's hex text (32 upper-case digits, no hyphens), not with the uuid string a read returns.
16+
- **Other dialects and other `RAW` widths** answer as before.

‎content/docs/data-modeling/external-datasources.mdx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ object whose `remoteName` is `OWNER.TABLE`.
555555
| `DATE` | `datetime` | An Oracle `DATE` carries a time of day. A `date` field over it is judged lossy: the time is dropped. |
556556
| `TIMESTAMP WITH TIME ZONE` | `datetime` | Compared and returned as UTC instants. |
557557
| `CLOB` | `textarea` | |
558-
| `RAW(16)` | `text` | Read as a lower-case UUID string. Every field pairing over it is judged lossy, so a draft marks it for review: it cannot be filtered or written by that string yet (see below). |
558+
| `RAW(16)` | `text` | Read as a lower-case UUID string, and filtered and written by that string (see below). A `lookup`, `master_detail` or `user` field over it is exact. A `text` field is judged lossy, so a draft marks it for review: `$contains` and the other pattern operators do not match it as the string it reads. |
559559

560560
The driver pins every session to UTC. Thin mode decodes `DATE` and `TIMESTAMP`
561561
values with the server process's local clock, and the driver repairs that on read.
@@ -573,11 +573,20 @@ the process's own time zone. Run the server with `TZ=UTC` and there is no such h
573573
`MERGE`. Use create and update.
574574
- **JSON-array membership** (`$contains` on a multi-value field) is refused. There is
575575
no Oracle construct modelled for it.
576-
- **Filtering or writing a `RAW(16)` column by its UUID string is not supported.**
577-
The driver presents the value as a string on read, but it does not convert the
578-
string back to `RAW` for a comparison or a write. This includes a `lookup` keyed
579-
by a `SYS_GUID()` column. Binding through `HEXTORAW` is tracked in
580-
[#31390](https://github.com/objectstack-ai/objectstack/issues/31390).
576+
- **A `RAW(16)` column is filtered and written by its UUID string.** The driver
577+
reads which of an object's columns are `RAW(16)` from the catalog, and binds a
578+
comparison value (`=`, `$ne`, `$in`, the range operators), a written value and a
579+
record's key for those columns as `HEXTORAW(?)`. That covers a `SYS_GUID()` key and
580+
a `lookup` keyed by one. A UUID is accepted with hyphens (the form a read returns)
581+
or as its 32 hex digits, in either case. Any other value is refused before the
582+
statement is sent: in a filter with `INVALID_FILTER`, in a write with
583+
`VALIDATION_ERROR`. So is a create that gives no id on an object keyed by such a
584+
column, because the id the driver would mint is not a UUID. A `VARCHAR2` column
585+
that holds UUIDs is still compared as text.
586+
- **Pattern operators on a `RAW(16)` column** (`$contains`, `$startsWith`, `$like`
587+
and the rest) are sent as text patterns. Oracle compares them with the column's
588+
hex text: 32 upper-case digits, no hyphens. A fragment of the UUID as it reads
589+
back matches only when it has no hyphen and the operator ignores case.
581590
- A `NUMBER` beyond 2^53 is read as a JavaScript number and loses precision.
582591
- **Paged reads are stable when the object's `columnMap` maps a column to `id`.**
583592
That column breaks ties after the caller's own sort. Without a mapped key, a paged

‎docs/adr/0015-external-datasource-federation.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Deciders**: ObjectStack Protocol Architects
55
**Builds on**: [ADR-0005](./0005-metadata-customization-overlay.md) (one Zod source of truth per metadata type)
66
**Consumers**: `@objectstack/spec`, `@objectstack/runtime`, `@objectstack/objectql`, `@objectstack/plugins/driver-sql`, `@objectstack/services/service-ai`, `@objectstack/cli`, `../objectui`
7-
**Amended by**: [ADR-0143](./0143-outbound-connector-auth-is-open-tier.md) (2026-10-27), attribution only — see the note below. D7 (2026-10-29, ruling 6486136301 on #27298) — an API-backed datasource may borrow a declared connector instance's credential through `external.connector`; see the D7 note below. #27688 (2026-10-30), example only — §8's `credentialsRef` is a `sys_secret:` handle, the only form the shipped secret binder resolves; see the note under §8. #27917 (2026-10-30), dialect list only — §4.6 names the `odata` vocabulary the matrix gained with #27745. #28208 (2026-10-31, ruling 6525963988 on #27687) — a datasource defined in code reads its credential at connect from `OS_DATASOURCE_<NAME>_PASSWORD`, behind the host switch `OS_DATASOURCE_ENV_CREDENTIALS`; see the note under §10 and the correction in the D7 note. 2026-11-03 (maintainer ruling in the security channel, D1 = B, D2 = (c2)+(a)) — under a walled tenancy posture every external object states its organization scope, or the boot is refused by name; see the note under §10 and the sentence added to the D7 note. #31328 (2026-11-08) — §4.6 names the `oracle` vocabulary, with how `NUMBER(p,s)` and `RAW(16)` are read, and its federation-only scope; §5.1 gains the federation-only arm of the DDL gate. #31327 (2026-11-08) — a second federation-only driver, SQL Server (`mssql`): §4.6 names the `mssql` vocabulary and its one dialect-only lossy rule, and the two dialects' lossy moves share one table; §5.1's federation-only arm names both drivers.
7+
**Amended by**: [ADR-0143](./0143-outbound-connector-auth-is-open-tier.md) (2026-10-27), attribution only — see the note below. D7 (2026-10-29, ruling 6486136301 on #27298) — an API-backed datasource may borrow a declared connector instance's credential through `external.connector`; see the D7 note below. #27688 (2026-10-30), example only — §8's `credentialsRef` is a `sys_secret:` handle, the only form the shipped secret binder resolves; see the note under §8. #27917 (2026-10-30), dialect list only — §4.6 names the `odata` vocabulary the matrix gained with #27745. #28208 (2026-10-31, ruling 6525963988 on #27687) — a datasource defined in code reads its credential at connect from `OS_DATASOURCE_<NAME>_PASSWORD`, behind the host switch `OS_DATASOURCE_ENV_CREDENTIALS`; see the note under §10 and the correction in the D7 note. 2026-11-03 (maintainer ruling in the security channel, D1 = B, D2 = (c2)+(a)) — under a walled tenancy posture every external object states its organization scope, or the boot is refused by name; see the note under §10 and the sentence added to the D7 note. #31328 (2026-11-08) — §4.6 names the `oracle` vocabulary, with how `NUMBER(p,s)` and `RAW(16)` are read, and its federation-only scope; §5.1 gains the federation-only arm of the DDL gate. #31327 (2026-11-08) — a second federation-only driver, SQL Server (`mssql`): §4.6 names the `mssql` vocabulary and its one dialect-only lossy rule, and the two dialects' lossy moves share one table; §5.1's federation-only arm names both drivers. #31592 (2026-11-09) — §4.6: with the `HEXTORAW` bind of #31390 on `main`, an Oracle `RAW(16)` column backs a `lookup`, `master_detail` or `user` field exactly again; only its `text` pairing stays `'lossy'`.
88

99
> **Amendment note D7 (2026-10-29, ruling 6486136301, letter A) — a second credential channel.**
1010
> §10 says credentials reach a datasource only through `credentialsRef`. That stays true for a
@@ -429,9 +429,11 @@ read before the matrix strips them (SQL Server's `(max)` length does not: an
429429
integral `NUMBER(p)` / `NUMBER(p,0)` (a negative scale counts its `p − s`
430430
digits) is `integer` up to nine digits and `bigint` beyond, `NUMBER(*,0)` —
431431
Oracle's `INTEGER` — included; a bare `NUMBER` is `decimal`. `RAW(16)` is
432-
`uuid`, any other `RAW` `binary`; on `oracle` every pairing over that `uuid` is
433-
judged `'lossy'`, not exact, because the driver reads it as a UUID string but
434-
cannot yet bind that string back to `RAW` for a filter or a write (#31390). `DATE` carries a time of day, so it is
432+
`uuid`, any other `RAW` `binary`. The driver reads it as a UUID string and binds
433+
that string back through `HEXTORAW` for a comparison, a write and a by-id key
434+
(#31390), so a `lookup`, `master_detail` or `user` field over it is exact; a
435+
`text` field over it stays `'lossy'` on `oracle`, because its pattern operators
436+
match the column's hex text, not the string it reads. `DATE` carries a time of day, so it is
435437
`datetime`. A pre-23ai flag column (`NUMBER(1)` / `CHAR(1)`) is judged as the
436438
integer or text it is, never coerced to `boolean`. The `oracle` and `mssql` driver ids
437439
serve federation only: a datasource naming either with `schemaMode: 'managed'`
@@ -443,7 +445,7 @@ sync would have nothing to send.
443445
names, and maps `timestamp` to binary, because on SQL Server it is the
444446
`rowversion` counter and not a date-time. A dialect moves a pairing to
445447
`'lossy'` in one table, `DIALECT_LOSSY_RULES`, and only ever toward `'lossy'`:
446-
`oracle` demotes the exact pairings of `uuid` (above), and `mssql` adds one, a
448+
`oracle` demotes the exact `text` pairing of `uuid` (above), and `mssql` adds one, a
447449
text column backing a `json`, `tags` or `multiselect` field, because SQL Server
448450
keeps JSON in `nvarchar(max)` and the SQL driver stores those fields there as
449451
JSON text (#31327).

‎packages/spec/src/data/type-compat.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,18 @@ describe('the oracle dialect (ADR-0015 §4.6)', () => {
392392

393393
it('reads RAW(16) as a UUID and every other RAW width as binary', () => {
394394
expect(canonicalizeSqlType('RAW(16)', 'oracle')).toBe('uuid');
395-
// Read as a UUID string, but the driver cannot yet filter or write it by
396-
// that string, so every pairing over it is flagged for review on oracle.
397-
for (const field of ['text', 'lookup', 'master_detail', 'user'] as const) {
398-
expect(isCompatible('RAW(16)', field, 'oracle'), field).toBe('lossy');
395+
// The driver filters, writes and keys a RAW(16) column by the UUID string
396+
// it reads (HEXTORAW), so a reference field over it is exact on oracle...
397+
for (const field of ['lookup', 'master_detail', 'user'] as const) {
398+
expect(isCompatible('RAW(16)', field, 'oracle'), field).toBe(true);
399399
}
400+
// ...and a text field stays flagged for review: its pattern operators
401+
// match the column's hex text, not the string it reads.
402+
expect(isCompatible('RAW(16)', 'text', 'oracle')).toBe('lossy');
400403
expect(suggestFieldTypeForSqlType('RAW(16)', 'oracle')).toBe('text');
404+
// The demotion names its field types; a type the uuid row does not pair
405+
// exactly is not promoted by it.
406+
expect(isCompatible('RAW(16)', 'number', 'oracle')).toBe(false);
401407
// Other dialects' uuid columns keep their exact pairings.
402408
expect(isCompatible('uuid', 'lookup', 'postgres')).toBe(true);
403409
expect(canonicalizeSqlType('RAW(32)', 'oracle')).toBe('binary');

‎packages/spec/src/data/type-compat.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ const DIALECT_ALIASES: Partial<Record<SqlDialect, Record<string, CanonicalSqlTyp
208208
*
209209
* `RAW(16)` is the conventional Oracle column for a UUID / GUID (`SYS_GUID()`
210210
* returns one), so it maps to `uuid`; every other width is `binary`. The
211-
* field pairings over it are `'lossy'` on oracle, not exact: see
212-
* {@link DIALECT_LOSSY_RULES}.
211+
* reference pairings over it are exact; a `text` field over it is `'lossy'`
212+
* on oracle: see {@link DIALECT_LOSSY_RULES}.
213213
*
214214
* `undefined` for any other spelling — the caller then strips parameters and
215215
* reads the alias tables as for every dialect.
@@ -427,13 +427,20 @@ export function suggestFieldTypeForSqlType(rawType: string, dialect?: SqlDialect
427427
* — never exact, never suggested — so a draft carries a `// REVIEW:` marker
428428
* and validation warns instead of passing silently or failing:
429429
*
430-
* - `demoteExact` — the canonical type's EXACT pairings, which this dialect
431-
* can only half-serve, answer `'lossy'` here.
432-
* `oracle` / `uuid`: a `RAW(16)` column reads back as a UUID string, but the
433-
* driver binds a string comparand or write value as text, and Oracle refuses
434-
* text against RAW. A field over it (a `lookup` keyed by a `SYS_GUID()`
435-
* column included) displays correctly and cannot yet be filtered or written
436-
* by its value. Binding through `HEXTORAW` is #31390.
430+
* - `demoteExact` — the EXACT pairings of the canonical type named here,
431+
* which this dialect can only half-serve, answer `'lossy'` here.
432+
* `oracle` / `uuid` → `text`: the SQL driver reads a `RAW(16)` column as a
433+
* lower-case hyphenated UUID string, and binds a comparison comparand, a
434+
* written value and a by-id key for it as `HEXTORAW(?)` over that string's
435+
* hex digits (#31390). A reference field over it — a `lookup` or
436+
* `master_detail` keyed by a `SYS_GUID()` column, a `user` — is filtered,
437+
* written and resolved by the very string it reads, so those pairings stay
438+
* exact. A `text` field is still half-served: its pattern operators
439+
* (`$contains`, `$startsWith`, `$like`, …) are not bound through
440+
* `HEXTORAW`, so they match the column as the text Oracle converts a
441+
* `RAW` to (its 32 hex digits, upper case, no hyphens), not as the string
442+
* it reads; a fragment of that string with a hyphen, or in the case it is
443+
* read in, answers no row instead of a refusal.
437444
* - `addLossy` — field types the base row answers `false` for, which this
438445
* dialect's column can carry with loss.
439446
* `mssql` / `text`: SQL Server (before its 2025 `json` type) keeps JSON in
@@ -446,12 +453,12 @@ export function suggestFieldTypeForSqlType(rawType: string, dialect?: SqlDialect
446453
* column shape the driver relies on (#31327).
447454
*/
448455
interface DialectLossyRule {
449-
readonly demoteExact?: true;
456+
readonly demoteExact?: readonly FieldType[];
450457
readonly addLossy?: readonly FieldType[];
451458
}
452459

453460
const DIALECT_LOSSY_RULES: Partial<Record<SqlDialect, Partial<Record<CanonicalSqlType, DialectLossyRule>>>> = {
454-
oracle: { uuid: { demoteExact: true } },
461+
oracle: { uuid: { demoteExact: ['text'] } },
455462
mssql: { text: { addLossy: ['json', 'tags', 'multiselect'] } },
456463
};
457464

@@ -468,7 +475,7 @@ export function isCompatible(
468475
const canonical = canonicalizeSqlType(rawType, dialect);
469476
const entry = CANONICAL_TO_FIELD[canonical];
470477
const rule = dialect ? DIALECT_LOSSY_RULES[dialect]?.[canonical] : undefined;
471-
if (entry.exact.includes(fieldType)) return rule?.demoteExact ? 'lossy' : true;
478+
if (entry.exact.includes(fieldType)) return rule?.demoteExact?.includes(fieldType) ? 'lossy' : true;
472479
if (entry.lossy.includes(fieldType) || rule?.addLossy?.includes(fieldType)) return 'lossy';
473480
// Unknown remote types are permissive-but-lossy against text/json only,
474481
// already encoded in CANONICAL_TO_FIELD.unknown.

0 commit comments

Comments
 (0)