feat: Decimal128 write support#12
Merged
Merged
Conversation
79a4a43 to
a28f1f3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds SDK support for writing DECIMAL(precision, scale) values as DataType.Decimal128 on the unary and streaming row-insert paths, including column schema metadata via DecimalTypeExtension, plus unit tests and explicit bulk Arrow-path rejection.
Changes:
- Introduces
DataType.Decimal128andTable.addDecimalFieldColumn(name, precision, scale)for declaring decimal columns with precision/scale metadata. - Encodes Decimal128 values into the protobuf
decimal128Valueoneof by converting inputs to an unscaled 128-bit integer and splitting into{hi, lo}parts. - Makes the bulk Arrow path explicitly reject Decimal128 at both schema and value normalization stages; adds unit tests and updates the changelog.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unit/decimal.test.ts | Adds unit coverage for decimal parsing/rounding, hi/lo splitting, and proto oneof encoding behavior. |
| src/write/encode.ts | Ships DecimalTypeExtension in column schema for Decimal128 and passes decimal metadata into value encoding. |
| src/table/value.ts | Adds Decimal128 handling in toProtoValue, converting to unscaled bigint and encoding {hi, lo}. |
| src/table/validators.ts | Implements decimal parsing/rounding (decimalToUnscaled) and {hi, lo} split (decimal128Parts). |
| src/table/table.ts | Adds addDecimalFieldColumn and enforces presence/consistency of decimal metadata for Decimal128 columns. |
| src/table/schema.ts | Extends ColumnSpec to carry decimal (precision/scale) metadata. |
| src/table/data-type.ts | Adds DataType.Decimal128 and maps it to proto ColumnDataType.DECIMAL128. |
| src/bulk/arrow-encoder.ts | Throws ValueError when Decimal128 is used on the bulk Arrow path. |
| package.json | Adds prepare script to build on install/publish workflows. |
| CHANGELOG.md | Documents the new Decimal128 write support and bulk-path behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
a28f1f3 to
66d678e
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
DataType.Decimal128write support on the unary and streaming paths.Close #11
What
Table.addDecimalFieldColumn(name, precision, scale)declares aDECIMAL(precision, scale)FIELD column. The unary/streaming encoder ships a protoDecimalTypeExtensionin the column schema, so server-side auto-create produces aDECIMAL(precision, scale)column.round(value * 10^scale)). Excess fractional digits round half-up on the magnitude (away from zero for negatives, matching JavaBigDecimal.HALF_UP).999.5intoDECIMAL(3,0)is rejected); malformed input, non-finite numbers, and invalid precision/scale throwValueError.Decimal128 { hi, lo }int64 pair using the standard two's-complement decomposition, matching the server'sfrom_value_precision_scalereconstruction.ValueError(at both schema build and value encode), keeping unary/bulk rejection behavior explicit.Tests
12 unit tests covering scaling/padding, half-up rounding (incl. negatives), number/bigint/exponential inputs, precision-overflow and malformed-input rejection, the hi/lo split (incl. negative two's-complement), and
toProtoValueoneof + missing-metadata + null encoding.typecheck/lint/format:check/buildgreen; full suite 200 passing.Notes
main(post multi-endpoint-failover merge).