2

是否可以使用具有 RC 或 ORC 文件格式的 JSON serde?我正在尝试使用文件格式 ORC 插入 Hive 表并以序列化 JSON 的形式存储在 azure blob 中。

4

2 回答 2

1

显然不是

insert overwrite local directory '/home/cloudera/local/mytable' 
stored as orc 
select '{"mycol":123,"mystring","Hello"}'
;

create external table verify_data (rec string) 
stored as orc 
location 'file:////home/cloudera/local/mytable'
;

select * from verify_data
;

记录 {" mycol
":123,"mystring","Hello"}

create external table mytable (myint int,mystring string)
row format serde 'org.apache.hive.hcatalog.data.JsonSerDe' 
stored as orc
location 'file:///home/cloudera/local/mytable'
;

myint mystring
失败并出现异常 java.io.IOException:java.lang.ClassCastException:
org.apache.hadoop.hive.ql.io.orc.OrcStruct 无法转换为 org.apache.hadoop.io.Text

JsonSerDe.java

...
import org.apache.hadoop.io.Text;
...

  @Override
  public Object deserialize(Writable blob) throws SerDeException {

    Text t = (Text) blob;
  ...
于 2017-04-05T06:35:38.423 回答
0

您可以使用某种转换步骤来执行此操作,例如分桶步骤,它将在目标目录中生成 ORC 文件,并在分桶后安装具有相同架构的配置单元表。如下所示。

CREATE EXTERNAL TABLE my_fact_orc
(
  mycol STRING,
  mystring INT
)
PARTITIONED BY (dt string)
CLUSTERED BY (some_id) INTO 64 BUCKETS
STORED AS ORC
LOCATION 's3://dev/my_fact_orc'
TBLPROPERTIES ('orc.compress'='SNAPPY');

ALTER TABLE my_fact_orc ADD IF NOT EXISTS PARTITION (dt='2017-09-07') LOCATION 's3://dev/my_fact_orc/dt=2017-09-07';

ALTER TABLE my_fact_orc PARTITION (dt='2017-09-07') SET FILEFORMAT ORC;

SELECT * FROM my_fact_orc WHERE dt='2017-09-07' LIMIT 5;
于 2018-01-15T23:46:50.983 回答