Skip to content

Commit 3ee710d

Browse files
feat: add min macros (#203)
Signed-off-by: Artem Inzhyyants <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 884897e commit 3ee710d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

airbyte_cdk/sources/declarative/interpolation/macros.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ def max(*args: typing.Any) -> typing.Any:
9494
return builtins.max(*args)
9595

9696

97+
def min(*args: typing.Any) -> typing.Any:
98+
"""
99+
Returns smallest object of an iterable, or two or more arguments.
100+
101+
min(iterable, *[, default=obj, key=func]) -> value
102+
min(arg1, arg2, *args, *[, key=func]) -> value
103+
104+
Usage:
105+
`"{{ min(2,3) }}"
106+
107+
With a single iterable argument, return its smallest item. The
108+
default keyword-only argument specifies an object to return if
109+
the provided iterable is empty.
110+
With two or more arguments, return the smallest argument.
111+
:param args: args to compare
112+
:return: smallest argument
113+
"""
114+
return builtins.min(*args)
115+
116+
97117
def day_delta(num_days: int, format: str = "%Y-%m-%dT%H:%M:%S.%f%z") -> str:
98118
"""
99119
Returns datetime of now() + num_days
@@ -147,6 +167,7 @@ def format_datetime(
147167
today_utc,
148168
timestamp,
149169
max,
170+
min,
150171
day_delta,
151172
duration,
152173
format_datetime,

unit_tests/sources/declarative/interpolation/test_jinja.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def test_to_string(test_name, input_value, expected_output):
184184
id="test_timestamp_from_rfc3339",
185185
),
186186
pytest.param("{{ max(1,2) }}", 2, id="test_max"),
187+
pytest.param("{{ min(1,2) }}", 1, id="test_min"),
187188
],
188189
)
189190
def test_macros(s, expected_value):
@@ -291,6 +292,8 @@ def test_undeclared_variables(template_string, expected_error, expected_value):
291292
),
292293
pytest.param("{{ max(2, 3) }}", 3, id="test_max_with_arguments"),
293294
pytest.param("{{ max([2, 3]) }}", 3, id="test_max_with_list"),
295+
pytest.param("{{ min(2, 3) }}", 2, id="test_min_with_arguments"),
296+
pytest.param("{{ min([2, 3]) }}", 2, id="test_min_with_list"),
294297
pytest.param("{{ day_delta(1) }}", "2021-09-02T00:00:00.000000+0000", id="test_day_delta"),
295298
pytest.param(
296299
"{{ day_delta(-1) }}", "2021-08-31T00:00:00.000000+0000", id="test_day_delta_negative"

unit_tests/sources/declarative/interpolation/test_macros.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
("test_now_utc", "now_utc", True),
1616
("test_today_utc", "today_utc", True),
1717
("test_max", "max", True),
18+
("test_min", "min", True),
1819
("test_day_delta", "day_delta", True),
1920
("test_format_datetime", "format_datetime", True),
2021
("test_duration", "duration", True),

0 commit comments

Comments
 (0)