Hive 中 'Stored as InputFormat, OutputFormat' 和 'Stored as' 之间的区别
Difference between 'Stored as InputFormat, OutputFormat' and 'Stored as' in Hive
如果 table 是 ORC,执行 show create table
然后执行生成的 create table
语句时出现问题。
使用show create table
,你得到这个:
STORED AS INPUTFORMAT
‘org.apache.hadoop.hive.ql.io.orc.OrcInputFormat’
OUTPUTFORMAT
‘org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat’
但是如果您使用这些子句创建 table,您将在选择时遇到转换错误。错误喜欢:
Failed with exception
java.io.IOException:java.lang.ClassCastException:
org.apache.hadoop.hive.ql.io.orc.OrcStruct cannot be cast to
org.apache.hadoop.io.BinaryComparable
要解决此问题,只需将 create table
语句更改为 STORED AS ORC
但是,正如类似问题中的答案所说:
.
我想不通原因。
STORED AS
意味着 3 件事:
- SERDE
- 输入格式
- 输出格式
您只定义了最后 2 个,SERDE 由 hive.default.serde
定义
hive.default.serde
Default Value: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
Added in: Hive 0.14 with HIVE-5976
The default SerDe Hive will use for storage formats that do not specify a SerDe.
Storage formats that currently do not specify a SerDe include 'TextFile, RcFile'.
演示
hive.default.serde
set hive.default.serde;
hive.default.serde=org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
存储为兽人
create table mytable (i int)
stored as orc;
show create table mytable;
请注意,SERDE 是 'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
CREATE TABLE `mytable`(
`i` int)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
'file:/home/cloudera/local_db/mytable'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}',
'numFiles'='0',
'numRows'='0',
'rawDataSize'='0',
'totalSize'='0',
'transient_lastDdlTime'='1496982059')
存储为输入格式...输出格式...
create table mytable2 (i int)
STORED AS
INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
;
show create table mytable2
;
请注意,SERDE 是 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
CREATE TABLE `mytable2`(
`i` int)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
'file:/home/cloudera/local_db/mytable2'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}',
'numFiles'='0',
'numRows'='0',
'rawDataSize'='0',
'totalSize'='0',
'transient_lastDdlTime'='1496982426')
您可以在创建 table 时在 STORED AS
中指定 INPUTFORMAT
、OUTPUTFORMAT
、SERDE
。 Hive 允许您将记录格式与文件格式分开。您可以为 INPUTFORMAT
、OUTPUTFORMAT
、SERDE
提供自定义 classes。查看详情:http://www.dummies.com/programming/big-data/hadoop/defining-table-record-formats-in-hive/
或者您可以简单地写 STORED AS ORC
或 STORED AS TEXTFILE
等。
STORED AS ORC 语句已经处理了 INPUTFORMAT
、OUTPUTFORMAT
和 SERDE
。这使您不必为 INPUTFORMAT
、OUTPUTFORMAT
、SERDE
编写那些长的完全限定的 Java class 名称。只是 STORED AS ORC
而不是。
如果 table 是 ORC,执行 show create table
然后执行生成的 create table
语句时出现问题。
使用show create table
,你得到这个:
STORED AS INPUTFORMAT
‘org.apache.hadoop.hive.ql.io.orc.OrcInputFormat’
OUTPUTFORMAT
‘org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat’
但是如果您使用这些子句创建 table,您将在选择时遇到转换错误。错误喜欢:
Failed with exception java.io.IOException:java.lang.ClassCastException: org.apache.hadoop.hive.ql.io.orc.OrcStruct cannot be cast to org.apache.hadoop.io.BinaryComparable
要解决此问题,只需将 create table
语句更改为 STORED AS ORC
但是,正如类似问题中的答案所说:
我想不通原因。
STORED AS
意味着 3 件事:
- SERDE
- 输入格式
- 输出格式
您只定义了最后 2 个,SERDE 由 hive.default.serde
定义hive.default.serde
Default Value: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
Added in: Hive 0.14 with HIVE-5976
The default SerDe Hive will use for storage formats that do not specify a SerDe.
Storage formats that currently do not specify a SerDe include 'TextFile, RcFile'.
演示
hive.default.serde
set hive.default.serde;
hive.default.serde=org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
存储为兽人
create table mytable (i int)
stored as orc;
show create table mytable;
请注意,SERDE 是 'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
CREATE TABLE `mytable`(
`i` int)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
'file:/home/cloudera/local_db/mytable'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}',
'numFiles'='0',
'numRows'='0',
'rawDataSize'='0',
'totalSize'='0',
'transient_lastDdlTime'='1496982059')
存储为输入格式...输出格式...
create table mytable2 (i int)
STORED AS
INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
;
show create table mytable2
;
请注意,SERDE 是 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
CREATE TABLE `mytable2`(
`i` int)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
'file:/home/cloudera/local_db/mytable2'
TBLPROPERTIES (
'COLUMN_STATS_ACCURATE'='{\"BASIC_STATS\":\"true\"}',
'numFiles'='0',
'numRows'='0',
'rawDataSize'='0',
'totalSize'='0',
'transient_lastDdlTime'='1496982426')
您可以在创建 table 时在 STORED AS
中指定 INPUTFORMAT
、OUTPUTFORMAT
、SERDE
。 Hive 允许您将记录格式与文件格式分开。您可以为 INPUTFORMAT
、OUTPUTFORMAT
、SERDE
提供自定义 classes。查看详情:http://www.dummies.com/programming/big-data/hadoop/defining-table-record-formats-in-hive/
或者您可以简单地写 STORED AS ORC
或 STORED AS TEXTFILE
等。
STORED AS ORC 语句已经处理了 INPUTFORMAT
、OUTPUTFORMAT
和 SERDE
。这使您不必为 INPUTFORMAT
、OUTPUTFORMAT
、SERDE
编写那些长的完全限定的 Java class 名称。只是 STORED AS ORC
而不是。