我通过遵循命令和avro模式创建了一个配置单元表。
CREATE TABLE table_name
PARTITIONED BY (t string, y string, m string, d string, h string, hh string)
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'
TBLPROPERTIES (
'avro.schema.url'='hdfs://location/schema.avsc');
现在我想将HDFS中的数据转储到创建的表中。
我有一个HDFS位置,在这里我的目录结构中的数据为t / y / m / d / h / hh / data.avro。根据分区,我有多个目录,因为这是我的分区列。
我想将所有数据转储到创建的表中。
我尝试使用外部表,但它给出了异常。
如果您在hdfs文件夹中遵循配置单元约定并创建指向该表位置的配置单元表,则应运行msck repair table语句。
例如
CREATE TABLE table_name
PARTITIONED BY (t string, y string, m string, d string, h string, hh string)
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'
TBLPROPERTIES (
'avro.schema.url'='hdfs://location/schema/schema.avsc')
location "hdfs:///location/data;
并像这样加载数据
/location/data/y=2016/m=02/d=03/h=03/hh=12/data.avro / location / data / y = 2016 / m = 02 / d = 03 / h = 03 / hh = 13 / data2.avro
这样,您将能够使用以下语句加载数据,因为Hive会识别分区
msck repair table table_name;
如果您不想这样做,可以使用添加分区,例如
ALTER TABLE table_nameADD PARTITION (y='01',m='02',d='03',h='03',hh='12') location '/yourpath/y=2016/m=02/d=03/h=03/hh=12/'; (or any other folder)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句