Skip to content

Commit

Permalink
vdk-trino: fix ingesting value with bool type failing (#753)
Browse files Browse the repository at this point in the history
vdk-trino ingestion was failing if `send_object_for_ingestion` is passed
value with type bool (as it was trying to cast it as if it's stirng.
Error was

"We could not convert the value to that type. Error is bool cast accept
only True/true/False/false values."

Testing Done: unit tests covered the new case

Signed-off-by: Antoni Ivanov <aivanov@vmware.com>
  • Loading branch information
antoniivanov committed Mar 16, 2022
1 parent 2f598d2 commit a0619c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def _ingest_payload(
)

@staticmethod
def __to_bool(value: str) -> bool:
def __to_bool(value: Any) -> bool:
if isinstance(value, bool):
return value
if value == "true" or value == "True":
return True
if value == "false" or value == "False":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def run(job_input):
payload=payload, destination_table="test_table"
)

payload_with_types = {
"str_data": "string",
"int_data": 12,
"float_data": 1.2,
"bool_data": True,
"decimal_data": 3.2,
}

job_input.send_object_for_ingestion(
payload=payload_with_types, destination_table="test_table"
)

# this setup:
# a) partial payload (only few columns are included)
# b) includes float data which is NaN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_ingest_to_trino(self):
"string 12 1.2 True 3.2\n"
"string 12 1.2 True 3.2\n"
"string 12 1.2 True 3.2\n"
"string 12 1.2 True 3.2\n"
"\n"
"------ -- --- ---- ---\n"
)
Expand Down

0 comments on commit a0619c1

Please sign in to comment.