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'
Related
I am trying to create an external table in hive with the following query in HDFS.
CREATE EXTERNAL TABLE `post` (
FileSK STRING,
OriginalSK STRING,
FileStatus STRING,
TransactionType STRING,
TransactionDate STRING
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS PARQUET TBLPROPERTIES("Parquet.compression"="SNAPPY")
LOCATION 'hdfs://.../post'
getting error
Error while compiling statement: FAILED: ParseException line 11:2
missing EOF at 'LOCATION' near ')'
What is the best way to create a HIVE external table with data stored in parquet format?
I am able to create table after removing property TBLPROPERTIES("Parquet.compression"="SNAPPY")
CREATE EXTERNAL TABLE `post` (
FileSK STRING,
OriginalSK STRING,
FileStatus STRING,
TransactionType STRING,
TransactionDate STRING
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS PARQUET,
LOCATION 'hdfs://.../post'
I am getting error when trying to create a table in hive database. I am accessing it through docker image.
The command I am using:
root#:/opt/Hadoop#hive -f test_db.sql
Below mentioned is the content for the .sql file:
create database test_db;
use test_db;
CREATE EXTERNAL TABLE purchases (
purchase_date DATE,
Purchase_time TIME,
store_name STRING,
item_name STRING,
item_cost FLOAT,
payment STRING
) ROW FORMAT DELIMITED
FIELDS TERMINATED BY '#'
STORED AS TEXTFILE
LOCATION '/user/input/purchases';
The error is:
FAILED: ParseException line 5:16 cannot recognize input near 'TIME' ','
'store_name' in column type
Any idea what's wrong in this?
Thanks!
When I changed the 'TIME' datatype into 'TIMESTAMP' and tried building the table, I could build the table inside HIVE.
create database test_db;
use test_db;
CREATE EXTERNAL TABLE purchases (
purchase_date DATE,
Purchase_time TIMESTAMP,
store_name STRING,
item_name STRING,
item_cost FLOAT,
payment STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE
LOCATION '/user/input/purchases';
create table Book_inf2(OID int, date timestamp, CUSTOMER_ID string, AMOUNT
int) row format delimited fields terminated by ',';
Error which I got:
FAILED: ParseException line 1:32 missing Identifier at 'date' near
'date' in create table statement line 1:37 mismatched input
'timestamp' expecting ) near 'date' in create table statement
Note: I am new to the Hive, please help me to get understand.
Date is a reserved keyword in hive that's the reason why you are facing issue
However hive allows to use reserved keywords as field names, but that's not the best practice to use them.
To fix the issue:
Surround date field name with backtick's
`
Try with below create table statement
hive> create table Book_inf2(OID int, `date` timestamp, CUSTOMER_ID string, AMOUNT int) row format delimited fields terminated by ',';
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'
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;