From c166cef6254bfccc6111feab49695a70031d7619 Mon Sep 17 00:00:00 2001 From: Robson Poffo Date: Tue, 22 Oct 2024 23:46:58 -0400 Subject: [PATCH] Create user.csql --- .../sql-pipelines-manifest-v2/user.csql | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 mastering-carol/sql-pipelines-manifest-v2/user.csql diff --git a/mastering-carol/sql-pipelines-manifest-v2/user.csql b/mastering-carol/sql-pipelines-manifest-v2/user.csql new file mode 100644 index 0000000..7586f47 --- /dev/null +++ b/mastering-carol/sql-pipelines-manifest-v2/user.csql @@ -0,0 +1,61 @@ +CREATE TEMP FUNCTION rejection_rules(arr ANY TYPE) AS ( + (SELECT [ + + STRUCT("REJECTION_RULE" as mdmStage, + "((record.mdmname is null) or (record.mdmname = ''))" as mdmErrorMsg, + ((record.mdmname is null) or (record.mdmname = '')) + as mdmActive) + , + STRUCT("RELATIONSHIP_CONSTRAINT" as mdmStage, + "invalid record.mdmlogin" as mdmErrorMsg, + (record.mdmlogin = "enforcingRelationshipError") + as mdmActive) + + ] FROM UNNEST(arr) AS record) +); + +WITH fake_data AS ( + SELECT [ + STRUCT('a1' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Cafu' AS mdmname, 'TENANT_ADMIN_ROLE' AS mdmroles, 'pt_BR' AS mdmlocale, TRUE AS mdmshouldsendwelcomeemail, '["tetra","penta"]' AS mdmgroups, 'cafu@test.com' AS mdmlogin, 'cafu2' AS mdmpassword, TRUE AS mdmshouldcreateuser, '+5500999225522' AS mdmphonenumber, TRUE AS mdmisactive, TRUE AS mdmallowcaroluiaccess), + STRUCT('a2' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Dunga' AS mdmname, 'TENANT_ADMIN_ROLE' AS mdmroles, 'pt_BR' AS mdmlocale, FALSE AS mdmshouldsendwelcomeemail, '["tetra"]' AS mdmgroups, 'dunga@test.com' AS mdmlogin, 'dunga8' AS mdmpassword, TRUE AS mdmshouldcreateuser, '+5500999885588' AS mdmphonenumber, CAST(NULL AS BOOL) AS mdmisactive, TRUE AS mdmallowcaroluiaccess), + STRUCT('a3' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Capita' AS mdmname, '' AS mdmroles, 'pt_BR' AS mdmlocale, CAST(NULL AS BOOL) AS mdmshouldsendwelcomeemail, 'tri' AS mdmgroups, 'capita@test.com' AS mdmlogin, 'capita2' AS mdmpassword, FALSE AS mdmshouldcreateuser, '' AS mdmphonenumber, TRUE AS mdmisactive, TRUE AS mdmallowcaroluiaccess), + STRUCT('a4' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Alex de Souza' AS mdmname, 'APP_ADMIN_ROLE' AS mdmroles, '' AS mdmlocale, FALSE AS mdmshouldsendwelcomeemail, CAST(NULL AS STRING) AS mdmgroups, '' AS mdmlogin, 'alex10' AS mdmpassword, FALSE AS mdmshouldcreateuser, CAST(NULL AS STRING) AS mdmphonenumber, TRUE AS mdmisactive, TRUE AS mdmallowcaroluiaccess), + STRUCT('a5' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Gamarra' AS mdmname, 'BUSINESS_USER_ROLE' AS mdmroles, 'en_US' AS mdmlocale, FALSE AS mdmshouldsendwelcomeemail, CAST(NULL AS STRING) AS mdmgroups, CAST(NULL AS STRING) AS mdmlogin, '' AS mdmpassword, CAST(NULL AS BOOL) AS mdmshouldcreateuser, '+5500999045504' AS mdmphonenumber, TRUE AS mdmisactive, FALSE AS mdmallowcaroluiaccess), + STRUCT('a6' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Paolo Maldini' AS mdmname, CAST(NULL AS STRING) AS mdmroles, 'en_US' AS mdmlocale, TRUE AS mdmshouldsendwelcomeemail, '' AS mdmgroups, 'maldini@test.com' AS mdmlogin, 'maldini3' AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, CAST(NULL AS BOOL) AS mdmallowcaroluiaccess), + STRUCT('a7' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'Nesta' AS mdmname, CAST(NULL AS STRING) AS mdmroles, CAST(NULL AS STRING) AS mdmlocale, TRUE AS mdmshouldsendwelcomeemail, CAST(NULL AS STRING) AS mdmgroups, 'a7@nesta.com' AS mdmlogin, CAST("a7Password" AS STRING) AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, FALSE AS mdmallowcaroluiaccess), + STRUCT('a8' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, '' AS mdmname, CAST(NULL AS STRING) AS mdmroles, CAST(NULL AS STRING) AS mdmlocale, TRUE AS mdmshouldsendwelcomeemail, CAST(NULL AS STRING) AS mdmgroups, 'a8@a8.com' AS mdmlogin, CAST(NULL AS STRING) AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, FALSE AS mdmallowcaroluiaccess), + STRUCT('a9' as mdmId, null as mdmTenantId, "" as mdmEntityType, 0 as mdmCounterForEntity, 'a9 Relationship Constraint Error' AS mdmname, CAST(NULL AS STRING) AS mdmroles, CAST(NULL AS STRING) AS mdmlocale, TRUE AS mdmshouldsendwelcomeemail, CAST(NULL AS STRING) AS mdmgroups, 'enforcingRelationshipError' AS mdmlogin, CAST(NULL AS STRING) AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, FALSE AS mdmallowcaroluiaccess) + ] AS players +), + +users AS ( + SELECT + mdmname, + mdmroles, + mdmlocale, + mdmshouldsendwelcomeemail, + mdmgroups, + mdmlogin, + mdmpassword, + mdmshouldcreateuser, + mdmphonenumber, + mdmisactive, + mdmallowcaroluiaccess + --metadataa-- + FROM + fake_data, + UNNEST(players) AS stg + WHERE + 1 = 1 + --timestamp-- AND mdmCounterForEntity > {{start_from}} +) + +SELECT + concat('blablabla', null) as __mdmId, 0 as __mdmCounterForEntity, *, (mdmlogin IS NULL OR LENGTH(TRIM(mdmlogin)) = 0) AS mdmDeleted, + (rejection_rules(ARRAY((SELECT AS STRUCT + dm.mdmname, + dm.mdmlogin + )))) AS mdmErrors +FROM + users dm +