Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Error inserting json file content into Hive string column

avatar
New Contributor

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.
1 REPLY 1

avatar
Community Manager

@alangularte Welcome to our community! To help you get the best possible answer, I have tagged in our Hive experts @asish @Shelton  who may be able to assist you further.

Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.



Regards,

Vidya Sargur,
Community Manager


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community: