Skip to content

[Draft] Add MongoPostgresWriteConsistencyTest#280

Open
suddendust wants to merge 39 commits intohypertrace:mainfrom
suddendust:bugfix_setSubDocOp
Open

[Draft] Add MongoPostgresWriteConsistencyTest#280
suddendust wants to merge 39 commits intohypertrace:mainfrom
suddendust:bugfix_setSubDocOp

Conversation

@suddendust
Copy link
Contributor

@suddendust suddendust commented Mar 8, 2026

This PR adds exhaustive MongoPostgresWriteConsistencyTest to ensure functional parity b/w Mongo and Postgres write implementations. In addition to this, it also:

  1. Fixes a bug in PostgresResultIteratorWithBasicTypes in which float4/real values were cast to strings. So say we have a field ratings with is a real field - It would appear as "4.3" in Document instead of 4.3 (Mongo behaves correctly so this fix is added for functional compatibility).
  2. Added checks on the type of input in update parsers for fail-fast. This is inline with Mongo's behaviour.
  3. Handle array fields properly in SET update parsers to parse them as a single value.
  4. Fix the return behaviour of Collection#upsert for PG. Till now, it returns true if a new doc is created, false if it's updated. This is not inline with the contract or Mongo's behaviour - So now, it returns true if it succeeds.
  5. Handle SET on entire JSONB columns properly.
  6. Unset based on type.

}
break;

case "float4":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently for PG, this returns the value as a string. This is not the behaviour in Mongo, so added a fix here. Validated this in the compatibility test.


@Override
public String parseNonJsonbField(final UpdateParserInput input) {
if (!input.isArray()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this check to make this compatible with Mongo.

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 92.18750% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.12%. Comparing base (9254122) to head (7a3b611).

Files with missing lines Patch % Lines
...ostgres/update/parser/PostgresUnsetPathParser.java 33.33% 2 Missing and 2 partials ⚠️
...documentstore/postgres/FlatPostgresCollection.java 96.29% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #280      +/-   ##
============================================
- Coverage     81.12%   81.12%   -0.01%     
- Complexity     1480     1485       +5     
============================================
  Files           240      240              
  Lines          7072     7124      +52     
  Branches        667      674       +7     
============================================
+ Hits           5737     5779      +42     
- Misses          911      915       +4     
- Partials        424      430       +6     
Flag Coverage Δ
integration 81.12% <92.18%> (-0.01%) ⬇️
unit 55.22% <21.87%> (-0.14%) ⬇️

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.

…setSubDocOp

# Conflicts:
#	document-store/src/integrationTest/java/org/hypertrace/core/documentstore/MongoPostgresWriteConsistencyTest.java
#	document-store/src/main/java/org/hypertrace/core/documentstore/postgres/update/parser/PostgresSetValueParser.java
@suddendust suddendust changed the title [Draft] [Bugfix] set sub doc op Add MongoPostgresWriteConsistencyTest Mar 9, 2026
if (isTopLevel && colMeta.isArray() && paramValue != null) {
Object[] arrayValues = (Object[]) paramValue;
Array sqlArray =
connection.createArrayOf(colMeta.getPostgresType().getSqlType(), arrayValues);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JDBC can't bind Object[] directly to array columns like TEXT[]. It requires java.sql.Array. So convert the Java array to JDBC Array.

@puneet-traceable
Copy link

@suddendust This is such a big chunk of change in tests, how are you ensuring that you are not changing tests behaviour?

@suddendust
Copy link
Contributor Author

@puneet-traceable So this PR contains changes in two tests:

  1. MongoPostgresWriteConsistencyTest: This is totally owned by me and the version that exists till now is rudimentary. This PR makes it exhaustive so it's better.
  2. FlatCollectionWriteTest: This again is totally owned by me and I have added more exhaustive tests on the write path. You'll find that I have changed assertions at certain places. This is due to the bugs discovered via the compatibility tests (the list of bugs is in the PR description), which were fixed and which in-turn changed the behaviour. For example:

Fix the return behaviour of Collection#upsert for PG. Till now, it returns true if a new doc is created, false if it's updated. This is not inline with the contract or Mongo's behaviour - So now, it returns true if it succeeds.

So you'll find the I now do an assertTrue instead of assertFalse at certain places where I am testing upserts.

At no place any Mongo write tests have been touched.

suresh-prakash
suresh-prakash previously approved these changes Mar 12, 2026
input.getParamsBuilder().addObjectParam(values);
} else {
// For scalar columns, use standard value parser (ignore returned JSONB expression)
input
Copy link
Contributor

Choose a reason for hiding this comment

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

Bit confused here. If the result/return value is ignored, then, why call this in the first place?

@suddendust suddendust changed the title Add MongoPostgresWriteConsistencyTest [Draft] Add MongoPostgresWriteConsistencyTest Mar 12, 2026
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