-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,51 @@ | ||
#TODO Align with the upsert tempalte | ||
# Copyright 2023-2024 Broadcom | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
Load example input data for an scd1 template test. | ||
""" | ||
from vdk.api.job_input import IJobInput | ||
|
||
|
||
def run(job_input: IJobInput) -> None: | ||
target_schema = job_input.get_arguments().get("target_schema") | ||
target_table = job_input.get_arguments().get("target_table") | ||
source_schema = job_input.get_arguments().get("source_schema") | ||
source_view = job_input.get_arguments().get("source_view") | ||
# Step 1: create a table that represents the current state | ||
|
||
source_composite_name = f'"{source_schema}"."{source_view}"' | ||
target_composite_name = f'"{target_schema}"."{target_table}"' | ||
source_data_composite_name = f'"{source_schema}"."{source_view}_data"' | ||
|
||
# Step 1: create a new table that represents the current state | ||
job_input.execute_query( | ||
f""" | ||
DROP TABLE IF EXISTS {target_composite_name} | ||
""" | ||
DROP TABLE IF EXISTS {target_schema}.{target_table} | ||
""" | ||
) | ||
job_input.execute_query( | ||
f""" | ||
CREATE TABLE IF NOT EXISTS {target_composite_name} ( | ||
""" | ||
CREATE TABLE IF NOT EXISTS {target_schema}.{target_table} ( | ||
org_id INT, | ||
org_name VARCHAR, | ||
org_type VARCHAR, | ||
company_name VARCHAR, | ||
sddc_limit INT, | ||
org_host_limit INT | ||
) | ||
""" | ||
""" | ||
) | ||
job_input.execute_query( | ||
f""" | ||
INSERT INTO {target_composite_name} VALUES | ||
""" | ||
INSERT INTO {target_schema}.{target_table} VALUES | ||
(2, '[email protected]' , 'CUSTOMER_POC' , 'VMware' , 1, 6 ), | ||
(3, '[email protected]', 'CUSTOMER' , 'Goofy''s' , 2, 16), | ||
(3, '[email protected]', 'CUSTOMER' , 'Goofy''s' , 2, 16), | ||
(4, '[email protected]' , 'PARTNER_SISO' , 'Uncanny Company' , 2, 16), | ||
(5, '[email protected]' , 'CUSTOMER' , 'VMware' , 2, 32), | ||
(6, '[email protected]' , 'CUSTOMER' , 'PharmaMed' , 1, 32), | ||
(7, '[email protected]' , 'PARTNER_SISO' , 'ACME' , 1, 32), | ||
(8, '[email protected]' , 'INTERNAL_CORE' , 'VMware' , 4, 32) | ||
""" | ||
""" | ||
) | ||
|
||
# Step 2: create a new table that represents the next state | ||
# Step 2: create a table that represents the data that will be upserted | ||
|
||
job_input.execute_query( | ||
f""" | ||
DROP TABLE IF EXISTS {source_composite_name} | ||
""" | ||
""" | ||
DROP TABLE IF EXISTS {source_schema}.{source_view} | ||
""" | ||
) | ||
|
||
job_input.execute_query( | ||
f""" | ||
CREATE TABLE IF NOT EXISTS {source_data_composite_name} ( | ||
""" | ||
CREATE TABLE IF NOT EXISTS {source_schema}.{source_view} ( | ||
org_id INT, | ||
org_name VARCHAR, | ||
org_type VARCHAR, | ||
|
@@ -68,27 +56,44 @@ def run(job_input: IJobInput) -> None: | |
""" | ||
) | ||
job_input.execute_query( | ||
f""" | ||
INSERT INTO {source_data_composite_name} VALUES | ||
(1, '[email protected]' , 'CUSTOMER_MSP_TENANT', 'actual Master Org', 2, 32), | ||
(2, '[email protected]' , 'CUSTOMER_POC' , 'VMware' , 1, 6 ), | ||
(3, '[email protected]', 'CUSTOMER' , 'Goofy''s' , 2, 32), | ||
(4, '[email protected]' , 'PARTNER_SISO' , 'Uncanny Company' , 2, 32), | ||
(5, '[email protected]' , 'CUSTOMER' , 'VMware' , 2, 32), | ||
(6, '[email protected]' , 'CUSTOMER' , 'PharmaMed' , 2, 32), | ||
(7, '[email protected]' , 'PARTNER_SISO' , 'ACME' , 2, 32), | ||
(8, '[email protected]' , 'INTERNAL_CORE' , 'VMware' , 2, 32) | ||
""" | ||
"""INSERT INTO {source_schema}.{source_view} VALUES | ||
(7, '[email protected]' , 'CUSTOMER' , 'ACME' , 1, 32), | ||
(8, '[email protected]' , 'CUSTOMER' , 'VMware' , 4, 32), | ||
(9, '[email protected]' , 'CUSTOMER_POC' , 'VMware' , 1, 6 ), | ||
(10, '[email protected]' , 'CUSTOMER' , 'Goofy''s' , 2, 16) | ||
""" | ||
) | ||
|
||
# Step 3: Create a table containing the state expected after upserting the target table with the source table data | ||
|
||
job_input.execute_query( | ||
f""" | ||
DROP VIEW IF EXISTS {source_composite_name} | ||
""" | ||
DROP TABLE IF EXISTS {expect_schema}.{expect_table} | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS {expect_schema}.{expect_table} ( | ||
org_id INT, | ||
org_name VARCHAR, | ||
org_type VARCHAR, | ||
company_name VARCHAR, | ||
sddc_limit INT, | ||
org_host_limit INT | ||
) | ||
""" | ||
) | ||
|
||
job_input.execute_query( | ||
f""" | ||
CREATE VIEW {source_composite_name} AS (SELECT * FROM {source_data_composite_name}) | ||
""" | ||
INSERT INTO {expect_schema}.{expect_table} VALUES | ||
(2, '[email protected]' , 'CUSTOMER_POC' , 'VMware' , 1, 6 ), | ||
(3, '[email protected]', 'CUSTOMER' , 'Goofy''s' , 2, 16), | ||
(4, '[email protected]' , 'PARTNER_SISO' , 'Uncanny Company' , 2, 16), | ||
(5, '[email protected]' , 'CUSTOMER' , 'VMware' , 2, 32), | ||
(6, '[email protected]' , 'CUSTOMER' , 'PharmaMed' , 1, 32), | ||
(7, '[email protected]' , 'CUSTOMER' , 'ACME' , 1, 32), | ||
(8, '[email protected]' , 'CUSTOMER' , 'VMware' , 4, 32), | ||
(9, '[email protected]' , 'CUSTOMER_POC' , 'VMware' , 1, 6 ), | ||
(10, '[email protected]', 'CUSTOMER' , 'Goofy''s' , 2, 16) | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters