Compare commits
No commits in common. "8b6819873d1c37440e7c80f6a720c5d947cfd477" and "64d5097e1b7bfe30100d86dda71cc35505176dcb" have entirely different histories.
8b6819873d
...
64d5097e1b
|
|
@ -39,29 +39,12 @@ def _string_value(value: Any) -> str | None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _flatten_projection_values(value: Any, json_path: Any = None) -> list[str]:
|
def _flatten_projection_values(value: Any) -> list[str]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return []
|
return []
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
result: list[str] = []
|
result: list[str] = []
|
||||||
for item in value:
|
for item in value:
|
||||||
result.extend(_flatten_projection_values(item, json_path))
|
|
||||||
return result
|
|
||||||
if isinstance(value, dict):
|
|
||||||
if json_path:
|
|
||||||
paths = [json_path] if isinstance(json_path, str) else list(json_path)
|
|
||||||
extracted: list[str] = []
|
|
||||||
for p in paths:
|
|
||||||
sub_val = value.get(p)
|
|
||||||
if sub_val is not None:
|
|
||||||
extracted.extend(_flatten_projection_values(sub_val))
|
|
||||||
if extracted:
|
|
||||||
return extracted
|
|
||||||
direct = _string_value(value)
|
|
||||||
if direct:
|
|
||||||
return [direct]
|
|
||||||
result = []
|
|
||||||
for item in value.values():
|
|
||||||
result.extend(_flatten_projection_values(item))
|
result.extend(_flatten_projection_values(item))
|
||||||
return result
|
return result
|
||||||
direct = _string_value(value)
|
direct = _string_value(value)
|
||||||
|
|
@ -307,30 +290,9 @@ class SearchRepository:
|
||||||
values.append(row["value_date"].isoformat())
|
values.append(row["value_date"].isoformat())
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def _project_value(
|
def _project_value(self, raw: Any, strategy: str) -> list[ProjectionValue]:
|
||||||
self,
|
|
||||||
raw: Any,
|
|
||||||
strategy: str,
|
|
||||||
metadata: dict[str, Any] | None = None,
|
|
||||||
) -> list[ProjectionValue]:
|
|
||||||
strategy = strategy.strip().lower()
|
strategy = strategy.strip().lower()
|
||||||
json_path = (metadata or {}).get("json_path") or (metadata or {}).get("json_key")
|
raw_values = _flatten_projection_values(raw)
|
||||||
raw_values = _flatten_projection_values(raw, json_path=json_path)
|
|
||||||
if strategy in ("multivalue", "comma_delimited", "delimited"):
|
|
||||||
split_values: list[str] = []
|
|
||||||
for item in raw_values:
|
|
||||||
if "," in item or ";" in item:
|
|
||||||
for token in item.replace(";", ",").split(","):
|
|
||||||
cleaned = token.strip().rstrip(".").strip()
|
|
||||||
if cleaned:
|
|
||||||
cleaned = cleaned[:1].upper() + cleaned[1:]
|
|
||||||
split_values.append(cleaned)
|
|
||||||
else:
|
|
||||||
cleaned = item.strip().rstrip(".").strip()
|
|
||||||
if cleaned:
|
|
||||||
cleaned = cleaned[:1].upper() + cleaned[1:]
|
|
||||||
split_values.append(cleaned)
|
|
||||||
raw_values = split_values
|
|
||||||
projected: list[ProjectionValue] = []
|
projected: list[ProjectionValue] = []
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
for label in raw_values:
|
for label in raw_values:
|
||||||
|
|
@ -444,13 +406,7 @@ class SearchRepository:
|
||||||
)
|
)
|
||||||
values: list[ProjectionValue] = []
|
values: list[ProjectionValue] = []
|
||||||
for raw in raw_rows:
|
for raw in raw_rows:
|
||||||
values.extend(
|
values.extend(self._project_value(raw, mapping.mapping_strategy))
|
||||||
self._project_value(
|
|
||||||
raw,
|
|
||||||
mapping.mapping_strategy,
|
|
||||||
metadata=mapping.metadata,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
for value in values:
|
for value in values:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue