Skip to content

Commit 6ffa925

Browse files
author
Hugo Rialan
authored
Merge pull request #21 from devoteamgcloud/dev-hugo
V2 Release
2 parents 152e8e5 + ee686c2 commit 6ffa925

12 files changed

+33
-29
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11

22
.df-credentials.json
33
node_modules/
4+
5+
.DS_Store

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ const commonAssertionsResult = commonAssertions({
5454
"disabledInEnvs": ["dv"] // Check match with 'dataform.projectConfig.vars.env' value
5555
},
5656
rowConditions: {
57-
"your_table": {
58-
"id_not_null": "id IS NOT NULL",
57+
"your_schema": {
58+
"your_table": {
59+
"id_not_null": "id IS NOT NULL",
60+
}
5961
}
6062
}
6163
});

dataform.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"defaultDatabase": "sandbox-hrialan",
66
"defaultLocation": "EU",
77
"vars":{
8-
"env":"dv"
8+
"env":"dv",
9+
"example":""
910
}
1011
}

definitions/example.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ const commonAssertionsResult = commonAssertions({
1212
// "disabledInEnvs": ["dv", "qa"]
1313
},
1414
config: {
15-
"first_table": {
16-
"where": "updated_date >= CURRENT_DATE() - 7"
17-
},
15+
"dataform": {
16+
"first_table": {
17+
"where": "updated_date >= CURRENT_DATE() - 7"
18+
}
19+
}
1820
},
1921
rowConditions: {
2022
// Format: "schema": { "table": { "conditionName": "conditionQuery", ... }, ... }
21-
"dataform": {
23+
["dataform" + dataform.projectConfig.vars.example]: {
2224
"first_table": {
2325
"id_not_null": "id IS NOT NULL",
2426
"id_strict_positive": "id > 0"
@@ -45,10 +47,7 @@ const commonAssertionsResult = commonAssertions({
4547
"timeZone": "America/Los_Angeles"
4648
},
4749
"second_table": {
48-
// If timeUnit is not DAY, WEEK, MONTH, QUARTER, or YEAR, dateColumn should be a TIMESTAMP.
49-
// Check here for valid Date time units: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_diff
50-
// Check here for valid Timestamp time units: https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#timestamp_diff
51-
"dateColumn": "TIMESTAMP(updated_date)",
50+
"dateColumn": "updated_date",
5251
"timeUnit": "HOUR",
5352
"delayCondition": 3,
5453
"timeZone": "-08"

includes/data_completeness_assertions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file contains a function to create data completeness assertions for specific tables and columns in a database.
55
* The assertions are used to check if the percentage of null values in each specified column exceeds an allowed limit.
66
* The conditions for data completeness checks are defined in an object format:
7-
* { tableName: { columnName: allowedPercentageNull, ... }, ... }
7+
* schemaName : { tableName: { columnName: allowedPercentageNull, ... }, ... }
88
*
99
* The function `createDataCompletenessAssertion` takes in global parameters, a table name, and column conditions to create these assertions.
1010
*/
@@ -59,7 +59,7 @@ module.exports = (globalParams, config, dataCompletenessConditions) => {
5959
const tableNames = dataCompletenessConditions[schemaName];
6060
for (let tableName in tableNames) {
6161
const columnConditions = tableNames[tableName];
62-
const filter = config[tableName]?.where ?? true;
62+
const filter = config[schemaName][tableName]?.where ?? true;
6363
createDataCompletenessAssertion(globalParams, schemaName, tableName, filter, columnConditions);
6464
}
6565
}

includes/data_freshness_assertions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
const assertions = [];
2222

23-
const createDataFreshnessAssertion = (globalParams, schemaName, tableName, filter, delayCondition, timeUnit, dateColumn) => {
23+
const createDataFreshnessAssertion = (globalParams, schemaName, tableName, filter, delayCondition, timeUnit, dateColumn, timeZone = "UTC") => {
2424
const assertion = assert(`assert_freshness_${schemaName}_${tableName}`)
2525
.database(globalParams.database)
2626
.schema(globalParams.schema)
@@ -40,7 +40,7 @@ const createDataFreshnessAssertion = (globalParams, schemaName, tableName, filte
4040
SELECT
4141
${["DAY", "WEEK", "MONTH", "QUARTER", "YEAR"].includes(timeUnit)
4242
? `DATE_DIFF(CURRENT_DATE("${timeZone}"), MAX(${dateColumn}), ${timeUnit})`
43-
: `TIMESTAMP_DIFF(CURRENT_TIMESTAMP(), MAX(${dateColumn}), ${timeUnit})`} AS delay
43+
: `TIMESTAMP_DIFF(CURRENT_TIMESTAMP(), TIMESTAMP(MAX(${dateColumn}),"${timeZone}"), ${timeUnit})`} AS delay
4444
FROM
4545
filtering
4646
)
@@ -59,7 +59,6 @@ const createDataFreshnessAssertion = (globalParams, schemaName, tableName, filte
5959
assertions.push(assertion);
6060
};
6161

62-
6362
module.exports = (globalParams, config, freshnessConditions) => {
6463
// Loop through freshnessConditions to create assertions.
6564
for (let schemaName in freshnessConditions) {
@@ -68,10 +67,11 @@ module.exports = (globalParams, config, freshnessConditions) => {
6867
const {
6968
delayCondition,
7069
timeUnit,
71-
dateColumn
70+
dateColumn,
71+
timeZone
7272
} = tableNames[tableName];
73-
const filter = config[tableName]?.where ?? true;
74-
createDataFreshnessAssertion(globalParams, schemaName, tableName, delayCondition, timeUnit, dateColumn);
73+
const filter = config[schemaName][tableName]?.where ?? true;
74+
createDataFreshnessAssertion(globalParams, schemaName, tableName, filter, delayCondition, timeUnit, dateColumn, timeZone);
7575
}
7676
}
7777

includes/referential_integrity_assertions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file contains a function to create referential integrity assertions for specific tables in a database.
55
* The assertions are used to check if the foreign key relationships are maintained between tables.
66
* The conditions for referential integrity checks are defined in an object format:
7-
* { parentTable: [{ parentKey, childTable, childKey }, ...], ... }
7+
* schemaName : { parentTable: [{ parentKey, childTable, childKey }, ...], ... }
88
*
99
* The function `createReferentialIntegrityAssertions` takes in global parameters and the referential integrity conditions.
1010
*/
@@ -68,7 +68,7 @@ module.exports = (globalParams, config, referentialIntegrityConditions) => {
6868
const parentTables = referentialIntegrityConditions[parentSchema];
6969
for (let parentTable in parentTables) {
7070
const relationships = parentTables[parentTable];
71-
const parentFilter = config[parentTable]?.where ?? true;
71+
const parentFilter = config[parentSchema][parentTable]?.where ?? true;
7272

7373
relationships.forEach(({
7474
parentKey,

includes/row_condition_assertions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file contains a function to create row condition assertions for specific tables in a database.
55
* The assertions are used to check if the rows in each specified table meet a certain condition.
66
* The conditions for row checks are defined in an object format:
7-
* { tableName: { conditionName: conditionQuery, ... }, ... }
7+
* schemaName : { tableName: { conditionName: conditionQuery, ... }, ... }
88
*
99
* The function `createRowConditionAssertion` takes in global parameters, a table name, a condition name, and a condition query to create these assertions.
1010
*/
@@ -56,7 +56,7 @@ module.exports = (globalParams, config, rowConditions) => {
5656
for (let tableName in tableNames) {
5757
for (let conditionName in tableNames[tableName]) {
5858
const conditionQuery = tableNames[tableName][conditionName];
59-
const filter = config[tableName]?.where ?? true;
59+
const filter = config[schemaName][tableName]?.where ?? true;
6060
createRowConditionAssertion(
6161
globalParams,
6262
schemaName,

includes/unique_key_assertions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file contains a function to create unique key assertions for specific tables in a database.
55
* The assertions are used to check if the combination of values in specified columns forms a unique key for each row in the table.
66
* The conditions for unique key checks are defined in an object format:
7-
* { tableName: [column1, column2, ...], ... }
7+
* schemaName : { tableName: [column1, column2, ...], ... }
88
*
99
* The function `createUniqueKeyAssertion` takes in global parameters, a table name, and an array of column names to create these assertions.
1010
*/
@@ -57,7 +57,7 @@ module.exports = (globalParams, config, uniqueKeyConditions) => {
5757
const tableNames = uniqueKeyConditions[schemaName];
5858
for (let tableName in tableNames) {
5959
const columns = tableNames[tableName];
60-
const filter = config[tableName]?.where ?? true;
60+
const filter = config[schemaName][tableName]?.where ?? true;
6161
createUniqueKeyAssertion(globalParams, schemaName, tableName, filter, columns);
6262
}
6363
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = ({
4545
const uniqueKeyAssertionsResult = unique_key_assertions(globalAssertionsParams, config, uniqueKeyConditions);
4646
const dataFreshnessAssertionsResult = data_freshness_assertions(globalAssertionsParams, config, dataFreshnessConditions);
4747
const dataCompletenessAssertionsResult = data_completeness_assertions(globalAssertionsParams, config, dataCompletenessConditions);
48-
const referentialIntegrityAssertionsResult = referential_integrity_assertions(globalAssertionsParams, config, referentialIntegrityConditions); // New assertion
48+
const referentialIntegrityAssertionsResult = referential_integrity_assertions(globalAssertionsParams, config, referentialIntegrityConditions);
4949

5050
return {
5151
rowConditionAssertions: rowConditionAssertionsResult,

0 commit comments

Comments
 (0)