【问题标题】:Difference between 'Stored as InputFormat, OutputFormat' and 'Stored as' in HiveHive 中“存储为 InputFormat、OutputFormat”和“存储为”之间的区别
【发布时间】:2017-11-10 15:21:03
【问题描述】:

如果表是 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’

但是,如果您使用这些子句创建表,则在选择时会出现转换错误。错误喜欢:

异常失败 java.io.IOException:java.lang.ClassCastException: org.apache.hadoop.hive.ql.io.orc.OrcStruct 不能转换为 org.apache.hadoop.io.BinaryComparable


要解决此问题,只需将 create table 语句更改为 STORED AS ORC

但是,正如答案在类似问题中所说: What is the difference between 'InputFormat, OutputFormat' & 'Stored as' in Hive? .

不知道是什么原因。

【问题讨论】:

  • 据我所知,STORED AS ORCSTORED AS INPUTFORMAT 'org.apache.hive.ql.io.orc.OrcInputFormat' 完全相同。它只是为输入和输出格式指定完全限定类的简写。

标签: hadoop hive hiveql orc hive-serde


【解决方案1】:

STORED AS 意味着 3 件事:

  1. SERDE
  2. 输入格式
  3. 输出格式

您只定义了最后 2 个,让 SERDE 由 hive.default.serde

定义

hive.default.serde
默认值:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
添加于:Hive 0.14 与 HIVE-5976
默认 SerDe Hive 将用于未指定 SerDe 的存储格式。
当前未指定 SerDe 的存储格式包括“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')

【讨论】:

    【解决方案2】:

    您可以在创建表时在STORED AS 中指定INPUTFORMATOUTPUTFORMATSERDE。 Hive 允许您将记录格式与文件格式分开。您可以为INPUTFORMATOUTPUTFORMATSERDE 提供自定义类。查看详情:http://www.dummies.com/programming/big-data/hadoop/defining-table-record-formats-in-hive/

    您也可以简单地写STORED AS ORCSTORED AS TEXTFILE,例如。 STORED AS ORC 语句已经处理了INPUTFORMATOUTPUTFORMATSERDE。这使您不必为INPUTFORMATOUTPUTFORMATSERDE 编写那些长的完全限定的Java 类名。只需STORED AS ORC

    【讨论】:

      猜你喜欢
      • 2017-07-13
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 2012-01-26
      • 2012-10-18
      • 2014-05-22
      相关资源
      最近更新 更多