【问题标题】:HIve CLI doesn't support MySql style data import to tablesHive CLI 不支持将 MySql 样式数据导入表
【发布时间】:2013-03-04 10:15:45
【问题描述】:

为什么我们不能将数据导入 Hive CLI,如下所示,hive_test 表有 user、comments 列。

insert into table hive_test (user, comments) 
value ("hello", "this is a test query");

Hive 在 Hive CLI 中引发以下异常

失败:ParseException line 1:28 无法识别 select 子句中 '(' 'user' ',' 附近的输入

我不想像下面这样通过 csv 文件导入数据以进行测试。

load data local inpath '/home/hduser/test_data.csv' into table hive_test;

【问题讨论】:

    标签: sql hadoop hive


    【解决方案1】:

    值得注意的是,Hive 宣传“类似 SQL”的语法,而不是实际的 SQL 语法。没有特别的理由认为纯 SQL 查询实际上会在 Hive 上运行。 HiveQL 的 DML 记录在 here on the Wiki 中,不支持列规范语法或 VALUES 子句。但是,它确实支持这种语法:

    INSERT INTO TABLE tablename1 SELECT ... FROM ...
    

    从these test queries 推断,您可能会得到类似以下的工作:

    INSERT INTO TABLE hive_test SELECT 'hello', 'this is a test query' FROM src LIMIT 1
    

    但是,Hive 似乎并没有真正针对这种小规模数据操作进行优化。我没有 Hive 实例来测试这些。

    【讨论】:

    • src 是什么意思?还有其他表名吗?
    • @KugathasanAbimaran:我想是的。只是从那里的测试用例开始,但任何表都应该工作。
    • 对于仍然好奇的人:INSERT...VALUES 从 Hive 0.14 开始可用。
    【解决方案2】:

    我认为,这是因为user 是一个内置(保留)关键字。

    试试这个:

    insert into table hive_test ("user", comments) 
    value ('hello', 'this is a test query');
    

    【讨论】:

    • [] 在(标准)SQL 中无效。保留字需要用双引号"引用
    • @a_horse_with_no_name :我尝试过使用不同的列,例如insert into table hive_test_table (test_column, comments) value ("hms", "this is a test query");。不可能!
    • @KugathasanAbimaran:您需要用双引号引用 column 名称,而不是值。字符值(字符串文字)必须用 单 引号括起来:insert into table hive_test ("user", comments) values ('hello', 'this is a test query'); 在标准 SQL 中它应该是 values 而不是 value
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    相关资源
    最近更新 更多