Skip to content

Commit 6bde991

Browse files
fix(mappers): Configuration schema now reflects that casting to bool(...) in stream map __filter__ expressions is not required (#3350)
fix(mapper): Configuration schema now reflects that casting to `bool(...)` in stream map `__filter__` expressions is not required
1 parent 43502d2 commit 6bde991

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

singer_sdk/helpers/capabilities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
),
6767
Property(
6868
"__filter__",
69-
StringType(pattern=r"^bool\((.*)\)$"),
69+
StringType(),
7070
title="Filter",
7171
description=(
7272
"Filter out records from a stream. A string expression "
@@ -79,7 +79,7 @@
7979
),
8080
Property(
8181
"__key_properties__",
82-
ArrayType(StringType),
82+
ArrayType(StringType()),
8383
title="Key Properties",
8484
description="Primary key properties for the stream.",
8585
nullable=False,

singer_sdk/mapper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,9 @@ def _init_functions_and_schema( # noqa: PLR0912, PLR0915, C901
443443
"""
444444
stream_map = copy.copy(stream_map)
445445

446-
filter_rule: str | None = None
446+
filter_rule: str | None = stream_map.pop(MAPPER_FILTER_OPTION, None)
447447
include_by_default = True
448-
if stream_map and MAPPER_FILTER_OPTION in stream_map:
449-
filter_rule = stream_map.pop(MAPPER_FILTER_OPTION)
448+
if filter_rule is not None:
450449
try:
451450
filter_rule_parsed: ast.Expr = ast.parse(filter_rule).body[0] # type: ignore[assignment]
452451
except (SyntaxError, IndexError) as ex:

tests/core/test_mapper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,11 +977,17 @@ def discover_streams(self):
977977
id="json_dumps",
978978
),
979979
pytest.param(
980-
{"mystream": {"__filter__": "bool(count < 20)"}},
980+
{"mystream": {"__filter__": "count < 20"}},
981981
{"flattening_enabled": False, "flattening_max_depth": 0},
982982
"filter_records.jsonl",
983983
id="filter_records",
984984
),
985+
pytest.param(
986+
{"mystream": {"__filter__": "bool(count < 20)"}},
987+
{"flattening_enabled": False, "flattening_max_depth": 0},
988+
"filter_records_cast_to_bool.jsonl",
989+
id="filter_records_cast_to_bool",
990+
),
985991
pytest.param(
986992
{"mystream": "__NULL__"},
987993
{"flattening_enabled": False, "flattening_max_depth": 0},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"type":"SCHEMA","stream":"mystream","schema":{"properties":{"email":{"type":["string"]},"count":{"type":["integer","null"]},"user":{"properties":{"id":{"type":["integer","null"]},"sub":{"properties":{"num":{"type":["integer","null"]},"custom_obj":{"type":["string","null"]}},"type":["object","null"],"additionalProperties":true},"some_numbers":{"items":{"type":["number"]},"type":["array","null"]}},"type":["object","null"],"additionalProperties":true},"joined_at":{"format":"date-time","type":["string","null"]}},"type":"object","required":["email"],"$schema":"https://json-schema.org/draft/2020-12/schema"},"key_properties":[]}
2+
{"type":"RECORD","stream":"mystream","record":{"email":"bob@example.com","count":13,"user":{"id":2,"sub":{"num":2,"custom_obj":"obj-world"},"some_numbers":[10.32,1.618]},"joined_at":"2022-01-01T00:00:00Z"},"time_extracted":"2022-01-01T00:00:00+00:00"}
3+
{"type":"RECORD","stream":"mystream","record":{"email":"charlie@example.com","count":19,"user":{"id":3,"sub":{"num":3,"custom_obj":"obj-hello"},"some_numbers":[1.414,1.732]},"joined_at":"2022-01-01T00:00:00Z"},"time_extracted":"2022-01-01T00:00:00+00:00"}
4+
{"type":"STATE","value":{"bookmarks":{"mystream":{}}}}

0 commit comments

Comments
 (0)