Bugfix for postgres - #49
Open
shiling wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Tests for Postgres + CockroachDB which were failing before are now passing. |
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.
Bug
There are two failing tests for postgres, these are the raw logs:
They indicate
DataObject.saveAllandDataObject.saveDeltafail to save deleted properties when using Postgres backend.Diagnosis
When a user calls
testObject.remove("prop")and saves the object using.saveDelta()or.saveAll(), the backend is expected to remove"prop"from the JSON column in the database. However, inPostgresJsonb_DataObjectMap.DataObjectRemoteDataMap_update, updates are applied via a nativeON CONFLICTupsert with the followingDO UPDATEclause:The issue:
In PostgreSQL/CockroachDB, the JSONB concatenation operator
||merges two JSONB documents. Since the deleted keys are omitted fromEXCLUDED.data(serialized asnullor skipped), the concatenation operator||retains their old values from the left-hand operand (dataStorageTable.data) instead of deleting them.Additionally, under partial saves (
saveDelta()), if a non-binary field was modified,serializeDataMapwould only process keys within the deltakeySet, causingbinMap(and thusbData) to serialize tonulland inadvertently drop any existing binary properties on conflict update.Fix
PostgresJsonb_DataObjectMap.java):• We now analyze the list of keys to be processed and detect if any keys are deleted/removed (their value is
nullorObjectToken.NULLin fullMap).• If there are deleted keys, we dynamically append PostgreSQL's jsonb subtraction operator (
- 'key') to the on-conflict upsert statement, e.g.:This cleanly and safely drops the removed keys from the merged JSONB document.
JsonbUtils.java):• Modified
serializeDataMapto always build the binary map (binMap) from the complete set of existing fields (fullSet) instead of the partial deltakeySet. This guarantees that existing binary properties are always preserved during partial updates to JSON properties.