使用直线从配置单元服务器2导出orc文件时的列名

vlf7wbxs  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(332)

我面临一个问题,从配置单元服务器2导出结果到orc文件时,会显示某种默认列名(例如,\u col0、\u col1、\u 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

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

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%

在查看结果时,我可以看到\u col0作为列名,而预期的是原始str。
你知道我遗漏了什么吗?
更新
我注意到beeline的连接将连接到hive1.x,而不是2.x。我更改了与hive server 2交互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)

但还是没找到兽人的档案。

pcrecxhr

pcrecxhr1#

解决方案

您需要在ambari中启用hivellap(交互式sql),然后更改正在使用的连接字符串。例如,我的关系变得 jdbc:hive2://.../;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-hive2 请注意url末尾的附加“-hive2”。这是一个来自hortonworks的教程视频。

“证明”

连接到更新的配置单元终结点后,我运行

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分发的工具。

bnl4lu3b

bnl4lu3b2#

你得把这个放进去 hive script 或者 hive-shell 否则把它放在一个 .hiverc 文件或任何其他配置单元用户属性文件。

set hive.cli.print.header=true;

相关问题