Skip to content

Commit c166cef

Browse files
authored
Create user.csql
1 parent 01924fd commit c166cef

File tree

1 file changed

+61
-0
lines changed
  • mastering-carol/sql-pipelines-manifest-v2

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
CREATE TEMP FUNCTION rejection_rules(arr ANY TYPE) AS (
2+
(SELECT [
3+
4+
STRUCT("REJECTION_RULE" as mdmStage,
5+
"((record.mdmname is null) or (record.mdmname = ''))" as mdmErrorMsg,
6+
((record.mdmname is null) or (record.mdmname = ''))
7+
as mdmActive)
8+
,
9+
STRUCT("RELATIONSHIP_CONSTRAINT" as mdmStage,
10+
"invalid record.mdmlogin" as mdmErrorMsg,
11+
(record.mdmlogin = "enforcingRelationshipError")
12+
as mdmActive)
13+
14+
] FROM UNNEST(arr) AS record)
15+
);
16+
17+
WITH fake_data AS (
18+
SELECT [
19+
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, '[email protected]' AS mdmlogin, 'cafu2' AS mdmpassword, TRUE AS mdmshouldcreateuser, '+5500999225522' AS mdmphonenumber, TRUE AS mdmisactive, TRUE AS mdmallowcaroluiaccess),
20+
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, '[email protected]' AS mdmlogin, 'dunga8' AS mdmpassword, TRUE AS mdmshouldcreateuser, '+5500999885588' AS mdmphonenumber, CAST(NULL AS BOOL) AS mdmisactive, TRUE AS mdmallowcaroluiaccess),
21+
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, '[email protected]' AS mdmlogin, 'capita2' AS mdmpassword, FALSE AS mdmshouldcreateuser, '' AS mdmphonenumber, TRUE AS mdmisactive, TRUE AS mdmallowcaroluiaccess),
22+
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),
23+
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),
24+
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, '[email protected]' AS mdmlogin, 'maldini3' AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, CAST(NULL AS BOOL) AS mdmallowcaroluiaccess),
25+
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, '[email protected]' AS mdmlogin, CAST("a7Password" AS STRING) AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, FALSE AS mdmallowcaroluiaccess),
26+
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, '[email protected]' AS mdmlogin, CAST(NULL AS STRING) AS mdmpassword, FALSE AS mdmshouldcreateuser, '+5500999135513' AS mdmphonenumber, TRUE AS mdmisactive, FALSE AS mdmallowcaroluiaccess),
27+
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)
28+
] AS players
29+
),
30+
31+
users AS (
32+
SELECT
33+
mdmname,
34+
mdmroles,
35+
mdmlocale,
36+
mdmshouldsendwelcomeemail,
37+
mdmgroups,
38+
mdmlogin,
39+
mdmpassword,
40+
mdmshouldcreateuser,
41+
mdmphonenumber,
42+
mdmisactive,
43+
mdmallowcaroluiaccess
44+
--metadataa--
45+
FROM
46+
fake_data,
47+
UNNEST(players) AS stg
48+
WHERE
49+
1 = 1
50+
--timestamp-- AND mdmCounterForEntity > {{start_from}}
51+
)
52+
53+
SELECT
54+
concat('blablabla', null) as __mdmId, 0 as __mdmCounterForEntity, *, (mdmlogin IS NULL OR LENGTH(TRIM(mdmlogin)) = 0) AS mdmDeleted,
55+
(rejection_rules(ARRAY((SELECT AS STRUCT
56+
dm.mdmname,
57+
dm.mdmlogin
58+
)))) AS mdmErrors
59+
FROM
60+
users dm
61+

0 commit comments

Comments
 (0)