|
57 | 57 | select * from {{ ref('input_model') }} |
58 | 58 | """ |
59 | 59 |
|
| 60 | +microbatch_model_hour_sql = """ |
| 61 | +{{ config(materialized='incremental', incremental_strategy='microbatch', unique_key='id', event_time='event_time', batch_size='hour', begin=modules.datetime.datetime(2020, 1, 1, 0, 0, 0)) }} |
| 62 | +select * from {{ ref('input_model') }} |
| 63 | +""" |
| 64 | + |
| 65 | +microbatch_model_month_sql = """ |
| 66 | +{{ config(materialized='incremental', incremental_strategy='microbatch', unique_key='id', event_time='event_time', batch_size='month', begin=modules.datetime.datetime(2020, 1, 1, 0, 0, 0)) }} |
| 67 | +select * from {{ ref('input_model') }} |
| 68 | +""" |
| 69 | + |
| 70 | +microbatch_model_year_sql = """ |
| 71 | +{{ config(materialized='incremental', incremental_strategy='microbatch', unique_key='id', event_time='event_time', batch_size='year', begin=modules.datetime.datetime(2020, 1, 1, 0, 0, 0)) }} |
| 72 | +select * from {{ ref('input_model') }} |
| 73 | +""" |
| 74 | + |
60 | 75 | microbatch_model_with_pre_and_post_sql = """ |
61 | 76 | {{ config( |
62 | 77 | materialized='incremental', |
@@ -841,6 +856,111 @@ def test_run_with_event_time(self, project): |
841 | 856 | ) |
842 | 857 |
|
843 | 858 |
|
| 859 | +class TestMicrobatchCompiledRunPathsHourly(BaseMicrobatchTest): |
| 860 | + |
| 861 | + @pytest.fixture(scope="class") |
| 862 | + def models(self): |
| 863 | + return { |
| 864 | + "input_model.sql": input_model_sql, |
| 865 | + "microbatch_model.sql": microbatch_model_hour_sql, |
| 866 | + } |
| 867 | + |
| 868 | + def test_run_with_event_time(self, project): |
| 869 | + # run all partitions from start - 2 expected rows in output, one failed |
| 870 | + with patch_microbatch_end_time("2020-01-03 13:57:00"): |
| 871 | + run_dbt(["run"]) |
| 872 | + |
| 873 | + # Compiled paths - batch compilations |
| 874 | + assert read_file( |
| 875 | + project.project_root, |
| 876 | + "target", |
| 877 | + "compiled", |
| 878 | + "test", |
| 879 | + "models", |
| 880 | + "microbatch_model", |
| 881 | + "microbatch_model_2020-01-03T13.sql", |
| 882 | + ) |
| 883 | + assert read_file( |
| 884 | + project.project_root, |
| 885 | + "target", |
| 886 | + "run", |
| 887 | + "test", |
| 888 | + "models", |
| 889 | + "microbatch_model", |
| 890 | + "microbatch_model_2020-01-03T13.sql", |
| 891 | + ) |
| 892 | + |
| 893 | + |
| 894 | +class TestMicrobatchCompiledRunPathsMonthly(BaseMicrobatchTest): |
| 895 | + |
| 896 | + @pytest.fixture(scope="class") |
| 897 | + def models(self): |
| 898 | + return { |
| 899 | + "input_model.sql": input_model_sql, |
| 900 | + "microbatch_model.sql": microbatch_model_month_sql, |
| 901 | + } |
| 902 | + |
| 903 | + def test_run_with_event_time(self, project): |
| 904 | + # run all partitions from start - 2 expected rows in output, one failed |
| 905 | + with patch_microbatch_end_time("2020-01-03 13:57:00"): |
| 906 | + run_dbt(["run"]) |
| 907 | + |
| 908 | + # Compiled paths - batch compilations |
| 909 | + assert read_file( |
| 910 | + project.project_root, |
| 911 | + "target", |
| 912 | + "compiled", |
| 913 | + "test", |
| 914 | + "models", |
| 915 | + "microbatch_model", |
| 916 | + "microbatch_model_2020-01.sql", |
| 917 | + ) |
| 918 | + assert read_file( |
| 919 | + project.project_root, |
| 920 | + "target", |
| 921 | + "run", |
| 922 | + "test", |
| 923 | + "models", |
| 924 | + "microbatch_model", |
| 925 | + "microbatch_model_2020-01.sql", |
| 926 | + ) |
| 927 | + |
| 928 | + |
| 929 | +class TestMicrobatchCompiledRunPathsYearly(BaseMicrobatchTest): |
| 930 | + |
| 931 | + @pytest.fixture(scope="class") |
| 932 | + def models(self): |
| 933 | + return { |
| 934 | + "input_model.sql": input_model_sql, |
| 935 | + "microbatch_model.sql": microbatch_model_year_sql, |
| 936 | + } |
| 937 | + |
| 938 | + def test_run_with_event_time(self, project): |
| 939 | + # run all partitions from start - 2 expected rows in output, one failed |
| 940 | + with patch_microbatch_end_time("2020-01-03 13:57:00"): |
| 941 | + run_dbt(["run"]) |
| 942 | + |
| 943 | + # Compiled paths - batch compilations |
| 944 | + assert read_file( |
| 945 | + project.project_root, |
| 946 | + "target", |
| 947 | + "compiled", |
| 948 | + "test", |
| 949 | + "models", |
| 950 | + "microbatch_model", |
| 951 | + "microbatch_model_2020.sql", |
| 952 | + ) |
| 953 | + assert read_file( |
| 954 | + project.project_root, |
| 955 | + "target", |
| 956 | + "run", |
| 957 | + "test", |
| 958 | + "models", |
| 959 | + "microbatch_model", |
| 960 | + "microbatch_model_2020.sql", |
| 961 | + ) |
| 962 | + |
| 963 | + |
844 | 964 | class TestMicrobatchFullRefreshConfigFalse(BaseMicrobatchTest): |
845 | 965 | @pytest.fixture(scope="class") |
846 | 966 | def models(self): |
|
0 commit comments