From cf765f0113e984a01adeb39bee2f220f0387c51e Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Thu, 11 Apr 2024 15:06:16 +0530 Subject: [PATCH 01/13] config for generic functions --- dbt_automation/assets/operations.template.yml | 20 ++++++++++++++++++- scripts/main.py | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dbt_automation/assets/operations.template.yml b/dbt_automation/assets/operations.template.yml index 8145af6..b9d9463 100644 --- a/dbt_automation/assets/operations.template.yml +++ b/dbt_automation/assets/operations.template.yml @@ -364,7 +364,25 @@ operations: is_col: output_column_name: sql_snippet: - + - type: generic + config: + function_name: + input: + input_type: <"source" or "model"> + input_name: + source_name: + source_columns: + - + - + - + - ... + operands: + - + - + - + - ... + dest_schema: + output_name: - type: mergeoperations config: dest_schema: diff --git a/scripts/main.py b/scripts/main.py index 9b2fadc..5356164 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -8,6 +8,7 @@ import json import yaml from dotenv import load_dotenv +from dbt_automation.operations.generic import generic_function from dbt_automation.operations.arithmetic import arithmetic from dbt_automation.operations.mergeoperations import merge_operations from dbt_automation.operations.scaffold import scaffold @@ -48,6 +49,7 @@ "groupby": groupby, "aggregate": aggregate, "casewhen": casewhen, + "generic": generic_function } load_dotenv("./../dbconnection.env") From 051f70e188dccc0b9c0384cd755e17fa6abaeddf Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Thu, 11 Apr 2024 15:07:19 +0530 Subject: [PATCH 02/13] generic operation --- dbt_automation/operations/generic.py | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dbt_automation/operations/generic.py diff --git a/dbt_automation/operations/generic.py b/dbt_automation/operations/generic.py new file mode 100644 index 0000000..5849172 --- /dev/null +++ b/dbt_automation/operations/generic.py @@ -0,0 +1,66 @@ +""" +This file contains the airthmetic operations for dbt automation +""" + +from logging import basicConfig, getLogger, INFO +from dbt_automation.utils.dbtproject import dbtProject +from dbt_automation.utils.interfaces.warehouse_interface import WarehouseInterface +from dbt_automation.utils.columnutils import quote_columnname, quote_constvalue + +from dbt_automation.utils.tableutils import source_or_ref + +basicConfig(level=INFO) +logger = getLogger() + + +def generic_function_dbt_sql( + config: dict, + warehouse: WarehouseInterface, +): + """ + model_name: name of the output model + function_name: name of the SQL function + operands: list of operands (column names or constant values) + output_name: name of the output column + """ + function_name = config["function_name"] + operands = config["operands"] + source_columns = config["source_columns"] + output_name = config["output_name"] + + if source_columns == "*": + dbt_code = "SELECT *\n" + else: + dbt_code = f"SELECT {', '.join([quote_columnname(col, warehouse.name) for col in source_columns])}\n" + + dbt_code = f"SELECT {function_name}({', '.join([str(operand) for operand in operands])}) AS {output_name}, {', '.join(source_columns)}" + + select_from = source_or_ref(**config["input"]) + if config["input"]["input_type"] == "cte": + dbt_code += f" FROM {select_from}\n" + else: + dbt_code += f" FROM {{{{{select_from}}}}}\n" + + return dbt_code + + +def generic_function(config: dict, warehouse: WarehouseInterface, project_dir: str): + """ + Perform a generic SQL function operation. + """ + dbt_sql = "" + if config["input"]["input_type"] != "cte": + dbt_sql = ( + "{{ config(materialized='table', schema='" + config["dest_schema"] + "') }}" + ) + + select_statement = generic_function_dbt_sql(config, warehouse) + + dest_schema = config["dest_schema"] + output_name = config["output_name"] + + dbtproject = dbtProject(project_dir) + dbtproject.ensure_models_dir(dest_schema) + model_sql_path = dbtproject.write_model(dest_schema, output_name, dbt_sql + select_statement) + + return model_sql_path \ No newline at end of file From d8a02d77d47559bceef157333a2350161ef15212 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Thu, 11 Apr 2024 17:31:08 +0530 Subject: [PATCH 03/13] generic bq test --- tests/warehouse/test_bigquery_ops.py | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/warehouse/test_bigquery_ops.py b/tests/warehouse/test_bigquery_ops.py index 2b4a85e..3e357e8 100644 --- a/tests/warehouse/test_bigquery_ops.py +++ b/tests/warehouse/test_bigquery_ops.py @@ -8,6 +8,7 @@ from logging import basicConfig, getLogger, INFO from dbt_automation.operations.droprenamecolumns import rename_columns, drop_columns from dbt_automation.operations.flattenjson import flattenjson +from dbt_automation.operations.generic import generic_function from dbt_automation.operations.mergeoperations import ( merge_operations, ) @@ -984,3 +985,44 @@ def test_flattenjson(self): assert "_airbyte_data_NGO" in cols assert "_airbyte_data_Month" in cols assert "_airbyte_ab_id" in cols + + def test_generic(self): + """test generic function""" + wc_client = TestBigqueryOperations.wc_client + output_name = "generic" + + config = { + "function_name": "lower", + "input": { + "input_type": "model", + "input_name": "_airbyte_raw_Sheet2", + "source_name": None, + }, + "operands": ["NGO"], + "dest_schema": "pytest_intermediate", + "output_name": output_name, + "source_columns": [ + "_airbyte_ab_id", + "NGO", + "SPOC", + "Indicator" + ], + } + + generic_function(config, wc_client, TestBigqueryOperations.test_project_dir) + + TestBigqueryOperations.execute_dbt("run", output_name) + + cols = [ + col_dict["name"] + for col_dict in wc_client.get_table_columns( + "pytest_intermediate", output_name + ) + ] + assert "NGO" in cols + assert "Indicator" in cols + table_data = wc_client.get_table_data("pytest_intermediate", output_name, 1) + ngo_column = [row['generic'] for row in table_data] + + for value in ngo_column: + assert value == value.lower(), f"Value {value} in 'NGO' column is not lowercase" From 5497ce1b1e85395b74fef1621ca413ba9b2d3386 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Thu, 11 Apr 2024 18:16:36 +0530 Subject: [PATCH 04/13] generic function test for postgres --- tests/warehouse/test_postgres_ops.py | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/warehouse/test_postgres_ops.py b/tests/warehouse/test_postgres_ops.py index a84b18a..eb0d0b6 100644 --- a/tests/warehouse/test_postgres_ops.py +++ b/tests/warehouse/test_postgres_ops.py @@ -7,6 +7,7 @@ from logging import basicConfig, getLogger, INFO from dbt_automation.operations.flattenjson import flattenjson from dbt_automation.operations.droprenamecolumns import rename_columns, drop_columns +from dbt_automation.operations.generic import generic_function from dbt_automation.operations.mergeoperations import merge_operations from dbt_automation.utils.warehouseclient import get_client from dbt_automation.operations.scaffold import scaffold @@ -998,3 +999,49 @@ def test_merge_operation(self): ) == 0 ) + + def test_generic(self): + """test generic operation""" + wc_client = TestPostgresOperations.wc_client + output_name = "generic" + + config = { + "input": { + "input_type": "model", + "input_name": "_airbyte_raw_Sheet1", + "source_name": None, + }, + "dest_schema": "pytest_intermediate", + "output_name": output_name, + "source_columns": [ + "_airbyte_ab_id", + '"NGO"', + '"Indicator"', + ], + "operands": ['"NGO"'], + "function_name": "lower", + } + + generic_function( + config, + wc_client, + TestPostgresOperations.test_project_dir, + ) + + TestPostgresOperations.execute_dbt("run", output_name) + + cols = [ + col_dict["name"] + for col_dict in wc_client.get_table_columns( + "pytest_intermediate", output_name + ) + ] + + assert "NGO" in cols + assert "Indicator" in cols + table_data = wc_client.get_table_data("pytest_intermediate", output_name, 1) + ngo_column = [row['generic'] for row in table_data] + + for value in ngo_column: + assert value == value.lower(), f"Value {value} in 'NGO' column is not lowercase" + From 1c25bd89e45b6226adf02c446cdd35a34e1ba763 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Thu, 11 Apr 2024 18:29:46 +0530 Subject: [PATCH 05/13] include generic in merge operations --- dbt_automation/operations/generic.py | 7 ++++--- dbt_automation/operations/mergeoperations.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dbt_automation/operations/generic.py b/dbt_automation/operations/generic.py index 5849172..887d2f3 100644 --- a/dbt_automation/operations/generic.py +++ b/dbt_automation/operations/generic.py @@ -41,7 +41,7 @@ def generic_function_dbt_sql( else: dbt_code += f" FROM {{{{{select_from}}}}}\n" - return dbt_code + return dbt_code, source_columns def generic_function(config: dict, warehouse: WarehouseInterface, project_dir: str): @@ -54,7 +54,8 @@ def generic_function(config: dict, warehouse: WarehouseInterface, project_dir: s "{{ config(materialized='table', schema='" + config["dest_schema"] + "') }}" ) - select_statement = generic_function_dbt_sql(config, warehouse) + select_statement, output_cols = generic_function_dbt_sql(config, warehouse) + dbt_sql += "\n" + select_statement dest_schema = config["dest_schema"] output_name = config["output_name"] @@ -63,4 +64,4 @@ def generic_function(config: dict, warehouse: WarehouseInterface, project_dir: s dbtproject.ensure_models_dir(dest_schema) model_sql_path = dbtproject.write_model(dest_schema, output_name, dbt_sql + select_statement) - return model_sql_path \ No newline at end of file + return model_sql_path, output_cols \ No newline at end of file diff --git a/dbt_automation/operations/mergeoperations.py b/dbt_automation/operations/mergeoperations.py index 7f538ff..66f7eba 100644 --- a/dbt_automation/operations/mergeoperations.py +++ b/dbt_automation/operations/mergeoperations.py @@ -9,6 +9,7 @@ rename_columns_dbt_sql, ) from dbt_automation.operations.flattenjson import flattenjson_dbt_sql +from dbt_automation.operations.generic import generic_function_dbt_sql from dbt_automation.operations.mergetables import union_tables_sql from dbt_automation.operations.regexextraction import regex_extraction_sql from dbt_automation.utils.dbtproject import dbtProject @@ -117,6 +118,11 @@ def merge_operations_sql( op_select_statement, out_cols = union_tables_sql( operation["config"], warehouse ) + elif operation["type"] == "generic": + breakpoint() + op_select_statement, out_cols = generic_function_dbt_sql( + operation["config"], warehouse + ) output_cols = out_cols From 1a16a205af347baff1400db9c709633245eb515d Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Thu, 11 Apr 2024 19:45:43 +0530 Subject: [PATCH 06/13] update merge operation --- dbt_automation/operations/mergeoperations.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dbt_automation/operations/mergeoperations.py b/dbt_automation/operations/mergeoperations.py index 66f7eba..76939b3 100644 --- a/dbt_automation/operations/mergeoperations.py +++ b/dbt_automation/operations/mergeoperations.py @@ -119,7 +119,6 @@ def merge_operations_sql( operation["config"], warehouse ) elif operation["type"] == "generic": - breakpoint() op_select_statement, out_cols = generic_function_dbt_sql( operation["config"], warehouse ) From b2489b636aff84d3dfcb070ca86627f54d7e03b6 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 00:22:02 +0530 Subject: [PATCH 07/13] use computed_columns to send function_name, operands, output_column_name --- dbt_automation/operations/generic.py | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/dbt_automation/operations/generic.py b/dbt_automation/operations/generic.py index 887d2f3..989f60c 100644 --- a/dbt_automation/operations/generic.py +++ b/dbt_automation/operations/generic.py @@ -18,28 +18,29 @@ def generic_function_dbt_sql( warehouse: WarehouseInterface, ): """ - model_name: name of the output model - function_name: name of the SQL function - operands: list of operands (column names or constant values) - output_name: name of the output column + source_columns: list of columns to copy from the input model + computed_columns: list of computed columns with function_name, operands, and output_column_name """ - function_name = config["function_name"] - operands = config["operands"] source_columns = config["source_columns"] - output_name = config["output_name"] + computed_columns = config["computed_columns"] if source_columns == "*": - dbt_code = "SELECT *\n" + dbt_code = "SELECT *" else: - dbt_code = f"SELECT {', '.join([quote_columnname(col, warehouse.name) for col in source_columns])}\n" + dbt_code = f"SELECT {', '.join([quote_columnname(col, warehouse.name) for col in source_columns])}" - dbt_code = f"SELECT {function_name}({', '.join([str(operand) for operand in operands])}) AS {output_name}, {', '.join(source_columns)}" + for computed_column in computed_columns: + function_name = computed_column["function_name"] + operands = [quote_columnname(operand, warehouse.name) for operand in computed_column["operands"]] + output_column_name = computed_column["output_column_name"] + + dbt_code += f", {function_name}({', '.join(operands)}) AS {output_column_name}" select_from = source_or_ref(**config["input"]) if config["input"]["input_type"] == "cte": - dbt_code += f" FROM {select_from}\n" + dbt_code += f" FROM {select_from}" else: - dbt_code += f" FROM {{{{{select_from}}}}}\n" + dbt_code += f" FROM {{{{{select_from}}}}}" return dbt_code, source_columns @@ -58,10 +59,10 @@ def generic_function(config: dict, warehouse: WarehouseInterface, project_dir: s dbt_sql += "\n" + select_statement dest_schema = config["dest_schema"] - output_name = config["output_name"] + output_model_name = config["output_model_name"] dbtproject = dbtProject(project_dir) dbtproject.ensure_models_dir(dest_schema) - model_sql_path = dbtproject.write_model(dest_schema, output_name, dbt_sql + select_statement) + model_sql_path = dbtproject.write_model(dest_schema, output_model_name, dbt_sql + select_statement) return model_sql_path, output_cols \ No newline at end of file From b2b5b972bc9f3e81b5b39ed73745e1756bb5dc20 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 01:29:10 +0530 Subject: [PATCH 08/13] update both the tests --- tests/warehouse/test_bigquery_ops.py | 29 ++++++++++++++++++---------- tests/warehouse/test_postgres_ops.py | 26 +++++++++++++++++-------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/tests/warehouse/test_bigquery_ops.py b/tests/warehouse/test_bigquery_ops.py index 1fb38f1..d001b54 100644 --- a/tests/warehouse/test_bigquery_ops.py +++ b/tests/warehouse/test_bigquery_ops.py @@ -1083,23 +1083,32 @@ def test_flattenjson(self): def test_generic(self): """test generic function""" wc_client = TestBigqueryOperations.wc_client - output_name = "generic" + output_name = "generic_table" config = { - "function_name": "lower", "input": { "input_type": "model", "input_name": "_airbyte_raw_Sheet2", "source_name": None, }, - "operands": ["NGO"], "dest_schema": "pytest_intermediate", - "output_name": output_name, - "source_columns": [ - "_airbyte_ab_id", - "NGO", - "SPOC", - "Indicator" + "output_model_name": "output_model_name", + "source_columns": ["NGO", "Month", "measure1", "measure2", "Indicator"], + "computed_columns": [ + { + "function_name": "LOWER", + "operands": [ + "NGO" + ], + "output_column_name": "ngo_lower" + }, + { + "function_name": "TRIM", + "operands": [ + "Indicator" + ], + "output_column_name": "trimmed_indicator" + } ], } @@ -1116,7 +1125,7 @@ def test_generic(self): assert "NGO" in cols assert "Indicator" in cols table_data = wc_client.get_table_data("pytest_intermediate", output_name, 1) - ngo_column = [row['generic'] for row in table_data] + ngo_column = [row['ngo_lower'] for row in table_data] for value in ngo_column: assert value == value.lower(), f"Value {value} in 'NGO' column is not lowercase" diff --git a/tests/warehouse/test_postgres_ops.py b/tests/warehouse/test_postgres_ops.py index 0eb01e0..62728ba 100644 --- a/tests/warehouse/test_postgres_ops.py +++ b/tests/warehouse/test_postgres_ops.py @@ -1105,14 +1105,24 @@ def test_generic(self): "source_name": None, }, "dest_schema": "pytest_intermediate", - "output_name": output_name, - "source_columns": [ - "_airbyte_ab_id", - '"NGO"', - '"Indicator"', + "output_model_name": "output_model_name", + "source_columns": ["NGO", "Month", "measure1", "measure2", "Indicator"], + "computed_columns": [ + { + "function_name": "LOWER", + "operands": [ + "NGO" + ], + "output_column_name": "ngo_lower" + }, + { + "function_name": "TRIM", + "operands": [ + "measure1" + ], + "output_column_name": "trimmed_measure_1" + } ], - "operands": ['"NGO"'], - "function_name": "lower", } generic_function( @@ -1133,7 +1143,7 @@ def test_generic(self): assert "NGO" in cols assert "Indicator" in cols table_data = wc_client.get_table_data("pytest_intermediate", output_name, 1) - ngo_column = [row['generic'] for row in table_data] + ngo_column = [row['ngo_lower'] for row in table_data] for value in ngo_column: assert value == value.lower(), f"Value {value} in 'NGO' column is not lowercase" From 54be444c554f22153569cabdf8815a9487f4880a Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 01:33:17 +0530 Subject: [PATCH 09/13] update yaml config --- dbt_automation/assets/operations.template.yml | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/dbt_automation/assets/operations.template.yml b/dbt_automation/assets/operations.template.yml index 39f49b6..9c3da1c 100644 --- a/dbt_automation/assets/operations.template.yml +++ b/dbt_automation/assets/operations.template.yml @@ -366,7 +366,6 @@ operations: sql_snippet: - type: generic config: - function_name: input: input_type: <"source" or "model"> input_name: @@ -376,13 +375,17 @@ operations: - - - ... - operands: - - - - - - - - ... dest_schema: - output_name: + output_model_name: + computed_columns: + - function_name: + operands: + - + output_column_name: + - function_name: + operands: + - + output_column_name: - type: pivot config: @@ -716,4 +719,26 @@ operations: - cast_to: unpivot_field_name: - unpivot_value_name: \ No newline at end of file + unpivot_value_name: + - type: generic + config: + input: + input_type: <"source" or "model"> + input_name: + source_name: + source_columns: + - + - + - + - ... + dest_schema: + output_model_name: + computed_columns: + - function_name: + operands: + - + output_column_name: + - function_name: + operands: + - + output_column_name: From a79427b989218193d8f7c270a27a93e54adda04c Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 11:09:06 +0530 Subject: [PATCH 10/13] fix generic function and update test --- dbt_automation/operations/generic.py | 5 ++--- tests/warehouse/test_bigquery_ops.py | 2 +- tests/warehouse/test_postgres_ops.py | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dbt_automation/operations/generic.py b/dbt_automation/operations/generic.py index 989f60c..57ac703 100644 --- a/dbt_automation/operations/generic.py +++ b/dbt_automation/operations/generic.py @@ -56,13 +56,12 @@ def generic_function(config: dict, warehouse: WarehouseInterface, project_dir: s ) select_statement, output_cols = generic_function_dbt_sql(config, warehouse) - dbt_sql += "\n" + select_statement dest_schema = config["dest_schema"] - output_model_name = config["output_model_name"] + output_name = config["output_model_name"] dbtproject = dbtProject(project_dir) dbtproject.ensure_models_dir(dest_schema) - model_sql_path = dbtproject.write_model(dest_schema, output_model_name, dbt_sql + select_statement) + model_sql_path = dbtproject.write_model(dest_schema, output_name, dbt_sql + select_statement) return model_sql_path, output_cols \ No newline at end of file diff --git a/tests/warehouse/test_bigquery_ops.py b/tests/warehouse/test_bigquery_ops.py index d001b54..c4b97d7 100644 --- a/tests/warehouse/test_bigquery_ops.py +++ b/tests/warehouse/test_bigquery_ops.py @@ -1092,7 +1092,7 @@ def test_generic(self): "source_name": None, }, "dest_schema": "pytest_intermediate", - "output_model_name": "output_model_name", + "output_model_name": output_name, "source_columns": ["NGO", "Month", "measure1", "measure2", "Indicator"], "computed_columns": [ { diff --git a/tests/warehouse/test_postgres_ops.py b/tests/warehouse/test_postgres_ops.py index 62728ba..0ce2887 100644 --- a/tests/warehouse/test_postgres_ops.py +++ b/tests/warehouse/test_postgres_ops.py @@ -1101,11 +1101,11 @@ def test_generic(self): config = { "input": { "input_type": "model", - "input_name": "_airbyte_raw_Sheet1", + "input_name": "_airbyte_raw_Sheet2", "source_name": None, }, "dest_schema": "pytest_intermediate", - "output_model_name": "output_model_name", + "output_model_name": output_name, "source_columns": ["NGO", "Month", "measure1", "measure2", "Indicator"], "computed_columns": [ { From 35e2d80bee5b71bc65b59d89efef20f73a81b3dd Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 12:59:55 +0530 Subject: [PATCH 11/13] operands can be column names or const value --- dbt_automation/assets/operations.template.yml | 14 ++++++++++++-- dbt_automation/operations/generic.py | 10 +++++++++- tests/warehouse/test_bigquery_ops.py | 4 ++-- tests/warehouse/test_postgres_ops.py | 4 ++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dbt_automation/assets/operations.template.yml b/dbt_automation/assets/operations.template.yml index 9c3da1c..6d3877b 100644 --- a/dbt_automation/assets/operations.template.yml +++ b/dbt_automation/assets/operations.template.yml @@ -736,9 +736,19 @@ operations: computed_columns: - function_name: operands: - - + - value: + is_col: + - value: + is_col: + - value: + is_col: output_column_name: - function_name: operands: - - + - value: + is_col: + - value: + is_col: + - value: + is_col: output_column_name: diff --git a/dbt_automation/operations/generic.py b/dbt_automation/operations/generic.py index 57ac703..3531c36 100644 --- a/dbt_automation/operations/generic.py +++ b/dbt_automation/operations/generic.py @@ -20,6 +20,9 @@ def generic_function_dbt_sql( """ source_columns: list of columns to copy from the input model computed_columns: list of computed columns with function_name, operands, and output_column_name + function_name: name of the function to be used + operands: list of operands to be passed to the function + output_column_name: name of the output column """ source_columns = config["source_columns"] computed_columns = config["computed_columns"] @@ -31,7 +34,12 @@ def generic_function_dbt_sql( for computed_column in computed_columns: function_name = computed_column["function_name"] - operands = [quote_columnname(operand, warehouse.name) for operand in computed_column["operands"]] + operands = [ + quote_constvalue(quote_columnname(str(operand["value"]), warehouse.name), warehouse.name) + if operand["is_col"] + else quote_constvalue(str(operand["value"]), warehouse.name) + for operand in computed_column["operands"] + ] output_column_name = computed_column["output_column_name"] dbt_code += f", {function_name}({', '.join(operands)}) AS {output_column_name}" diff --git a/tests/warehouse/test_bigquery_ops.py b/tests/warehouse/test_bigquery_ops.py index c4b97d7..e1551b8 100644 --- a/tests/warehouse/test_bigquery_ops.py +++ b/tests/warehouse/test_bigquery_ops.py @@ -1098,14 +1098,14 @@ def test_generic(self): { "function_name": "LOWER", "operands": [ - "NGO" + {"value": "NGO", "is_col": True} ], "output_column_name": "ngo_lower" }, { "function_name": "TRIM", "operands": [ - "Indicator" + {"value": "measure1", "is_col": True} ], "output_column_name": "trimmed_indicator" } diff --git a/tests/warehouse/test_postgres_ops.py b/tests/warehouse/test_postgres_ops.py index 0ce2887..7ed230f 100644 --- a/tests/warehouse/test_postgres_ops.py +++ b/tests/warehouse/test_postgres_ops.py @@ -1111,14 +1111,14 @@ def test_generic(self): { "function_name": "LOWER", "operands": [ - "NGO" + {"value": "NGO", "is_col": True} ], "output_column_name": "ngo_lower" }, { "function_name": "TRIM", "operands": [ - "measure1" + {"value": "measure1", "is_col": True} ], "output_column_name": "trimmed_measure_1" } From 776de62432cc7ccf6636dd09aa939c8df17bdc62 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 13:04:37 +0530 Subject: [PATCH 12/13] update operations.yaml.template --- dbt_automation/assets/operations.template.yml | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/dbt_automation/assets/operations.template.yml b/dbt_automation/assets/operations.template.yml index 6d3877b..5ff29f3 100644 --- a/dbt_automation/assets/operations.template.yml +++ b/dbt_automation/assets/operations.template.yml @@ -380,11 +380,12 @@ operations: computed_columns: - function_name: operands: - - - output_column_name: - - function_name: - operands: - - + - value: + is_col: + - value: + is_col: + - value: + is_col: output_column_name: - type: pivot @@ -743,12 +744,3 @@ operations: - value: is_col: output_column_name: - - function_name: - operands: - - value: - is_col: - - value: - is_col: - - value: - is_col: - output_column_name: From 4e20d4b4d06046747bd5b84f526b1c784a3cd6a6 Mon Sep 17 00:00:00 2001 From: Abhishek-N Date: Fri, 12 Apr 2024 16:33:15 +0530 Subject: [PATCH 13/13] remove quote_constvalue --- dbt_automation/operations/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_automation/operations/generic.py b/dbt_automation/operations/generic.py index 3531c36..81e66a4 100644 --- a/dbt_automation/operations/generic.py +++ b/dbt_automation/operations/generic.py @@ -35,7 +35,7 @@ def generic_function_dbt_sql( for computed_column in computed_columns: function_name = computed_column["function_name"] operands = [ - quote_constvalue(quote_columnname(str(operand["value"]), warehouse.name), warehouse.name) + quote_columnname(str(operand["value"]), warehouse.name) if operand["is_col"] else quote_constvalue(str(operand["value"]), warehouse.name) for operand in computed_column["operands"]