Type coercion
The grid sends numbers and dates as text. The adapter converts each value once, using the type the schema declares for the field, and no compiler converts it again. A value that cannot be converted is a request error in Strict mode.
Rule. Coercing a grid's stringly-typed wire value into a typed IR value (e.g. AG Grid's number filter sending "30", coerced to an int64Value) happens exactly once, in the frontend adapter, at parse time, using the field's schema-declared type (SC-2) as the coercion target. No backend compiler ever performs coercion or re-interprets a typedValue — by the time a compiler sees a value, its type is already fixed and the compiler trusts it completely. If the adapter cannot coerce a wire value to the field's declared type, that is a request error in Strict mode (SC-1's default) — never a value that is passed through untyped or best-effort.
Rationale. The naive alternative pushes the stringly-typed value all the way down to the database layer and lets the target engine's own implicit-coercion rules decide what "30" means against an integer column. That makes behavior backend-dependent by construction — one engine coerces, another errors, a third compares as a string and never matches an integer column at all — which directly violates G3/G4 (identical semantics across backends and language ports). Worse is the failure mode the TRD's problem statement (§1) attributes by name to string-DSL intermediaries like OData/dynamic-LINQ adapters: an unparseable filter value is sometimes treated as "no constraint at all," silently degrading a supposedly-narrowing filter into a full-table match — the opposite of what the user asked for, and dangerous precisely because it fails silently rather than loudly.
Worked example — coercing a number filter's wire value against a field declared int64:
- AG Grid adapter (the one and only coercion site) — wire value
{"filterType":"number","type":"equals","filter":"30"}against a field configuredtype: "int64"in theGridSchemais parsed once, here, into:{ "type": "int64", "value": 30 }Every downstream compiler (SQL/Mongo/ES) binds
30as a native integer parameter/value; none of them contain coercion logic of any kind — they operate on the already-typedint64Valuenode. - Strict-mode rejection — the same field, wire value
"abc"(not parseable as an integer): the adapter's coercion fails before any IR node is produced, and Strict mode (SC-1's default) surfaces a request error (a validation failure an execution adapter typically maps to an HTTP 400-class response) rather than emitting a fallback value. Lenient mode (SC-1's non-default alternative) would need an explicit, documented fallback (e.g., dropping just that condition) — but that is a deliberate per-host opt-out, not this rule's canonical path. - Boolean and date/datetime coercion (
"true"/"false"→booleanValue; AG Grid's"YYYY-MM-DD HH:mm:ss"string →dateValue/datetimeValueper SEM-4) follow the identical one-layer rule — only the target type differs, not where or how coercion happens. - A set filter's
valueson adateordatetimefield are resolved by the adapter like a comparison filter's value, per field type (SEM-4, "A set filter'svaluesfollow the same rule"): the zone-lessYYYY-MM-DD HH:mm:ss/YYYY-MM-DDspellings are resolved withrequestContext.zone, an ISO instant on adatetimefield passes unchanged, and any other text — including a non-midnight time or an ISO instant on adatefield — is amalformed-requestraised by the adapter before any typed value exists, not a later coercion error.
Must NOT.
- Compilers must NOT attempt to coerce a
typedValue's declared type against a schema's physical column/field type — that check is the adapter/validator's job, never the compiler's. - Must NOT silently substitute an uncoercible value with a sentinel that matches everything (e.g. turning a bad numeric string into a SQL
1=1) or with one that matches nothing, without surfacing a request error — both hide the failure instead of reporting it. - Must NOT rely on the target engine's own implicit cast rules (e.g. a database comparing a string literal against an integer column via its native cast rules) as the coercion mechanism — that reintroduces exactly the backend-dependent behavior this rule exists to eliminate.
Cross-links. $defs/typedValue and its member shapes — $defs/int64Value, $defs/decimalValue, $defs/doubleValue, $defs/booleanValue, $defs/stringValue, $defs/dateValue, $defs/datetimeValue — the closed, tagged union that makes "compilers never guess" structurally true: a compiler cannot receive an ambiguous scalar in the first place.