Anastasia Novikova
Anastasia Novikova

Reputation: 111

Using SQL reserved words in Hive when creating external temporary table

I need to create an external hive table from hdfs location where one column in files has reserved name (end).

When running the script I get the error: "cannot recognize input near 'end' 'STRUCT' '<' in column specification"

I found 2 solutions.

The first one is to set hive.support.sql11.reserved.keywords=false, but this option has been removed. https://issues.apache.org/jira/browse/HIVE-14872

The second solution is to use quoted identifiers (column).

But in this case I get the error: "org.apache.hadoop.hive.serde2.SerDeException: org.codehaus.jackson.JsonParseException: Unexpected character ('c' (code 99)): was expecting comma to separate OBJECT entries"

This is my code for table creation:

CREATE TEMPORARY EXTERNAL TABLE ${tmp_db}.${tmp_table}
(
    id STRING,
    email STRUCT<string:STRING>,
    start STRUCT<long:BIGINT>,
    end STRUCT<long:BIGINT>
)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
LOCATION '${input_dir}';

It's not possible to rename the column.

Does anybody know the solution for this problem? Or maybe any ideas? Thanks a lot in advance!

Upvotes: 0

Views: 775

Answers (1)

Vijiy
Vijiy

Reputation: 1197

can you try below.

hive> set hive.support.quoted.identifiers=column;
hive> create temporary table sp_char ( `#` int, `end` string);

OK Time taken: 0.123 seconds

OK
Time taken: 0.362 seconds
hive>

When you set hive property hive.support.quoted.identifiers=column all the values within back ticks are treated as literals. Other value for above property is none , when it is set to none you can use regex to evaluate the column or expression value.

Hope this helps

Upvotes: 0

Related Questions