8 Inline Augmentation: JSON Field Generation
Instead of mapping a JSON field directly to a relational column, a JSON-relational duality view can generate the field. Generated fields and fields mapped to columns can be hidden, that is, not shown in documents supported by the view.
The computation of a generated field value can use the values of other fields defined by the duality view, including other generated fields, whether those fields are hidden or are present in the supported documents.
points of
a racing-team document as being generated by a path expression that sums the
points fields of the team's driversFoot 1:points @generated (path : "$.driver.points.sum()")
Read and write document augmentation differ:
-
When a document that's supported by a duality view is read, it is augmented by adding new fields.
-
When a document is written, it is augmented by adding fields or by overriding the values of fields in the document. A given write augmentation does one of the following:
-
Always provide a field with a generated value. It is an error for the incoming document to already have that field.
-
Provide a missing field, using a default value. If the field is present in the incoming document then it is kept.
-
Substitute a different value for a field that's present in the document. The field value is derived dynamically from the values of other fields in the document.
-
When document augmentation (read or write) is defined inline, in the sense that the definition of the augmentation is part of the duality-view definition/creation code (DDL), we speak of inline augmentation, the subject of this chapter.
For inline read augmentation, a duality view can generate a field using using a SQL/JSON path expression (as shown above), a SQL expression, or a SQL query. For inline write augmenation, it can only use a path expression to generate a field.
_________________________________________________________
Footnote Legend
Footnote 1: See Example 8-2 for the full team duality-view definition.