Error when trying to create a new hive table - hive

I am trying to create a new Hive table, but I am getting the following error
hive> create table salary(id int,name string,salary int,promoted string)
fields terminated by ','
lines terminated by '\n'
stored as textfile;
FAILED: ParseException line 1:67 missing EOF at 'fields' near ')'

In your example, the sentence to create a table with comma separated fields in Hive would be
CREATE TABLE salary(id int,name string,salary int,promoted string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE;

Related

Error while creating hive table

I used the following syntax while creating the hive table--
Create table tablename (ColumnName Type)
row format SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with SERDEPROPERTIES ("separatorChar" = "\;")
lines terminated by '\n'
tblproperties ("skip.header.line.count" = "1");
But I am getting an error message
FAILED: ParseException line 1:361 missing EOF at 'lines' near ')'
I'm not sure what I'm doing wrong. Please help!
If you have a single column, you don't need a separatorchar.If you have multiple fields and if they are separated by ';' then you don't need to escape the ';'
SERDEPROPERTIES ("separatorChar" = ";")
STORED AS TEXTFILE
LOCATION '/path/yourfile.csv'

error loading csv into hive table

I'm trying to load a tab delimited file into a table in hive, and I want to skip the first row because it contains column names. I'm trying to run the code below, but I'm getting the error below. Does anyone see what the issue is?
Code:
set hive.exec.compress.output=false;
set hive.mapred.mode=nonstrict;
-- region to state mapping
DROP TABLE IF EXISTS StateRegion;
CREATE TEMPORARY TABLE StateRegion (Zip_Code int,
Place_Name string,
State string,
State_Abbreviate string,
County string,
Latitude float,
Longitude float,
ZIP_CD int,
District_NM string,
Region_NM string)
row format delimited fields terminated by '\t'
tblproperties("skip.header.line.count"="1");
STORED AS TEXTFILE;
LOAD DATA LOCAL INPATH 'StateRegion'
OVERWRITE INTO TABLE StateRegion;
--test Export
INSERT OVERWRITE LOCAL DIRECTORY './StateRegionTest/'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
select * from StateRegion;
Error:
FAILED: ParseException line 2:0 cannot recognize input near 'STORED' 'AS' 'TEXTFILE'

Load data into HIVE table

My data format is:
1::Toy Story (1995)::Animation|Children's|Comedy
when I try to load data into Hive 3rd column is reading from file .
I created table as follows:
hive> create table movies(mid int,mname string,gn string)
row format delimited
fields terminated by '::'
lines terminated by '\n'
stored as TEXTFILE;
if the table wont read the data try changing the fields delimiter with the relevant unicode of '::'.
hive> create table movies(mid int,mname string,gn array<string>)
row format delimited
fields terminated by '::'
collection items terminated by '|'
lines terminated by '\n'
stored as TEXTFILE;
Now you can load your dataset.

Creating column names with "(" in hive 1.1.0

I tried to create table in hive as below:
create table IF NOT EXISTS department(deptid int, deptname(1) string, deptname(2) string)
row format delimited
fields terminated by ','
lines terminated by '\n'
stored as textfile;
I am getting error as
Error while compiling statement: FAILED: ParseException line 1:58 cannot recognize input near '(' '1' ')' in column type
Is there any other way to create columns with "("
Use ` (backtick) to escape ( (round bracket).
It can be used for both tables names and fields names.
Try:
create table IF NOT EXISTS department(`deptid` int, `deptname(1)` string, `deptname(2)` string) row format delimited fields terminated by ',' lines terminated by '\n' stored as textfile;

Create Table Syntax Error in Hive

I am trying to create a table in hive using following query:
create table customers(Cust_ID INT, Cust_Name STRING, Dealer_ID INT, Country STRING, State STRING, City STRING, ZipCode INT)
row format delimited
fields terminated by ';'
stored as textfile;
but i'm getting the following error:
FAILED: Parse Error: line 0:-1 mismatched input '<EOF>' expecting StringLiteral in table row format's field separator
i have created previously transactions table with same syntax and it had worked out just fine..but somehow i think m making some syntatical error. plz help.
Try escaping ';' by adding '\' os your query will look as follow:
create table customers(Cust_ID INT, Cust_Name STRING, Dealer_ID INT, Country STRING, State STRING, City STRING, ZipCode INT)
row format delimited
fields terminated by '\;'
stored as textfile;
Try using the OCT \073 instead of ';'
Example:
row format delimited fields terminated by '\073'