Skip to content

Commit

Permalink
HGI-7053: Fallback to str if no type set (#5)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Hassan Syyid <[email protected]>
  • Loading branch information
butkeraites-hotglue and hsyyid authored Jan 15, 2025
1 parent 742b903 commit d42663f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions target_parquet/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ def build_pyarrow_field(key: str, value: dict):
)


def parse_record_value(record_value, property: dict):
def parse_record_value(record_value, key: str, property: dict):
if record_value in [None, ""]:
return None

if "anyOf" in property:
property = property["anyOf"][0]

types = remove_null_string(property["type"])
type_id = types[0] if isinstance(types, list) else types
if "type" in property:
types = remove_null_string(property["type"])
type_id = types[0] if isinstance(types, list) else types
else:
# raise Exception(f"No type found for property {key}:{property}. Check your schema.")
type_id = "string"

if type_id == "number":
return float(record_value)
Expand Down Expand Up @@ -150,7 +154,7 @@ def process_record(self, record: dict, context: dict) -> None:
"""Process the record."""

for (key, property) in self.schema["properties"].items():
record[key] = parse_record_value(record.get(key), property)
record[key] = parse_record_value(record.get(key), key, property)

context["records"].append(record)

Expand Down

0 comments on commit d42663f

Please sign in to comment.