From 17a2bce0ff7f8d574c9cf7bd2c6bfce5aa927faa Mon Sep 17 00:00:00 2001 From: Artem Inzhyyants Date: Tue, 7 Jan 2025 17:25:52 +0100 Subject: [PATCH 1/3] CDK: add min macros Signed-off-by: Artem Inzhyyants --- .../declarative/interpolation/macros.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/airbyte_cdk/sources/declarative/interpolation/macros.py b/airbyte_cdk/sources/declarative/interpolation/macros.py index e786f0116..1ca5b31f0 100644 --- a/airbyte_cdk/sources/declarative/interpolation/macros.py +++ b/airbyte_cdk/sources/declarative/interpolation/macros.py @@ -94,6 +94,26 @@ def max(*args: typing.Any) -> typing.Any: return builtins.max(*args) +def min(*args: typing.Any) -> typing.Any: + """ + Returns smallest object of an iterable, or two or more arguments. + + min(iterable, *[, default=obj, key=func]) -> value + min(arg1, arg2, *args, *[, key=func]) -> value + + Usage: + `"{{ min(2,3) }}" + + With a single iterable argument, return its smallest item. The + default keyword-only argument specifies an object to return if + the provided iterable is empty. + With two or more arguments, return the smallest argument. + :param args: args to compare + :return: smallest argument + """ + return builtins.min(*args) + + def day_delta(num_days: int, format: str = "%Y-%m-%dT%H:%M:%S.%f%z") -> str: """ Returns datetime of now() + num_days @@ -147,6 +167,7 @@ def format_datetime( today_utc, timestamp, max, + min, day_delta, duration, format_datetime, From 7eaa17fab73b4c49f4d63bd79ef02bbbfef2c385 Mon Sep 17 00:00:00 2001 From: Artem Inzhyyants Date: Tue, 7 Jan 2025 17:28:52 +0100 Subject: [PATCH 2/3] CDK: add unit tests Signed-off-by: Artem Inzhyyants --- unit_tests/sources/declarative/interpolation/test_jinja.py | 3 +++ unit_tests/sources/declarative/interpolation/test_macros.py | 1 + 2 files changed, 4 insertions(+) diff --git a/unit_tests/sources/declarative/interpolation/test_jinja.py b/unit_tests/sources/declarative/interpolation/test_jinja.py index 1126520f9..a99236324 100644 --- a/unit_tests/sources/declarative/interpolation/test_jinja.py +++ b/unit_tests/sources/declarative/interpolation/test_jinja.py @@ -184,6 +184,7 @@ def test_to_string(test_name, input_value, expected_output): id="test_timestamp_from_rfc3339", ), pytest.param("{{ max(1,2) }}", 2, id="test_max"), + pytest.param("{{ min(1,2) }}", 1, id="test_min"), ], ) def test_macros(s, expected_value): @@ -291,6 +292,8 @@ def test_undeclared_variables(template_string, expected_error, expected_value): ), pytest.param("{{ max(2, 3) }}", 3, id="test_max_with_arguments"), pytest.param("{{ max([2, 3]) }}", 3, id="test_max_with_list"), + pytest.param("{{ min(2, 3) }}", 2, id="test_min_with_arguments"), + pytest.param("{{ min([2, 3]) }}", 2, id="test_min_with_list"), pytest.param("{{ day_delta(1) }}", "2021-09-02T00:00:00.000000+0000", id="test_day_delta"), pytest.param( "{{ day_delta(-1) }}", "2021-08-31T00:00:00.000000+0000", id="test_day_delta_negative" diff --git a/unit_tests/sources/declarative/interpolation/test_macros.py b/unit_tests/sources/declarative/interpolation/test_macros.py index 4aa2a0c08..cca454b98 100644 --- a/unit_tests/sources/declarative/interpolation/test_macros.py +++ b/unit_tests/sources/declarative/interpolation/test_macros.py @@ -15,6 +15,7 @@ ("test_now_utc", "now_utc", True), ("test_today_utc", "today_utc", True), ("test_max", "max", True), + ("test_min", "max", True), ("test_day_delta", "day_delta", True), ("test_format_datetime", "format_datetime", True), ("test_duration", "duration", True), From f16ab95ddef7c9a70a80835675a0871d94b73759 Mon Sep 17 00:00:00 2001 From: Artem Inzhyyants <36314070+artem1205@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:44:51 +0100 Subject: [PATCH 3/3] Update unit_tests/sources/declarative/interpolation/test_macros.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- unit_tests/sources/declarative/interpolation/test_macros.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit_tests/sources/declarative/interpolation/test_macros.py b/unit_tests/sources/declarative/interpolation/test_macros.py index cca454b98..3fcad5d15 100644 --- a/unit_tests/sources/declarative/interpolation/test_macros.py +++ b/unit_tests/sources/declarative/interpolation/test_macros.py @@ -15,7 +15,7 @@ ("test_now_utc", "now_utc", True), ("test_today_utc", "today_utc", True), ("test_max", "max", True), - ("test_min", "max", True), + ("test_min", "min", True), ("test_day_delta", "day_delta", True), ("test_format_datetime", "format_datetime", True), ("test_duration", "duration", True),