From 52036976ad6c01c1d9ace2f391ec13f69ebdb025 Mon Sep 17 00:00:00 2001 From: Manish Kumar <97503740+manishkumar1991@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:22:21 +0530 Subject: [PATCH] Update ingestASimSampleData.py --- .../asimParsersTest/ingestASimSampleData.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.script/tests/asimParsersTest/ingestASimSampleData.py b/.script/tests/asimParsersTest/ingestASimSampleData.py index 9b3022be241..11f940561cb 100644 --- a/.script/tests/asimParsersTest/ingestASimSampleData.py +++ b/.script/tests/asimParsersTest/ingestASimSampleData.py @@ -267,6 +267,28 @@ def extract_event_vendor_product(parser_query,parser_file): print(f'Event Product field not mapped in parser. Please map it in parser query.{parser_file}') return event_vendor, event_product ,schema_name +def convert_data_type(schema_result, data_result): + for data in data_result: + for schema in schema_result: + field_name = schema["name"] + field_type = schema["type"] + + if field_name in data: + value = data[field_name] + + # Handle conversion based on schema type + + if field_type == "string": + # Convert to string + data[field_name] = str(value) + elif field_type == "boolean": + # Convert to boolean + if isinstance(value, str) and value.lower() in ["true", "false"]: + data[field_name] = value.lower() == "true" + + return data_result + + #main starting point of script workspace_id = "e9beceee-7d61-429f-a177-ee5e2b7f481a" @@ -336,7 +358,11 @@ def extract_event_vendor_product(parser_query,parser_file): else: print(f"::error::An error occurred while trying to get content of Schema file located at {schemaUrl}: {response.text}") continue - schema_result = convert_schema_csv_to_json('tempfile.csv') + schema_result = convert_schema_csv_to_json('tempfile.csv') + data_result = convert_data_type(schema_result, data_result) + # conversion of datatype is needed for boolean and string values because during testing it has been observed that + # boolean values are consider as string and numerical value of type string are consider + # as integer which leds to non ingestion of those value in sentinel # create table request_body, url_to_call , method_to_use = create_table(json.dumps(schema_result, indent=4),table_name) response_body=hit_api(url_to_call,request_body,method_to_use)