is "following" a reserved keyword in Hive? - hive

Hive command - create table table_name (accountId string,name string,following string);
throws following exception,
[main] ERROR org.apache.hadoop.hive.ql.Driver - FAILED: ParseException line 2:198 cannot recognize input near 'following' 'string' ',' in column specification
org.apache.hadoop.hive.ql.parse.ParseException: line 2:198 cannot recognize input near 'following' 'string' ',' in column specification
In the below link,"following" is not mentioned in the reserved keywords list,
http://docs.treasuredata.com/articles/faq

I think it might be in the reserved key word list. However you can use the below query to create the column name following.
create table test (accountId string,name string,`following` string);

Related

How to drop a column starting with a Digit in Netezza

Due to some error while uploading data, extra columns got created and one of the column names became 84. Trying to remove that column but getting following error:
org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [1100] [HY000]: ERROR: 'ALTER TABLE XXX.XXXXX
DROP 84'
error ^ found "84" (at char 44) expecting an identifier, identifiers must begin with a letter
You can find examples of how to handle identifiers that does does not begin with a letter. You can wrap the identifier in double quotes
https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.1/com.ibm.nz.dbu.doc/c_dbuser_handle_sql_identifiers.html

Modify / Change command not working in HIVE for converting String type data to TIMESTAMP

I want to change datatype from String to TimeStamp in hive but below queries aren't helping.
ALTER TABLE so_wireless_cpu_utilization MODIFY start_time start_time TIMESTAMP;
It throws below error:
Getting log thread is interrupted, since query is done!
Error: Error while compiling statement: FAILED: ParseException line 1:40 cannot recognize input near 'MODIFY' 'start_time' 'start_time' in alter table statement (state=42000,code=40000)
org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:40 cannot recognize input near 'MODIFY' 'start_time' 'start_time' in alter table statement
at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:279)
Also, I tried below query but it doesn't work either:
alter table so_wireless_ap_channels CHANGE load_date load_date String;
So what is the best way of converting the string format to timestamp in hive.

Error : ParseException line 2:0 missing EOF at 'LIKE' near ')'

I would like to create externel table using like option.
CREATE EXTERNAL TABLE IF NOT EXISTS test1 (rec string)
LIKE 'EPCTR_201804'
LOCATION '/hdfs/t1/tt1/PR/34/1xx/E1ERPSE/201801/PR/20180202-000758/*';
But this error was shown saying :
FAILED: ParseException line 2:0 missing EOF at 'LIKE' near ')'
How can I resolve it please ?
You don't have to give schema for new table. When you use CREATE TABLE LIKE, new table keeps the same schema as old one.
Use following:
CREATE EXTERNAL TABLE IF NOT EXISTS test1
LIKE 'EPCTR_201804'
LOCATION '/hdfs/t1/tt1/PR/34/1xx/E1ERPSE/201801/PR/20180202-000758/*';
Create Table Like should be without columns specification, because LIKE means create table with the same exactly schema like the other table.
Also table location is a folder where the data files are being stored, there should be no /* at the end, like this:
CREATE EXTERNAL TABLE IF NOT EXISTS test1 LIKE 'EPCTR_201804'
LOCATION '/hdfs/t1/tt1/PR/34/1xx/E1ERPSE/201801/PR/20180202-000758';

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

How to add avro.schema.url to hive partition storage information?

I am trying command
ALTER TABLE mytable PARTITION(date='2010-02-22') SET 'avro.schema.url'
'hdfs://xxx.com:9000/location/to/my/schema/_schema.avsc';
But it is returning parsing Error :
FAILED: ParseException line 1:49 cannot recognize input near 'SET'
''avro.schema.url'' ''hdfs://xxx.com:9000/location/to/my/schema/_schema.avsc'' in alter
table partition statement suffix
This is right syntax:
ALTER TABLE mytable PARTITION(date='2010-02-22') SET TBLPROPERTIES(
'avro.schema.url'
'hdfs://xxx.com:9000/location/to/my/schema/_schema.avsc');