FAILED: ParseException line 5:16 cannot recognize input near 'TIME' ',' 'store_name' in column type - hive

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';

Related

How Create a hive external table with parquet format

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'

Amazon Athena returning "mismatched input 'partitioned' expecting {, 'with'}" error when creating partitions

I'd like to use this query to create a partitioned table in Amazon Athena:
CREATE TABLE IF NOT EXISTS
testing.partitioned_test(order_id bigint, name string, car string, country string)
PARTITIONED BY (year int)
ROW FORMAT SERDE 'parquet.hive.serde.ParquetHiveSerDe'
STORED AS 'PARQUET'
LOCATION 's3://testing-imcm-into/partitions'
Unfortunately I don't get the error message which tells me the following:
line 3:2: mismatched input 'partitioned' expecting {, 'with'}
The quotes around 'PARQUET' seemed to be causing a problem.
Try this:
CREATE EXTERNAL TABLE IF NOT EXISTS
partitioned_test (order_id bigint, name string, car string, country string)
PARTITIONED BY (year int)
STORED AS PARQUET
LOCATION 's3://testing-imcm-into/partitions/'

Error while running Hive command with DATE as of the colume name

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 ',';

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'

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'