Hive - Adding comments to tables - hive

When I try to add comments to my Hive table,
ALTER TABLE table1 SET TBLPROPERTIES ('comment' = new_comment);
I get the following error:
FAILED: ParseException line 1:64 mismatched input 'new_comment' expecting StringLiteral near '=' in specifying key/value property
Anyone know how to properly add a comment?

The comment needs to be a quoted string. For example, these should work:
ALTER TABLE table1 SET TBLPROPERTIES ('comment' = 'Hello World!');
ALTER TABLE table1 SET TBLPROPERTIES ('comment' = "Hello World!");

Related

Create Hive table using “as select” and also specify TBLPROPERTIES

For example, when using Parquet format, I'd like to be able to specify the compression scheme (("parquet.compression"="SNAPPY")). Running this query:
CREATE TABLE table_a_copy
STORED AS PARQUET
TBLPROPERTIES("parquet.compression"="SNAPPY")
AS
SELECT * FROM table_a
returns an error:
Error: Error while compiling statement: FAILED: ParseException line 1:69 cannot recognize input near 'parquet' '.' 'compression' in table properties list (state=42000,code=40000)
The same query without the TBLPROPERTIES works just fine.
This is similar to this question: Create hive table using "as select" or "like" and also specify delimiter. But I can't figure out how to make TBLPROPERTIES work with that approach. I'm using Hive 1.1.
I was able to run same exact statement in Hive 2.1.1 version.
Try with this workaround:
CREATE TABLE table_a_copy like table_a STORED AS PARQUET;
alter table set TBLPROPERTIES("parquet.compression"="SNAPPY");
insert into table table_a_copy select * from table_a ;

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

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

is "following" a reserved keyword in 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);