Repository navigation
series/3.x Numeric operators accept BigDecimal, BigInt and Byte fields - #1167
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 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, withDdbGrammar.NSconsequently supporting their sets. - Adds comprehensive codec, expression encoding, and compile-time acceptance/rejection tests.
- Documents the standalone
Bytecompatibility 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
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.

Summary
DdbGrammar.Nlisted onlyInt,Long,Float,DoubleandShort, soincrement,decrement,addandbetweenon aBigDecimal,BigIntorBytefield did not compile, nor didaddSet/deleteFromSet/containsElementon aSetof them - although the codec stores all three as aNumber(and their sets as aNumberSet).Nnow includes them.BigDecimalis the usual type for money, so this was likely to bite.Change
NaddsPrimitive.Byte,Primitive.BigInt,Primitive.BigDecimal.NSis built fromN, so sets of them follow.Byteis a 1-byteBinaryunderwithSchema1ByteCompatibility(ReadBothWriteOld), where numeric updates fail in DynamoDB; included anyway since the default encoding is aNumber, and noted onN.Tests
New
DdbExprNumericFieldsSpec(Scala 2.13 and 3), covering all eight numeric types and aSetof each:Number/NumberSet;increment,decrement,add,between,addSet,deleteFromSet,containsElementencode their values as numbers;typeCheckisRight), andString,Boolean,Instantand non-set fields are rejected by the grammar (Left, namingAllows).The existing tests only used
Intwith 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
ceanditagainst DynamoDB Local.Not in this PR
betweenon 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.