def test_wrapped_sql(): from airflow.operators.postgres_operator import PostgresOperator from flowetl.mixins.table_name_macros_mixin import TableNameMacrosMixin from flowetl.mixins.wrapping_sql_mixin import wrapped_sql_operator new_type = wrapped_sql_operator(class_name="DUMMY_TYPE", sql="WRAPS({sql})") new_instance = new_type(sql="WRAPPED", task_id="DUMMY") assert new_type.wrapper_sql == "WRAPS({sql})" assert isinstance(new_instance, PostgresOperator) assert isinstance(new_instance, TableNameMacrosMixin) assert type(new_instance).__name__ == "DUMMY_TYPE" new_instance.prepare_template() assert new_instance.sql == "WRAPS(WRAPPED)"
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flowetl.mixins.wrapping_sql_mixin import wrapped_sql_operator ExtractFromForeignTableOperator = wrapped_sql_operator( class_name="ExtractFromForeignTableOperator", sql=""" DROP TABLE IF EXISTS {{{{ extract_table }}}}; CREATE TABLE {{{{ extract_table }}}} AS ( {sql}); DROP FOREIGN TABLE {{{{ staging_table }}}}; """, )
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flowetl.mixins.wrapping_sql_mixin import wrapped_sql_operator ExtractFromViewOperator = wrapped_sql_operator( class_name="ExtractFromViewOperator", sql=""" DROP TABLE IF EXISTS {{{{ extract_table }}}}; CREATE TABLE {{{{ extract_table }}}} AS ( {sql}); DROP VIEW {{{{ staging_table }}}}; """, )
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flowetl.mixins.wrapping_sql_mixin import wrapped_sql_operator QACheckOperator = wrapped_sql_operator( sql="""INSERT INTO etl.post_etl_queries(cdr_date, cdr_type, type_of_query_or_check, outcome, timestamp) VALUES (date '{{{{ ds }}}}', '{{{{ params.cdr_type }}}}', '{{{{ task.task_id }}}}', ({sql}), NOW()) """, class_name="QACheckOperator", )
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from flowetl.mixins.wrapping_sql_mixin import wrapped_sql_operator CreateStagingViewOperator = wrapped_sql_operator( class_name="CreateStagingViewOperator", sql="CREATE OR REPLACE VIEW {{{{ staging_table }}}} AS {sql}", )