-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
In MQL we have fields with null values, and missing fields, and their semantics is different. The former has a counterpart in SQL/HQL (though, semantics of the null values there is different from that in MQL), while the latter does not and cannot exist in SQL/HQL. The concept of missing fields exists in MQL/BSON due to the schema-on-read approach, where a reader decides on the set of fields to be read from a BSON document, potentially disregarding the set of fields that exist in the document. Consequently, we probably have no choice but to make the semantics of missing fields and the semantics of null fields equivalent in our extension of Hibernate ORM, despite those not being identical in MQL. Here is an example:
- inserting equal entities via Hibernate ORM normally, or using dynamic insert, should result in equal entities and equivalent data;
- the inserted data is potentially different: normal inserts produce null fields, while dynamic inserts result in missing fields;
- therefore, null fields should be made equivalent to missing fields.
We also should take into account scenarios where the data is given to us (it may be produced by the relational migrator), i.e., dynamically inserted entities is not the only source of missing fields.
- Do we store BSON fields with null values, or do we omit them?
- Do we store BSON array fields with empty arrays, or do we omit them?
- If we omit them, do we read them back as if they were stored with the explicit null or the explicit empty array value?
- Do we store BSON document fields with empty documents, or do we omit them?
- If we omit them, do we read them back as if they were stored with the explicit null or the explicit empty document value?
I think, that empty arrays and documents should be stored as empty, and not omitted.
Relevant/important links/references:
- https://mongodb.slack.com/archives/C07K0TU8GKW/p1739311817506979
(or,
if the Slack discussion expired).
- https://github.com/mongodb/mongosql/blob/main/semantics.md#null--missing (maybe even https://github.com/mongodb/mongosql/blob/main/mongosql/src/air/desugarer/sql_null_semantics_operators.rs).
- $ifNull
- $type, allows detecting missing fields
- $cond, we may have to use it to make the semantics of null fields and missing fields equivalent
- BasicInsertionTests.testEntityWithNullFieldValueInsertion
- MongoAdditionalMappingContributor.contribute, which currently forbids dynamic inserts, as well as MongoResultSet.getValue, which currently forbids reading data with missing fields.
Addressing the source code notes tagged with TODO-HIBERNATE-48 is in scope of this ticket.
- is depended on by
-
HIBERNATE-71 'is Null' ('is not null') MQL translation
-
- Ready for Work
-
- related to
-
HIBERNATE-74 null/missing field comparison MQL translation
-
- Ready for Work
-