From 5fb7c76e2b17031901a315732c27a7c62827f300 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 20 Mar 2023 15:31:57 -0500 Subject: [PATCH 1/5] add negative test case --- .../dbt/tests/adapter/utils/fixture_split_part.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py b/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py index 7fc70e5bf54..4d4288182fe 100644 --- a/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py +++ b/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py @@ -1,8 +1,8 @@ # split_part -seeds__data_split_part_csv = """parts,split_on,result_1,result_2,result_3 -a|b|c,|,a,b,c -1|2|3,|,1,2,3 +seeds__data_split_part_csv = """parts,split_on,result_1,result_2,result_3,result_4 +a|b|c,|,a,b,c,c +1|2|3,|,1,2,3,3 ,|,,, """ @@ -34,6 +34,14 @@ {{ split_part('parts', 'split_on', 3) }} as actual, result_3 as expected +from data + +union all + +select + {{ split_part('parts', 'split_on', -1) }} as actual, + result_4 as expected + from data """ From 8c64e80669cde761758088044e2714e83b221d0b Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 20 Mar 2023 15:33:32 -0500 Subject: [PATCH 2/5] changie --- .changes/unreleased/Fixes-20230320-153225.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230320-153225.yaml diff --git a/.changes/unreleased/Fixes-20230320-153225.yaml b/.changes/unreleased/Fixes-20230320-153225.yaml new file mode 100644 index 00000000000..c6b55115780 --- /dev/null +++ b/.changes/unreleased/Fixes-20230320-153225.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: add negative part_number arg for split part macro +time: 2023-03-20T15:32:25.5932-05:00 +custom: + Author: dave-connors-3 + Issue: "615" From 83c97ca3d5b74106f99e0c7b2533c57ef5eaaca0 Mon Sep 17 00:00:00 2001 From: Dave Connors Date: Mon, 20 Mar 2023 16:30:02 -0500 Subject: [PATCH 3/5] missed a comma --- tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py b/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py index 4d4288182fe..244fbdb7464 100644 --- a/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py +++ b/tests/adapter/dbt/tests/adapter/utils/fixture_split_part.py @@ -3,7 +3,7 @@ seeds__data_split_part_csv = """parts,split_on,result_1,result_2,result_3,result_4 a|b|c,|,a,b,c,c 1|2|3,|,1,2,3,3 -,|,,, +,|,,,, """ From 755921413c46a875bf8fc20a772b55aa83d5bde8 Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Wed, 21 Jun 2023 10:50:40 -0600 Subject: [PATCH 4/5] Update changelog entry --- .changes/unreleased/Fixes-20230320-153225.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/unreleased/Fixes-20230320-153225.yaml b/.changes/unreleased/Fixes-20230320-153225.yaml index c6b55115780..be49986203f 100644 --- a/.changes/unreleased/Fixes-20230320-153225.yaml +++ b/.changes/unreleased/Fixes-20230320-153225.yaml @@ -3,4 +3,4 @@ body: add negative part_number arg for split part macro time: 2023-03-20T15:32:25.5932-05:00 custom: Author: dave-connors-3 - Issue: "615" + Issue: "7915" From 70d421732fdc65b9b6574d49106a7c49ae89e511 Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:03:11 -0600 Subject: [PATCH 5/5] Add a negative number (rather than subtract a positive number) --- core/dbt/include/global_project/macros/utils/split_part.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/include/global_project/macros/utils/split_part.sql b/core/dbt/include/global_project/macros/utils/split_part.sql index cecc4497b58..766539ac0c1 100644 --- a/core/dbt/include/global_project/macros/utils/split_part.sql +++ b/core/dbt/include/global_project/macros/utils/split_part.sql @@ -20,7 +20,7 @@ length({{ string_text }}) - length( replace({{ string_text }}, {{ delimiter_text }}, '') - ) + 2 {{ part_number }} + ) + 2 + {{ part_number }} ) {% endmacro %}