Python 如何使用luigi将输出写入orc格式的分区表?
假设我们有这样的工作:Python 如何使用luigi将输出写入orc格式的分区表?,python,hadoop,mapreduce,etl,luigi,Python,Hadoop,Mapreduce,Etl,Luigi,假设我们有这样的工作: class MRjob(JobTask): def output(self): return ... def requires(self): return ... def mapper(self, line): # some line process yield key, (...information, stored in hashable type...) def reducer(self,key,values):
class MRjob(JobTask):
def output(self):
return ...
def requires(self):
return ...
def mapper(self, line):
# some line process
yield key, (...information, stored in hashable type...)
def reducer(self,key,values):
# some reduce logic... for example this
unique = set(values)
for elem in unique:
yield key, elem[0], elem[1]
在output方法中,我应该如何将数据插入现有的表分区(表也是以orc格式存储的)?我想跳过将数据转换为orc的过程,所以我尝试
return HivePartitionTarget(self.insert_table, database=self.database_name, partition=partition)
但这不起作用。我还发现luigi试图将输出传递给某个文件。对于HivePartitionTarget,luigi返回类似“对象没有属性写入”的错误,所以我的假设是HivePartitionTarget不包含写入方法。因此,我认为我做错了什么,应该使用另一种方法,但没有找到一个例子我不太清楚如何在
luigi
中实现这一点。我建议使用一种简单的方法,以普通分隔格式(比如逗号分隔格式)编写luigi
脚本的输出
在上面创建一个外部配置单元表:
CREATE EXTERNAL TABLE temp_table(
<col_name> <col_type>,
<col_name2> <col_type>
.......
.......
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘,’
LOCATION ‘ /hive/data/weatherext’;
您的目标表将具有ORC格式的数据,hive将为您处理转换
有关详细语法,请参阅
我对luigi不太了解,但给出了一种方法。希望这对你有用。是的,这是一个可能的解决方案。我发现没有python库可以转换为ORC格式。因此,我转而使用HiveQueryTask并处理相应表的sql脚本。所以,基本上这是你的建议
INSERT INTO TABLE target_table
PARTITION( xxx )
SELECT
COL_NAME1,
COL_NAME2
FROM temp_table;