Skip to content

series/3.x Numeric operators accept BigDecimal, BigInt and Byte fields - #1167

Merged
googley42 merged 3 commits into
series/3.xfrom
series/3.x_numeric_grammar
Nov 29, 2026
Merged

googley42 merged 3 commits into
series/3.xfrom
series/3.x_numeric_grammar

Conversation

@googley42

Copy link
Copy Markdown
Contributor

Summary

DdbGrammar.N listed only Int, Long, Float, Double and Short, so increment, decrement, add and between on a BigDecimal, BigInt or Byte field did not compile, nor did addSet / deleteFromSet / containsElement on a Set of them - although the codec stores all three as a Number (and their sets as a NumberSet). N now includes them. BigDecimal is the usual type for money, so this was likely to bite.

Change

  • N adds Primitive.Byte, Primitive.BigInt, Primitive.BigDecimal. NS is built from N, so sets of them follow.
  • Source compatible: the grammar only accepts more field types.
  • A standalone Byte is a 1-byte Binary under withSchema1ByteCompatibility(ReadBothWriteOld), where numeric updates fail in DynamoDB; included anyway since the default encoding is a Number, and noted on N.

Tests

New DdbExprNumericFieldsSpec (Scala 2.13 and 3), covering all eight numeric types and a Set of each:

  • the derived codec stores each as a Number / NumberSet;
  • increment, decrement, add, between, addSet, deleteFromSet, containsElement encode their values as numbers;
  • compile time, both directions: every numeric type is accepted (typeCheck is Right), and String, Boolean, Instant and non-set fields are rejected by the grammar (Left, naming Allows).

The existing tests only used Int with these operators, and the compile-time tests only checked rejections, so a grammar narrower than the codec went unnoticed.

All suites pass on Scala 3.3.9 and 2.13.18, including ce and it against DynamoDB Local.

Not in this PR

between on temporal fields stored as ISO strings (Instant, LocalDate, ...) still doesn't compile; tracked separately, since it needs a per-type check that the stored strings sort in time order.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate active findings show that newly accepted Byte set and numeric-update operations fail under the supported legacy compatibility mode, requiring changes to prevent or explicitly handle these invalid requests.

2 open issues
What changed in this PR

This pull request expands DynamoDB expression grammar support so Byte, BigInt, and BigDecimal fields and their sets can be used with numeric and set operators, matching the default codec encodings.

Changes:

  • Adds the three numeric primitive types to DdbGrammar.N, with DdbGrammar.NS consequently supporting their sets.
  • Adds comprehensive codec, expression encoding, and compile-time acceptance/rejection tests.
  • Documents the standalone Byte compatibility caveat for legacy schema encoding.
File Description
blocks-schema/​src/​main/​scala/​zio/​dynamodb/​blocks/​DdbGrammar.scala Expands scalar and set numeric grammar support and documents legacy Byte compatibility behavior.
blocks-schema-ddbexpr/​src/​test/​scala/​zio/​dynamodb/​DdbExprNumericFieldsSpec.scala Adds coverage for numeric scalar and set codecs, expression encoding, operators, and compile-time grammar constraints.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported, and the change includes targeted grammar, operand-validation, and compatibility coverage.

No open issues 🎉

2 resolved since last review

Review effort: Lite

@googley42
googley42 marked this pull request as ready for review November 29, 2026 10:56
@googley42
googley42 merged commit b0c7af6 into series/3.x Nov 29, 2026
17 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.

2 participants