Skip to content

[FlatPostgresCollection] Implement bulkCreateOrReplaceReturnOlder + drop + Bugfix for delete(key) always returning true#286

Merged
suddendust merged 5 commits intomainfrom
flat_bulkCreateOrReplaceAndReturn
Apr 9, 2026
Merged

[FlatPostgresCollection] Implement bulkCreateOrReplaceReturnOlder + drop + Bugfix for delete(key) always returning true#286
suddendust merged 5 commits intomainfrom
flat_bulkCreateOrReplaceAndReturn

Conversation

@suddendust
Copy link
Copy Markdown
Contributor

@suddendust suddendust commented Apr 9, 2026

Description

This PR contains three changes:

  1. [BugFix] FlatPostgresCollection#bulkUpsert had a bug where it would replace missing columns in the query with null. It now has proper merge semantics.
  2. Introduce a new API Collection#bulkCreateOrReplaceReturnOlder and implement it for FlatPostgresCollection. This is similar to FlatPostgresCollection#bulkUpsertReturnOlder but with replace (instead of merge) semantics.
  3. [Bugfix] FlatPostgresCollection#delete(key) would always return true even if no rows were deleted - This was divergent with Mongo's behaviour. So this has been fixed.
  4. Implement FlatPostgresCollection#drop. This is now rolled back.

Testing

Added integration tests + compatibility tests.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.51%. Comparing base (2fe1f90) to head (8a18b2d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...documentstore/postgres/FlatPostgresCollection.java 90.90% 2 Missing and 1 partial ⚠️
.../org/hypertrace/core/documentstore/Collection.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #286      +/-   ##
============================================
+ Coverage     81.30%   81.51%   +0.21%     
- Complexity     1521     1531      +10     
============================================
  Files           241      241              
  Lines          7305     7334      +29     
  Branches        700      702       +2     
============================================
+ Hits           5939     5978      +39     
+ Misses          924      915       -9     
+ Partials        442      441       -1     
Flag Coverage Δ
integration 81.51% <88.23%> (+0.21%) ⬆️
unit 56.32% <58.82%> (+0.91%) ⬆️

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Test Results

  120 files  + 7    120 suites  +7   38s ⏱️ ±0s
  810 tests +18    809 ✅ +18  1 💤 ±0  0 ❌ ±0 
1 147 runs  +18  1 146 ✅ +18  1 💤 ±0  0 ❌ ±0 

Results for commit 8a18b2d. ± Comparison against base commit 2fe1f90.

This pull request removes 27 and adds 45 tests. Note that renamed tests count towards both.
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should bulk createOrReplace multiple new documents
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should bulk createOrReplace replacing existing documents and reset missing cols to default
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should bulk upsert documents with different column sets
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should bulk upsert multiple new documents
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should bulk upsert updating existing documents
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should bulk upsert with mixed inserts and updates
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should handle empty document map
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should handle empty document map for bulkCreateOrReplace
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should handle null document map
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkOperationTests ‑ Should handle null document map for bulkCreateOrReplace
…
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkCreateOrReplaceTests ‑ Should bulk create new documents and replace existing ones
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder ‑ Should return empty iterator for empty document map
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder ‑ Should return empty iterator for null document map
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder ‑ Should return empty iterator when upserting new documents (no old docs exist)
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder ‑ Should return old documents when updating existing documents
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder ‑ Should return only existing old documents in mixed insert/update scenario
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder ‑ Should throw IOException when bulkUpsert fails
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder$BulkCreateOrReplaceTests ‑ Should bulk createOrReplace and return older documents with JSONB and arrays
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder$BulkCreateOrReplaceTests ‑ Should bulk createOrReplace multiple new documents
org.hypertrace.core.documentstore.FlatCollectionWriteTest$BulkUpsertAndReturnOlder$BulkCreateOrReplaceTests ‑ Should bulk createOrReplace replacing existing documents and reset missing cols to default
…

♻️ This comment has been updated with latest results.

@Override
public void drop() {
throw new UnsupportedOperationException(WRITE_NOT_SUPPORTED);
String dropTableSQL = String.format("DROP TABLE IF EXISTS %s", tableIdentifier);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do we really need this? For postgres we haven't been creating table using this route, deletion should probably not happen through this route.

Copy link
Copy Markdown
Contributor Author

@suddendust suddendust Apr 9, 2026

Choose a reason for hiding this comment

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

I added this method for completeness sake, since we have this for Mongo. If any direct clients want to use it, they'd have an option.

Copy link
Copy Markdown

@puneet-traceable puneet-traceable Apr 9, 2026

Choose a reason for hiding this comment

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

I am ok with it being there. Might be useful just for tests.

The way I am thinking about it is: if drop is exposed here, then corresponding createTable should also happen via this route. A simple create is also fine. But any other DDL on the table will be very hard. So my personal recommendation is to have all of this happen outside or we build comprehensive ddl support.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As discussed, table management is not supported via this interface, so I have removed this impl.

@suresh-prakash
Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@suddendust suddendust merged commit f6614c6 into main Apr 9, 2026
7 checks passed
@suddendust suddendust deleted the flat_bulkCreateOrReplaceAndReturn branch April 9, 2026 10:17
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.

3 participants