Skip to content

Commit b3b8ba0

Browse files
committed
Sample updates
1 parent 0fdec03 commit b3b8ba0

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

Virtual_EDW/Templates/templateCollection.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"TemplateFilePath": "templateHubView.handlebars",
88
"TemplateNotes": "Standard Hub template - display the distinct list of Business Keys for a Core Business Concept."
99
},
10+
{
11+
"TemplateName": "100 Data Vault Hub View Template With Delivery Key",
12+
"TemplateType": "CoreBusinessConcept",
13+
"TemplateConnectionKey": "PsaConnectionInternalId",
14+
"TemplateOutputFileConvention": "{targetDataObject.name}.sql",
15+
"TemplateFilePath": "templateHubViewWithDeliveryKey.handlebars",
16+
"TemplateNotes": "Standard Hub template - display the distinct list of Business Keys for a Core Business Concept."
17+
},
1018
{
1119
"TemplateName": "100 Data Vault Link View Template",
1220
"TemplateType": "NaturalBusinessRelationship",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--
2+
-- Hub View definition for {{generationSpecificMetadata.selectedDataObject.name}}
3+
--
4+
-- This template represents a standard Data Vault style 'Hub' table as a view.
5+
-- The view shows the same data as would otherwise be the case if the table would be created and all data logistics processes run.
6+
--
7+
8+
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[{{metadataConfiguration.vdwSchemaName}}].[{{generationSpecificMetadata.selectedDataObject.name}}]') AND type in (N'V'))
9+
DROP VIEW [{{metadataConfiguration.vdwSchemaName}}].[{{generationSpecificMetadata.selectedDataObject.name}}]
10+
GO
11+
12+
CREATE VIEW [{{metadataConfiguration.vdwSchemaName}}].[{{generationSpecificMetadata.selectedDataObject.name}}] AS
13+
SELECT {{#each dataObjectMappings}}{{#if @first}}
14+
{{#each businessKeys}} {{#if @first}}hub.[{{surrogateKey}}],{{/if}}{{/each}}
15+
hub.[{{../metadataConfiguration.etlProcessAttribute}}],
16+
hub.[{{../metadataConfiguration.loadDateTimeAttribute}}],{{#each businessKeys}}{{#each businessKeyComponentMapping}}
17+
hub.[{{targetDataItem.name}}],{{/each}}{{/each}}
18+
ROW_NUMBER() OVER ( ORDER BY
19+
[{{../metadataConfiguration.loadDateTimeAttribute}}],{{#each businessKeys}}{{#each businessKeyComponentMapping}}
20+
[{{targetDataItem.name}}]{{#unless @last}},{{/unless}}{{/each}}{{/each}}
21+
) AS DATA_DELIVERY_KEY
22+
{{/if}}{{/each}}
23+
FROM (
24+
{{#each dataObjectMappings}}{{#if @first}}
25+
SELECT
26+
HASHBYTES('MD5', {{#each businessKeys}} {{#if @first}} {{!-- Create the Surrogate Key using the Business Key and components --}}
27+
{{#each businessKeyComponentMapping}}
28+
ISNULL(RTRIM(CONVERT(NVARCHAR(100), {{targetDataItem.name}})), 'N/A') + '#~!'{{#unless @last}} +{{/unless}}
29+
{{/each}}
30+
) AS {{surrogateKey}},{{/if}}{{/each}}
31+
-1 AS {{../metadataConfiguration.etlProcessAttribute}},
32+
MIN({{../metadataConfiguration.loadDateTimeAttribute}}) AS {{../metadataConfiguration.loadDateTimeAttribute}},
33+
--{{../metadataConfiguration.recordSourceAttribute}},{{#each businessKeys}} {{!-- The Hub business key --}}
34+
{{#each businessKeyComponentMapping}}
35+
{{targetDataItem.name}},{{/each}}{{/each}}
36+
ROW_NUMBER() OVER (PARTITION BY {{#each businessKeys}}{{#each businessKeyComponentMapping}} {{!-- Create a row number to enable selection only the earliest row, ordered by date/time --}}
37+
{{targetDataItem.name}}{{#unless @last}},{{/unless}}{{/each}}
38+
{{/each}}
39+
ORDER BY
40+
MIN({{../metadataConfiguration.loadDateTimeAttribute}})
41+
) AS ROW_NR
42+
FROM
43+
( {{/if}}{{/each}}
44+
{{#each dataObjectMappings }}
45+
SELECT {{#each businessKeys}}{{#each businessKeyComponentMapping}}
46+
CAST({{sourceDataItems.0.name}} AS NVARCHAR(100)) AS {{targetDataItem.name}},{{/each}}{{/each}}
47+
--{{../metadataConfiguration.recordSourceAttribute}},
48+
MIN({{../metadataConfiguration.loadDateTimeAttribute}}) AS {{../metadataConfiguration.loadDateTimeAttribute}}
49+
FROM [{{sourceDataObjects.0.dataObjectConnection.extensions.0.value}}].[{{sourceDataObjects.0.dataObjectConnection.extensions.1.value}}].[{{sourceDataObjects.0.name}}]
50+
WHERE {{#each businessKeys}}{{#each businessKeyComponentMapping}}
51+
{{sourceDataItems.0.name}} IS NOT NULL{{#unless @last}} AND{{/unless}}{{/each}}{{/each}}
52+
{{#if filterCriterion}}AND {{filterCriterion}}{{/if}}
53+
GROUP BY
54+
{{#each businessKeys}}{{#each businessKeyComponentMapping}}{{#each sourceDataItems}}{{#stringcompare isHardCodedValue "True"}}{{else}}{{name}}{{#unless @last}},{{/unless}}{{/stringcompare}}{{/each}}{{/each}}{{/each}}
55+
-- {{../metadataConfiguration.recordSourceAttribute}}
56+
{{#unless @last}}UNION{{/unless}}
57+
{{/each}}
58+
) HUB_selection {{#each dataObjectMappings}}{{#if @first}}
59+
GROUP BY {{#each businessKeys}}{{#each businessKeyComponentMapping}}
60+
{{targetDataItem.name}}{{#unless @last}},{{/unless}}{{/each}}{{/each}}
61+
--{{../metadataConfiguration.recordSourceAttribute}} {{/if}}{{/each}}
62+
) hub
63+
WHERE ROW_NR = 1
64+
UNION
65+
SELECT
66+
0x00000000000000000000000000000000,
67+
- 1,
68+
'1900-01-01',
69+
--'Data Warehouse',{{#each dataObjectMappings}}{{#if @first}}{{#each businessKeys}}{{#each businessKeyComponentMapping}}
70+
'Unknown',{{/each}}{{/each}}{{/if}}{{/each}}
71+
0 AS DATA_DELIVERY_KEY

Virtual_EDW/Templates/templateSatelliteViewWithDeliveryKey.Handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ SELECT
5555
ROW_NUMBER() OVER (
5656
ORDER BY {{#each businessKeys}}{{#each businessKeyComponentMapping}} {{!-- Create a row number to enable selection only the earliest row, ordered by date/time --}}
5757
{{targetDataItem.name}},{{/each}}{{/each}}
58-
{{#each dataItemMappings}}{{#each targetDataItem.dataItemClassification}}{{#if classification}}{{../sourceDataItems.0.name}},{{/if}}{{/each}}{{/each}}
58+
{{#each dataItemMappings}}{{#each targetDataItem.dataItemClassification}}{{#if classification}}{{../targetDataItem.name}},{{/if}}{{/each}}{{/each}}
5959
{{../metadataConfiguration.loadDateTimeAttribute}},
6060
{{../metadataConfiguration.sourceRowIdAttribute}}
61-
) AS DELIVERY_KEY
61+
) AS DATA_DELIVERY_KEY
6262
FROM
6363
(
6464
SELECT

0 commit comments

Comments
 (0)