使用Beeline从Hive Server 2导出ORC文件时



我面临一个问题,即来自Hive Server 2到ORC文件的导出结果显示某种默认的列名称(例如_COL0,_COL1,_COL2(,而不是在Hive中创建的原始列。我们正在使用 HDP-2.6.3.0 的几乎默认组件。

我也想知道以下问题是否相关:

https://issues.apache.org/jira/browse/hive-4243

以下是我们正在采取的步骤:

连接:

export SPARK_HOME=/usr/hdp/current/spark2-client
beeline
!connect jdbc:hive2://HOST1:2181,HOST2:2181,HOST2:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

创建测试表并插入样本值:

create table test(str string);
insert into test values ('1');
insert into test values ('2');
insert into test values ('3');

运行测试查询:

select * from test;
+-----------+--+
| test.str  |
+-----------+--+
| 1         |
| 2         |
| 3         |
+-----------+--+

导出为ORC:

insert overwrite directory 'hdfs://HOST1:8020/tmp/test' stored as orc select * from test;

获得结果:

hdfs dfs -get /tmp/test/000000_0 test.orc

检查结果:

java -jar orc-tools-1.4.1-uber.jar data test.orc
Processing data file test.orc [length: 228]
{"_col0":"1"}
{"_col0":"2"}
{"_col0":"3"}
java -jar orc-tools-1.4.1-uber.jar meta test.orc
Processing data file test.orc [length: 228]
Structure for test.orc
File Version: 0.12 with HIVE_13083
Rows: 2
Compression: SNAPPY
Compression size: 262144
Type: struct<_col0:string>
Stripe Statistics:
  Stripe 1:
    Column 0: count: 2 hasNull: false
    Column 1: count: 2 hasNull: false min: 1 max: 3 sum: 2
File Statistics:
  Column 0: count: 2 hasNull: false
  Column 1: count: 2 hasNull: false min: 1 max: 3 sum: 2
Stripes:
  Stripe: offset: 3 data: 11 rows: 2 tail: 60 index: 39
    Stream: column 0 section ROW_INDEX start: 3 length 11
    Stream: column 1 section ROW_INDEX start: 14 length 28
    Stream: column 1 section DATA start: 42 length 5
    Stream: column 1 section LENGTH start: 47 length 6
    Encoding column 0: DIRECT
    Encoding column 1: DIRECT_V2
File length: 228 bytes
Padding length: 0 bytes
Padding ratio: 0%

查看结果,我可以看到 _COL0 是列名称,同时期待原始 str

关于我缺少什么的想法?

update

我注意到,Beeline的连接将用于Hive 1.x ,而不是 2.x> 2.x 。我将连接更改为 Hive Server 2 Interactive url:

Connected to: Apache Hive (version 2.1.0.2.6.3.0-235)
Driver: Hive JDBC (version 1.21.2.2.6.3.0-235)
Transaction isolation: TRANSACTION_REPEATABLE_READ

并再次尝试使用相同的样本。它甚至正确打印出架构:

INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:test.str, type:string, comment:null)], properties:null)

,但仍然没有运气。

解决方案

您需要在Ambari中启用Hive LLAP(Interactive SQL(,然后更改所使用的连接字符串。例如,我的连接变成jdbc:hive2://.../;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-hive2

请注意URL末尾的其他" -hive2"。这是Hortonworks的教程VID。

"证明"

连接到更新的Hive端点后,我运行

create table t_orc(customer string, age int) stored as orc;
insert into t_orc values('bob', 12),('kate', 15);

然后

~$ hdfs dfs -copyToLocal /apps/hive/warehouse/t_orc/000000_0 ~/tmp/orc/hive2.orc 
~$ orc-metadata tmp/orc/hive2.orc 
{ "name": "tmp/orc/hive2.orc",
  "type": "struct<customer:string,age:int>",
  "rows": 2,
  "stripe count": 1,
  "format": "0.12", "writer version": "HIVE-13083",
  "compression": "zlib", "compression block": 262144,
  "file length": 305,
  "content": 139, "stripe stats": 46, "footer": 96, "postscript": 23,
  "row index stride": 10000,
  "user metadata": {
  },
  "stripes": [
    { "stripe": 0, "rows": 2,
      "offset": 3, "length": 136,
      "index": 67, "data": 23, "footer": 46
    }
  ]
}

其中 orc-metadata是orc repo在github上分发的工具。

您必须在hive scripthive-shell中设置此设置,否则将其放入主目录或任何其他Hive用户属性文件中的.hiverc文件中。

set hive.cli.print.header=true;

最新更新