I have a Hive table which was created with the following command:
create external table test_temp (url string, database_name string, created_date date, json_file string)
row format delimited fields terminated by ';';
My json file has the following content:
{
"uri": "t",
"database": "v3.1",
"start_time, ": "2023-06-08T13:36:12.327935",
"end_time": "2023-06-08T15:29:01.423394",
"duration": "1:52:49.095459
}
This is the piece of my Python code that tries to insert the json above into the mentioned Hive table:
import cml.data_v1 as cmldata
import json
conn = cmldata.get_connection("hive-conn")
db_cursor = conn.get_cursor()
with open('json_file.json') as f:
json_file = f.read()
params = ("url_test", "v3.1", "2023-03-05", json_file)
query = "INSERT INTO test_temp (url, database_name, created_date, json_file) VALUES (?,?,?,?)"
db_cursor.execute(query, params)
db_cursor.commit()
But I am getting the following error:
KeyError: '\\\\\\"uri\\\\\\"'
- This script is running in CML (Cloudera Machine Learning).
- I also tried to convert the json file to have all the content in a single line, but the error is still the same.
- I also tried to use json.dumps(json_file), but the error is still the same.
- I also tried to use str(json_file), but the error is still the same.