You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/SEMANTIC_TYPES.md
+34-16Lines changed: 34 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,14 +165,30 @@ Note: If a semantic type is not supported by a dialect, the dialect falls back t
165
165
166
166
### Format Hints
167
167
168
-
Format hints provide additional guidance for value conversion (when conversions are used):
169
-
170
-
| Format Hint | Description | Usage |
171
-
|-------------|-------------|-------|
172
-
|`hex`| Hexadecimal format | For `uint256`, `int256` fields containing hex strings |
173
-
|`decimal`| Decimal format | For numeric fields containing decimal strings |
174
-
|`base64`| Base64 format | For binary data encoded as base64 |
175
-
|`string`| String format | Default string handling |
168
+
Format hints provide additional guidance for value conversion. Important: in the default from-proto runtime, these hints do not change schema or insert behavior. They are metadata primarily for documentation and future/custom inserters. The built-in conversion helpers (see db_proto/sql/*/types.go) honor `hex`, but are not wired into from-proto’s insert path today.
169
+
170
+
| Format Hint | Description | Effect in from-proto today |
|`hex`| Value is hexadecimal (optionally 0x-prefixed) | No effect by default; respected only by conversion helpers if explicitly used |
173
+
|`decimal`| Value is base-10 decimal | No effect by default; serves as documentation/intent |
174
+
|`base64`| Value is base64-encoded | No effect by default |
175
+
|`string`| Treat value as plain string | No effect by default |
176
+
177
+
format_hint: "decimal" — What it means today
178
+
- Schema selection: none. Column type selection is driven by `semantic_type`, not by `format_hint`.
179
+
- Insert semantics: none. The runtime passes your field value as-is to the database driver.
180
+
- CSV export: none. Values are serialized as they appear in your message.
181
+
- Practical use: declare that the field’s textual representation is base‑10 (not hex). This helps readers and future/custom inserters apply the right conversions.
182
+
183
+
When to use format_hint: "decimal"
184
+
- Use it for large integer semantic types (e.g., `uint256`, `int256`) when your Substreams output carries decimal strings and your target dialect stores them as a numeric type (Postgres `NUMERIC(78,0)`, RisingWave `rw_uint256`/`rw_int256`).
185
+
- Omit it when storing in ClickHouse: the current mapping stores `uint256`/`int256` as `String`, so the hint has no effect.
186
+
- Do not rely on it to convert hex to decimal automatically — conversion is not applied by default. Emit decimal strings from your Substreams if your destination column is numeric.
187
+
188
+
Safety notes per dialect for `uint256`/`int256`
189
+
- PostgreSQL: Mapped to `NUMERIC(78,0)`. Passing a hex string like `0x...` will fail to cast to numeric via prepared statements. Provide decimal strings (use `format_hint: "decimal"` to document intent), or implement a custom inserter that calls the dialect’s `ConvertSemanticValue` helper.
190
+
- RisingWave: Mapped to `rw_uint256`/`rw_int256`. RisingWave accepts literals with explicit casts (e.g., `'123...'::rw_uint256`). from-proto does not add casts; ensure your values are accepted as-is by the server (decimal strings are the safest choice), or implement custom conversion.
191
+
- ClickHouse: Currently mapped to `String` for maximum compatibility. `format_hint` has no effect; you can store either decimal or hex and cast at query time when needed. Native Decimal256 cannot represent the full uint256 range (max ~76 digits), so automatic Decimal mapping is intentionally avoided.
0 commit comments