-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vdk-trino: Add unit tests for templates using reserved words
Trino templates can work with identifiers which are reserved Trino keywords. A unit test is added for each template (scd1, scd2 and periodic snapshot) with reserved keywords as table and column names. Tested by unit tests. Signed-off-by: Yana Zhivkova <[email protected]>
- Loading branch information
1 parent
7aba991
commit 42172f5
Showing
3 changed files
with
269 additions
and
25 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
...-trino/tests/jobs/load_dimension_scd2_template_job_reserved_args/01_prepare_input_data.py
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Copyright (c) 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
Load example input data for an scd2 template test. | ||
""" | ||
from taurus.api.job_input import IJobInput | ||
from taurus.vdk.trino_utils import TrinoTemplateQueries | ||
|
||
|
||
def run(job_input: IJobInput) -> None: | ||
# Step 1: create a table that represents the current state | ||
|
||
job_input.execute_query( | ||
""" | ||
DROP TABLE IF EXISTS "{target_schema}"."{target_table}" | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS "{target_schema}"."{target_table}" ( | ||
"{sk_column}" VARCHAR, | ||
{active_from_column} TIMESTAMP, | ||
{active_to_column} TIMESTAMP, | ||
"{id_column}" INT, | ||
"with" INT, | ||
state VARCHAR, | ||
is_next BOOLEAN, | ||
cloud_vendor VARCHAR, | ||
version SMALLINT | ||
) | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
INSERT INTO "{target_schema}"."{target_table}" VALUES | ||
('sddc01-v01', TIMESTAMP '2019-01-01', TIMESTAMP '9999-12-31', 1, 7, 'RUNNING' , false, 'Azure', 498), | ||
('sddc02-v01', TIMESTAMP '2019-02-01', TIMESTAMP '9999-12-31', 2, 9, 'STOPPED' , false, 'AWS' , 500), | ||
('sddc03-v01', TIMESTAMP '2019-03-01', TIMESTAMP '9999-12-31', 3, 3, 'PROVISIONING', false, 'Azure', 497), | ||
('sddc04-v01', TIMESTAMP '2019-04-01', TIMESTAMP '9999-12-31', 4, 5, 'PROVISIONING', true , 'Azure', 498), | ||
('sddc05-v01', TIMESTAMP '2019-05-01', TIMESTAMP '2019-05-02', 5, 9, 'STARTING' , true , 'AWS' , 500), | ||
('sddc05-v02', TIMESTAMP '2019-05-02', TIMESTAMP '2019-05-03', 5, 2, 'STARTING' , true , 'AWS' , 500), | ||
('sddc05-v03', TIMESTAMP '2019-05-03', TIMESTAMP '9999-12-31', 5, 3, 'STARTING' , true , 'AWS' , 500) | ||
""" | ||
) | ||
|
||
# Step 2: create a table that represents the delta to be applied | ||
|
||
job_input.execute_query( | ||
""" | ||
DROP TABLE IF EXISTS "{source_schema}"."{source_view}" | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS "{source_schema}"."{source_view}" ( | ||
{updated_at_column} TIMESTAMP, | ||
"{id_column}" INT, | ||
"with" INT, | ||
state VARCHAR, | ||
is_next BOOLEAN, | ||
cloud_vendor VARCHAR, | ||
version SMALLINT | ||
) | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
INSERT INTO "{source_schema}"."{source_view}" VALUES | ||
(TIMESTAMP '2019-02-02', 2, 1, 'STARTING' , false, 'AWS' , 500), -- Update (1) - new time, new values | ||
(TIMESTAMP '2019-03-01', 3, 4, 'RUNNING' , false, 'Azure', 497), -- Update (2) - same time, new values | ||
(TIMESTAMP '2019-04-02', 4, 5, 'PROVISIONING', true , 'Azure', 498), -- Update (3) - new time, same values | ||
(TIMESTAMP '2019-05-01', 5, 9, 'STARTING' , true , 'AWS' , 500), -- Update (4) - same time, same values | ||
(TIMESTAMP '2019-05-02', 5, 9, 'STARTING' , true , 'AWS' , 500), -- Update (5) - same time, prev values | ||
(TIMESTAMP '2019-05-04', 5, 9, 'STARTING' , true , 'AWS' , 500), -- Update (1) - new time, new values | ||
(TIMESTAMP '2019-06-01', 6, 9, 'STARTING' , true , 'AWS' , 499) -- Insert | ||
""" | ||
) | ||
|
||
# Step 3: Create a table containing the state expected after updating the current state with the given delta | ||
|
||
job_input.execute_query( | ||
""" | ||
DROP TABLE IF EXISTS "{expect_schema}"."{expect_table}" | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS "{expect_schema}"."{expect_table}" ( | ||
"{sk_column}" VARCHAR, | ||
{active_from_column} TIMESTAMP, | ||
{active_to_column} TIMESTAMP, | ||
"{id_column}" INT, | ||
"with" INT, | ||
state VARCHAR, | ||
is_next BOOLEAN, | ||
cloud_vendor VARCHAR, | ||
version SMALLINT | ||
) | ||
""" | ||
) | ||
job_input.execute_query( | ||
""" | ||
INSERT INTO "{expect_schema}"."{expect_table}" VALUES | ||
('sddc01-v01', TIMESTAMP '2019-01-01', TIMESTAMP '9999-12-31', 1, 7, 'RUNNING' , false, 'Azure', 498), | ||
('sddc02-v01', TIMESTAMP '2019-02-01', TIMESTAMP '2019-02-02', 2, 9, 'STOPPED' , false, 'AWS' , 500), | ||
('sddc02-v02', TIMESTAMP '2019-02-02', TIMESTAMP '9999-12-31', 2, 1, 'STARTING' , false, 'AWS' , 500), | ||
('sddc03-v01', TIMESTAMP '2019-03-01', TIMESTAMP '9999-12-31', 3, 4, 'RUNNING' , false, 'Azure', 497), | ||
('sddc04-v01', TIMESTAMP '2019-04-01', TIMESTAMP '9999-12-31', 4, 5, 'PROVISIONING', true , 'Azure', 498), | ||
('sddc05-v01', TIMESTAMP '2019-05-01', TIMESTAMP '2019-05-03', 5, 9, 'STARTING' , true , 'AWS' , 500), | ||
('sddc05-v03', TIMESTAMP '2019-05-03', TIMESTAMP '2019-05-04', 5, 3, 'STARTING' , true , 'AWS' , 500), | ||
('sddc05-v04', TIMESTAMP '2019-05-04', TIMESTAMP '9999-12-31', 5, 9, 'STARTING' , true , 'AWS' , 500), | ||
('sddc06-v01', TIMESTAMP '2019-06-01', TIMESTAMP '9999-12-31', 6, 9, 'STARTING' , true , 'AWS' , 499) | ||
""" | ||
) |
12 changes: 12 additions & 0 deletions
12
...obs/load_dimension_scd2_template_job_reserved_args/02_run_load_dimension_scd2_template.py
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2021 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from taurus.api.job_input import IJobInput | ||
|
||
|
||
def run(job_input: IJobInput) -> None: | ||
result = job_input.execute_template( | ||
template_name="scd2", | ||
template_args=job_input.get_arguments(), | ||
) | ||
if result.is_failed() and result.get_exception(): | ||
raise result.get_exception() |
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