Chapter 8 - Metadata, Automation, Code Generation
This section contains the sample code related to chapter 8 of Data Engine Thinking: metadata, automation, and code generation.
Sections
Section titled “Sections”Equivalent Load Patterns
Section titled “Equivalent Load Patterns”Templates give you the freedom to express the same design in your own preferred syntax. Because the templates are independent from the design metadata, the same metadata can be rendered into different — but equivalent — code: the data model stays stable while the generated logic can change gradually and improve incrementally, without impacting the design of the data logistics overall.
Both queries below load only the new rows and return the same result set — one with NOT EXISTS, the other with a LEFT OUTER JOIN. They use the same values from the design metadata, applied in a different way by a different template.
/******************************************************************************* * Data Engine Thinking ******************************************************************************* * * Purpose: * - Two equivalent ways to load only the new rows, generated from the same * design metadata. Both return the same result set; only the template * that produced them differs. * * Disclaimer: * - See disclaimer.md in the repository root. * ******************************************************************************/
-- Using NOT EXISTS:INSERT INTO Products (ProductName, SalePrice)SELECT PrdNm, PrdValueFROM products srcWHERE NOT EXISTS ( SELECT NULL FROM ProductMaster tgt WHERE src.PrdNm = tgt.ProductName )
-- Using a LEFT OUTER JOIN:INSERT INTO ProductMaster (ProductName, SalePrice)SELECT PrdNm, PrdValueFROM products srcLEFT OUTER JOIN ProductMaster tgt ON src.PrdNm = tgt.ProductNameWHERE tgt.ProductName IS NULL