使用直线从配置单元服务器 2 导出 ORC 文件时的列名
Column names when exporting ORC files from hive server 2 using beeline
我遇到一个问题,从配置单元服务器 2 导出结果到 ORC 文件显示某种默认列名(例如 _col0、_col1、_col2)而不是在配置单元中创建的原始列名。我们使用了来自 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
正在创建测试 table 并插入示例值:
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 的连接将配置到 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 文件。
您必须在 hive script
或 hive-shell
中设置它,否则将其放在主目录或任何其他配置单元用户属性文件中的 .hiverc
文件中。
set hive.cli.print.header=true;
解决方案
您需要在 Ambari 中启用 Hive LLAP(交互式 SQL),然后更改您正在使用的连接字符串。比如我的连接变成了jdbc:hive2://.../;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-hive2
请注意 URL 末尾的附加“-hive2”。这是来自 hortonworks 的 tutorial vid。
"Proof"
连接到更新的 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 仓库在 github 上分发的工具。
我遇到一个问题,从配置单元服务器 2 导出结果到 ORC 文件显示某种默认列名(例如 _col0、_col1、_col2)而不是在配置单元中创建的原始列名。我们使用了来自 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
正在创建测试 table 并插入示例值:
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 的连接将配置到 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 文件。
您必须在 hive script
或 hive-shell
中设置它,否则将其放在主目录或任何其他配置单元用户属性文件中的 .hiverc
文件中。
set hive.cli.print.header=true;
解决方案
您需要在 Ambari 中启用 Hive LLAP(交互式 SQL),然后更改您正在使用的连接字符串。比如我的连接变成了jdbc:hive2://.../;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-hive2
请注意 URL 末尾的附加“-hive2”。这是来自 hortonworks 的 tutorial vid。
"Proof"
连接到更新的 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 仓库在 github 上分发的工具。