From 91a14dc55519f73ffea94d2341556b0642c05d5b Mon Sep 17 00:00:00 2001 From: Antoni Ivanov Date: Sat, 5 Mar 2022 18:28:32 +0200 Subject: [PATCH] vdk-trino: fix ingesting value with bool type failing 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 --- .../src/vdk/plugin/trino/ingest_to_trino.py | 4 +++- .../test_ingest_to_trino_job/10_ingest_to_trino.py | 12 ++++++++++++ .../vdk-trino/tests/test_ingest_to_trino.py | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py b/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py index 0f92ad655e..203949df03 100644 --- a/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py +++ b/projects/vdk-plugins/vdk-trino/src/vdk/plugin/trino/ingest_to_trino.py @@ -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": diff --git a/projects/vdk-plugins/vdk-trino/tests/jobs/test_ingest_to_trino_job/10_ingest_to_trino.py b/projects/vdk-plugins/vdk-trino/tests/jobs/test_ingest_to_trino_job/10_ingest_to_trino.py index 8f626d30c2..f996c5e801 100644 --- a/projects/vdk-plugins/vdk-trino/tests/jobs/test_ingest_to_trino_job/10_ingest_to_trino.py +++ b/projects/vdk-plugins/vdk-trino/tests/jobs/test_ingest_to_trino_job/10_ingest_to_trino.py @@ -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 diff --git a/projects/vdk-plugins/vdk-trino/tests/test_ingest_to_trino.py b/projects/vdk-plugins/vdk-trino/tests/test_ingest_to_trino.py index 0c64fb358d..42485f664f 100644 --- a/projects/vdk-plugins/vdk-trino/tests/test_ingest_to_trino.py +++ b/projects/vdk-plugins/vdk-trino/tests/test_ingest_to_trino.py @@ -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" )