使用beeline从配置单元服务器2导出ORC文件时的列名

时间:2018-02-08 09:13:11

标签: hive orc beeline

我遇到的问题是,从hive服务器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

关于我缺少的任何想法?

更新

我注意到beeline的连接是hob 1.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)

但是把它带到ORC文件仍然没有运气。

2 个答案:

答案 0 :(得分:0)

您必须在conda install rpy2 hive script中进行设置,否则请将其放在主目录或任何其他配置单元用户属性文件的hive-shell文件中。

.hiverc

答案 1 :(得分:0)

解决方案

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

注意额外的&#34; -hive2&#34;在URL的末尾。这是来自hortonworks的tutorial vid

&#34;证明&#34;

连接到更新的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是由github上的ORC repo分发的工具。