- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Hive Insert into table issue
- Labels:
-
Apache Hive
Created 08-14-2017 12:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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'};
Created 08-16-2017 09:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Created 08-14-2017 01:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Created 08-14-2017 06:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 08-16-2017 07:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 08-16-2017 09:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Created 08-16-2017 09:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 08-16-2017 10:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 08-16-2017 10:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 08-16-2017 11:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Install putty to interact with your sandbox from your desktop, let download what is the version of sandbox?
Created 08-16-2017 11:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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