[英]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). 我需要从hdfs位置创建一个外部配置单元表,其中文件中的一列具有保留名称(结尾)。
When running the script I get the error: "cannot recognize input near 'end' 'STRUCT' '<' in column specification" 运行脚本时出现错误:“无法在列规范中识别'end''STRUCT''<'附近的输入”
I found 2 solutions. 我找到2个解决方案。
The first one is to set hive.support.sql11.reserved.keywords=false, but this option has been removed. 第一个是设置hive.support.sql11.reserved.keywords = false,但是此选项已被删除。 https://issues.apache.org/jira/browse/HIVE-14872
https://issues.apache.org/jira/browse/HIVE-14872
The second solution is to use quoted identifiers ( column
). 第二种解决方案是使用带引号的标识符(
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" 但是在这种情况下,我得到了错误:“ org.apache.hadoop.hive.serde2.SerDeException:org.codehaus.jackson.JsonParseException:意外字符('c'(代码99)):期望逗号分隔对象条目”
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!
在此先多谢!
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时间:0.123秒
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. 当您设置hive属性
hive.support.quoted.identifiers=column
内的所有值都被视为文字。 Other value for above property is none , when it is set to none you can use regex to evaluate the column or expression value. 上述属性的其他值是none ,如果设置为none,则可以使用regex评估列或表达式的值。
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.