Skip to content

Implement ADD Subdoc Update for FlatPostgresCollection#272

Merged
suddendust merged 5 commits intohypertrace:mainfrom
suddendust:pg_write_subdoc_add
Feb 20, 2026
Merged

Implement ADD Subdoc Update for FlatPostgresCollection#272
suddendust merged 5 commits intohypertrace:mainfrom
suddendust:pg_write_subdoc_add

Conversation

@suddendust
Copy link
Contributor

@suddendust suddendust commented Feb 6, 2026

Add ADD sub-document update operator for flat collections

Summary

Implements the ADD operator for FlatPostgresCollection, enabling atomic numeric increment/decrement operations on both top-level columns and nested JSONB fields.

Changes

  • Added [FlatCollectionSubDocAddOperatorParser] to handle ADD operations
  • Registered the parser in FlatPostgresCollection.SUB_DOC_UPDATE_PARSERS

SQL Generated

Scenario Generated SQL
Top-level column "price" = COALESCE("price", 0) + ?::integer
Nested JSONB "metrics" = jsonb_set(COALESCE("metrics", '{}'), '{sales,total}'::text[], (COALESCE("metrics"#>>'{sales,total}', '0')::integer + ?::integer)::text::jsonb, true)

Features

  • Type-aware: Uses column schema type for top-level, infers from Java value type for JSONB. This information is then use for the apt type-cast.
  • NULL-safe: COALESCE handles NULL columns/fields (treats as 0)
  • Creates missing JSONB keys via jsonb_set(..., true)

@suddendust suddendust changed the title Subdoc update - ADD Implement ADD Subdoc Update for FlatPostgresCollection Feb 6, 2026
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 80.85106% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.71%. Comparing base (65909a2) to head (92ef9a2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../parser/FlatCollectionSubDocAddOperatorParser.java 80.00% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #272      +/-   ##
============================================
+ Coverage     80.68%   80.71%   +0.02%     
- Complexity     1396     1398       +2     
============================================
  Files           240      241       +1     
  Lines          6882     6928      +46     
  Branches        638      642       +4     
============================================
+ Hits           5553     5592      +39     
- Misses          914      919       +5     
- Partials        415      417       +2     
Flag Coverage Δ
integration 80.71% <80.85%> (+0.02%) ⬆️
unit 52.88% <10.63%> (-0.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


assertTrue(result.isPresent());
JsonNode resultJson = OBJECT_MAPPER.readTree(result.get().toJson());
assertEquals(100, resultJson.get("price").asInt());

Choose a reason for hiding this comment

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

do we do something for these operations to be idempotent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, for this method that'd depend on the filter query containing a CAS clause, which the client has to pass. Something like lastUpdatedTime. document-store by itself doesn't care about idempotency.

@suddendust suddendust merged commit 3504ce4 into hypertrace:main Feb 20, 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.

2 participants