Support Questions

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

Hive Insert into table issue

avatar
Contributor

I need to create a table with just a field, which is a map of string: string. I have created the table without problems, but when I try to insert the values (they are defined, not in another table) I am not able to achieve it. The code is below.

create table comunidades ( codigo MAP<STRING, STRING> );
INSERT INTO TABLE comunidades SELECT 1, {"AND": '01'};
1 ACCEPTED SOLUTION

avatar
Master Mentor

@Luis Ruiz

I tried recreating your situation and it worked. see attached.To use the map function the source tables should already exist. I used a text file ruiz.txt with values

$ cat ruiz.txt
"AND": '01'
"TOO": '02'
"MORE": '03'

Hope that helps please accept the reponse if it resolved your problem!

View solution in original post

12 REPLIES 12

avatar

@Luis Ruiz

Are you trying to insert from one table to another and facing this issue?

If that is the case then when you are inserting from one table to another then you may need to convert the columns into MAP as you have used MAP in the second table.

avatar
Contributor

@Luis Ruiz

You should use map() complex type constructor in your insert statement.

insert into table testMap SELECT map('AND','01');

You can find more details about complex type constructors from here:

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

avatar
Contributor
@Jagruti Varia

I've just tried your command and it returns an error. I'm using the Hortonworks Sandbox, and I don't understand why it throws that error.

org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:52 Failed to recognize predicate '<EOF>'. Failed rule: 'regularBody' in statement

avatar
Master Mentor

@Luis Ruiz

I tried recreating your situation and it worked. see attached.To use the map function the source tables should already exist. I used a text file ruiz.txt with values

$ cat ruiz.txt
"AND": '01'
"TOO": '02'
"MORE": '03'

Hope that helps please accept the reponse if it resolved your problem!

avatar
Contributor

@Geoffrey Shelton Okot

I have repeated your steps in Ambari and it throws me an error (below). I have checked the community entries and it's something repeated. I don't know if there is a solution yet for this issue.

java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask

avatar
Master Mentor

@Luis Ruiz

Try this

# cd /tmp/data 
# su - hdfs 
$ hdfs dfs -copyFromLocal autonomias.txt  /apps/hive/warehouse/ 
$ hdfs dfs -chown -R hive:hive  /apps/hive/warehouse/ 
hive> load data inpath '/apps/hive/warehouse/autonomias.txt' into table comunidades;

Tell me that should work

avatar
Contributor
@Geoffrey Shelton Okot

In Ambari I have no terminal client, I upload files through a visual interface and the permissions for the file and folder are all enabled. I though the same, a problem with the permissions, but not. I don't know if the Sandbox is limited in some Hive operations

avatar
Master Mentor

@Luis Ruiz

Install putty to interact with your sandbox from your desktop, let download what is the version of sandbox?

avatar
Contributor

@Geoffrey Shelton Okot

Yes I know about putty, but it is possible to do also from Ambari. I will try to do it from putty.

The version of the sandbox is 2.6.1 for VirtualBox. It's available here: https://es.hortonworks.com/downloads/#sandbox