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'
Related
When I use hive to create a table, I am prompted not to include the dot symbol.
(state=42000,code=40000)
How can I solve this problem?
CREATE EXTERNAL TABLE `ods.a2`(
`key` string COMMENT 'k',
`value` string COMMENT 'v')
COMMENT '注释'
ROW FORMAT SERDE
'org.apache.hadoop.hive.contrib.serde2.MultiDelimitSerDe'
WITH SERDEPROPERTIES (
'field.delim'=',,',
'serialization.format'=',,')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs:///user/hive/warehouse/ods.db/a2';
err:
Error: Error while compiling statement: FAILED: SemanticException Line 1:22 Table or database name may not contain dot(.) character 'ods.a2' (state=42000,code=40000)
Please use CREATE EXTERNAL TABLE `ods`.`a2`
If any components of a multiple-part name require quoting, quote them individually rather than quoting the name as a whole. For example, write `my-table`.`my-column`, not `my-table.my-column`
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;
This article shows that we can use multi-character delimiter in Hive.
But can we also specify the NULL value?
I tried the following hive sql which returns an error:
CREATE TABLE temp
( a STRING, b STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.MultiDelimitSerDe'
WITH SERDEPROPERTIES ("field.delim"="##")
NULL DEFINED AS 'NULL'
STORED AS TEXTFILE;
The error:
Error: Error while compiling statement: FAILED: ParseException line 5:0 missing EOF at 'NULL' near ')' (state=42000,code=40000)
The option to use NULL DEFINED AS 'NULL' is available when we are using a ROW FORMAT DELIMITED option. Here we are using a ROW FORMAT SERDE option so we need to explicitly pass the property serialization.null.format.
you can use the below query by setting the property value of serialization.null.format:
CREATE TABLE temp
( a STRING, b STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.MultiDelimitSerDe'
WITH SERDEPROPERTIES ("field.delim"="##",'serialization.null.format'='NULL')
STORED AS TEXTFILE;
For more information you can refer Hive DDL reference guide. MultiDelimitSerde source code.
HIVE DDL GUIDE:
row_format
: DELIMITED [FIELDS TERMINATED BY char [ESCAPED BY char]] [COLLECTION ITEMS TERMINATED BY char]
[MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]
[NULL DEFINED AS char] -- (Note: Available in Hive 0.13 and later)
| SERDE serde_name [WITH SERDEPROPERTIES (property_name=property_value, property_name=property_value, ...)]
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;
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!");