Skip to content

series/3.x Set[Byte] under 2.x byte compatibility keeps its elements and reads 2.x data - #1168

Merged
googley42 merged 1 commit into
series/3.xfrom
series/3.x_byte_set_compat
Nov 29, 2026
Merged

googley42 merged 1 commit into
series/3.xfrom
series/3.x_byte_set_compat

Conversation

@googley42

Copy link
Copy Markdown
Contributor

Summary

Under withSchema1ByteCompatibility(ReadBothWriteOld), a put of a record with a non-empty Set[Byte] succeeded but stored the item without that attribute: the elements encode to Binary, the Set[numeric] branch kept only Numbers and produced an empty NumberSet, and empty sets are left out of the item. And no mode, including the two ReadBoth* modes, could read the format 2.x wrote. Found from a review comment on #1167.

2.x had no native Set[Byte]: its set encoder has no ByteType case, so it wrote a List of single-byte Binary values.

Change

Set[Byte] gets its own codec in the two compatibility modes; the default mode is unchanged.

Mode Writes Reads
ReadNewWriteNew (default) NumberSet NumberSet
ReadBothWriteNew NumberSet NumberSet, or 2.x's List of single-byte Binary
ReadBothWriteOld 2.x's List of single-byte Binary (an empty set is an empty List, so it is kept) both

Also: addSet / deleteFromSet now fail in the effect, before a request is sent, when the field's codec doesn't encode the value as a set (as under ReadBothWriteOld, where it is a List), like the numeric-update check added in #1167. containsElement keeps working there, since DynamoDB's contains accepts a list.

Docs: a Set[Byte] row in the Schema1Compat table in docs/reference/codec.md.

Tests

  • DynamoDBCodecDeriverSpec ("Schema1Compat Set[Byte]"): what each mode writes and reads, including the empty set and a malformed element.
  • DdbExprNumericFieldsSpec: addSet / deleteFromSet fail under the legacy codec and are unaffected for other sets; containsElement on the List form.
  • New ByteSetCompatibilitySpec (against DynamoDB Local): under ReadBothWriteOld a non-empty and an empty Set[Byte] round-trip and are stored as a List; under ReadBothWriteNew an item stored in 2.x's format reads back.

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

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

A critical Scala 2.13 compilation error in the shared interpreter prevents the cross-built project from compiling and blocks verification of the new checks.

1 open issue
What changed in this PR

Adds schema compatibility for Set[Byte], supporting migration between the 2.x list-of-single-byte-binary representation and the 3.x NumberSet representation while preserving empty sets. It also validates set update operations against the field codec.

Changes:

  • Adds compatibility-aware encoding and decoding for Set[Byte] across schema compatibility modes.
  • Validates addSet and deleteFromSet before generating update requests when the codec does not produce a native DynamoDB set.
  • Adds unit, integration, and documentation coverage for legacy and modern wire formats.
File Description
it/​src/​test/​scala/​zio/​dynamodb/​ByteSetCompatibilitySpec.scala Verifies Set[Byte] compatibility round trips and stored wire formats against DynamoDB Local.
docs/​reference/​codec.md Documents the Set[Byte] representations and schema compatibility mappings.
blocks-schema/​src/​test/​scala/​zio/​dynamodb/​blocks/​schema/​DynamoDBCodecDeriverSpec.scala Tests Set[Byte] encoding and decoding across compatibility modes, including empty sets and malformed legacy elements.
blocks-schema/​src/​main/​scala/​zio/​dynamodb/​blocks/​schema/​DynamoDBCodecDeriver.scala Implements compatibility-aware codecs for legacy and modern Set[Byte] representations.
blocks-schema-ddbexpr/​src/​test/​scala/​zio/​dynamodb/​DdbExprNumericFieldsSpec.scala Tests set-update validation and containsElement behavior for legacy list encoding.
blocks-schema-ddbexpr/​src/​main/​scala/​zio/​dynamodb/​blocks/​schema/​ddbexpr/​DdbUpdateExprInterpreter.scala Validates set update operands before constructing DynamoDB update actions.

Review effort: Lite

@googley42
googley42 marked this pull request as ready for review November 29, 2026 11:27
@googley42
googley42 merged commit 6110c0d 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