Skip to content

feat: Decimal128 write support#12

Merged
killme2008 merged 4 commits into
mainfrom
feature/decimal-support
Jun 12, 2026
Merged

feat: Decimal128 write support#12
killme2008 merged 4 commits into
mainfrom
feature/decimal-support

Conversation

@killme2008

@killme2008 killme2008 commented Jun 12, 2026

Copy link
Copy Markdown
Member

Adds DataType.Decimal128 write support on the unary and streaming paths.

Close #11

What

  • Table.addDecimalFieldColumn(name, precision, scale) declares a DECIMAL(precision, scale) FIELD column. The unary/streaming encoder ships a proto DecimalTypeExtension in the column schema, so server-side auto-create produces a DECIMAL(precision, scale) column.
  • Values accept decimal strings (recommended — exact), numbers, or bigints, and are converted to the 128-bit unscaled integer GreptimeDB stores (round(value * 10^scale)). Excess fractional digits round half-up on the magnitude (away from zero for negatives, matching Java BigDecimal.HALF_UP).
  • Range is validated against the declared precision after rounding (so e.g. 999.5 into DECIMAL(3,0) is rejected); malformed input, non-finite numbers, and invalid precision/scale throw ValueError.
  • The 128-bit value is split into the proto Decimal128 { hi, lo } int64 pair using the standard two's-complement decomposition, matching the server's from_value_precision_scale reconstruction.
  • Bulk Arrow path does not support decimal and throws 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 toProtoValue oneof + missing-metadata + null encoding.

typecheck / lint / format:check / build green; full suite 200 passing.

Notes

  • Decimal is unary/streaming only by design; the bulk Arrow path is unchanged.
  • Builds on top of main (post multi-endpoint-failover merge).

Copilot AI 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.

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.Decimal128 and Table.addDecimalFieldColumn(name, precision, scale) for declaring decimal columns with precision/scale metadata.
  • Encodes Decimal128 values into the protobuf decimal128Value oneof 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.

Comment thread src/table/validators.ts
Comment thread src/table/table.ts
Comment thread test/unit/decimal.test.ts Outdated
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
@killme2008 killme2008 force-pushed the feature/decimal-support branch from a28f1f3 to 66d678e Compare June 12, 2026 10:00

Copilot AI 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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Comment thread src/table/schema.ts Outdated
Comment thread package.json
Comment thread src/bulk/arrow-encoder.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@killme2008 killme2008 merged commit 4984bbf into main Jun 12, 2026
6 checks passed
Sign up for free to 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.

Supports decimal

2 participants