Mapping Working Group | Mike Gorrell The task: We have over 80 Derived Tables scripts that currently extract JSON objects/arrays Metadb 1.4 can do this for us automatically by creating appropriate MAPPING commands We need to create the MAPPINGs
For today: Review Metadb documentation which outlines how to create these mappings Example of a Mapping created from a derived table creation script. From the po_lines_cost.sql script: jsonb_extract_path_text(pol.jsonb, 'cost', 'listUnitPrice')::numeric(19,4) AS po_line_list_unit_price_phys,
jsonb_extract_path_text(pol.jsonb, 'cost', 'quantityPhysical') AS po_line_quant_phys,
jsonb_extract_path_text(pol.jsonb, 'cost', 'listUnitPriceElectronic')::numeric(19,4) AS po_line_list_unit_price_elec,
jsonb_extract_path_text(pol.jsonb, 'cost', 'quantityElectronic') AS po_line_quant_elec,
jsonb_extract_path_text(pol.jsonb, 'cost', 'additionalCost')::numeric(19,4) AS po_line_additional_cost,
jsonb_extract_path_text(pol.jsonb, 'cost', 'currency') AS po_line_currency,
jsonb_extract_path_text(pol.jsonb, 'cost', 'discount')::numeric(19,4) AS po_line_discount,
jsonb_extract_path_text(pol.jsonb, 'cost', 'discountType') AS po_line_discount_type,
jsonb_extract_path_text(pol.jsonb, 'cost', 'poLineEstimatedPrice')::numeric(19,4) AS po_line_estimated_price
TO this in the Mapping file CREATE DATA MAPPING FOR json FROM TABLE folio_orders.po_line__ COLUMN jsonb PATH '$.cost' TO 'cost';
Meta analysis. I have written a script that tries to collect all Fields+Tables that are being extracted. This might speed up the analysis See the Derived Table JSON Mappings Workgroup folder on the Reporting SIG google drive folder to contribute to this project mapping assignments to divvy up the work examples to see how to do the mappings questions about how to do the mappings
Notes: -multiple derived tables may be extracting the same data fields in the data arrays, so need to make sure we do not have duplicates -see create json mappings section of Metadb documentation | -What would be the new name of the table after mapping? Is the suffix taken from the value of TO and "pasted" behind the underscores? (They are going to the “__t” tables)I have clarity around which tables the transformed data will appear in. Let’s refer to the documentation https://metadb.dev/doc/#_create_data_mapping There is an image of the data we are working with: Image AddedAnd the CREATE DATA MAPPING commands: Code Block |
---|
CREATE DATA MAPPING FOR json
FROM TABLE library.inventory__ COLUMN jsondata PATH '$'
TO 't';
CREATE DATA MAPPING FOR json
FROM TABLE library.inventory__ COLUMN jsondata PATH '$.metadata'
TO 'metadata';
CREATE DATA MAPPING FOR json
FROM TABLE library.inventory__ COLUMN jsondata PATH '$.tags'
TO 'tags';
CREATE DATA MAPPING FOR json
FROM TABLE library.inventory__ COLUMN jsondata PATH '$.tags.tagList'
TO 'taglist'; |
Mapping a JSON object creates columns, and mapping a JSON array creates a table. The only array in this example is tagList . This results in an inventory__taglist table. Everything else results in columns in the corresponding parent table, which in this case is inventory__t .The outermost object is a special case because there is no parent table. So it results in the top-level inventory__t table.But if you imagine there is already a table inventory__t , the top-level columns and nested objects are added to it. |