将配置单元表导出到.avro文件

时间:2014-03-04 02:15:00

标签: sql hadoop export hive

我创建了一个这样的外部配置单元表:

CREATE EXTERNAL TABLE some_hive_table
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
LOCATION '/hdfs/path/some_hive_table/'
TBLPROPERTIES ('avro.schema.literal'='{json schema here}');

我想对它运行一些配置单元查询并将该数据导出到avro文件中。我知道我可以导出这样的数据:

INSERT
OVERWRITE DIRECTORY '/hdfs/path/avrofileoutput/' 
SELECT * FROM some_hive_table; 

但我希望我的输出文件是avro文件 - 而不是csv。可以这样做,如果是这样的话?

2 个答案:

答案 0 :(得分:2)

您可以使用以下命令将任何表格(无论InputStorage作为AVRO文件)导出到本地位置或HDFS位置。

从Hive 0.11.0开始

import pytest
import os
import datetime
from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

db = SQLAlchemy(app)


@pytest.fixture
def app():
    app = create_app()
    db.create_all()
    # db.session.commit()  # Try this with and without this line
    yield app
    db.session.remove()
    db.drop_all()

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Writingdataintothefilesystemfromqueries

答案 1 :(得分:1)

您可以尝试以下选项。

从some_hive_table_text插入覆盖表some_hive_table_avro select *;