Hive 在配置单元分区中写入子目录
问题陈述 我有如下文件,其中包含模式事件\u Time、AD\u idHive 在配置单元分区中写入子目录,hive,partition,subdirectory,Hive,Partition,Subdirectory,问题陈述 我有如下文件,其中包含模式事件\u Time、AD\u id file_20170102-May have records with event_time for 20170101,20170102,20170103 file_20170103-May have records with event_time for 20170102,20170103,20170104 这里事件时间是事件发生的时间,文件名上的时间戳是收集事件的时间。因此文件名上的时间戳和文件中的事件时间不同步 当我
file_20170102-May have records with event_time for 20170101,20170102,20170103
file_20170103-May have records with event_time for 20170102,20170103,20170104
这里事件时间是事件发生的时间,文件名上的时间戳是收集事件的时间。因此文件名上的时间戳和文件中的事件时间不同步
当我将此数据写入hive时,我肯定需要基于事件时间分区写入数据,因为用户对基于事件时间的查询感兴趣
因此,我的输出如下所示
/path/to/output/event_time=20170102/....parquet
/path/to/output/event_time=20170103/....parquet
但是,我需要能够跟踪文件时间戳,因为有时文件会被重新提交,我们希望根据文件时间戳删除已经处理过的文件
我有没有办法写这个
/路径/目标/输出/事件\u时间=20170101/20170202(文件\u tiemstamp)
请注意,在上面的20170102(文件\u时间戳)中,是一个目录,而不是配置单元分区
或者,我可以控制拼花地板文件的名称,这样当我要删除文件名时,就可以很容易地确定要删除哪些文件
/home/dmarkovitz/myfiles下的文件
myfile_1_20161204.csv
20161204,1
20161203,2
myfile_2_20161205.csv
20161203,3
20161204,4
20161205,5
20161203,6
20161205,7
20161205,8
20161203,9
myfile_3_20161205.csv
20161203,3
20161204,4
20161205,5
20161203,6
20161205,7
20161205,8
20161203,9
蜂巢
create external table myfiles
(
Event_Time string
,AD_id int
)
row format delimited
fields terminated by ','
stored as textfile
location 'file:///home/dmarkovitz/myfiles'
;
{“input_tables”:[{“tablename”:“local”_db@mytable,“tabletype”:“MANAGED_TABLE”}],“input_partitions”:[{“partitionName”:“local”_db@mytable@文件_dt=2016-12-04/event_time=2016-12-04“},{“分区名称”:“本地”_db@mytable@文件\u dt=2016-12-05/事件\u时间=2016-12-04“}]}
bash
tree mytable
演示
/home/dmarkovitz/myfiles下的文件
myfile_1_20161204.csv
20161204,1
20161203,2
myfile_2_20161205.csv
20161203,3
20161204,4
20161205,5
20161203,6
20161205,7
20161205,8
20161203,9
myfile_3_20161205.csv
20161203,3
20161204,4
20161205,5
20161203,6
20161205,7
20161205,8
20161203,9
蜂巢
create external table myfiles
(
Event_Time string
,AD_id int
)
row format delimited
fields terminated by ','
stored as textfile
location 'file:///home/dmarkovitz/myfiles'
;
{“input_tables”:[{“tablename”:“local”_db@mytable,“tabletype”:“MANAGED_TABLE”}],“input_partitions”:[{“partitionName”:“local”_db@mytable@文件_dt=2016-12-04/event_time=2016-12-04“},{“分区名称”:“本地”_db@mytable@文件\u dt=2016-12-05/事件\u时间=2016-12-04“}]}
bash
tree mytable
您不使用日期ISO格式(yyyy-MM-dd)的任何原因?您不使用日期ISO格式(yyyy-MM-dd)的任何原因?感谢您花时间回答!感谢您花时间回答!
tree mytable
mytable
├── file_dt=2016-12-04
│ ├── event_time=2016-12-03
│ │ └── 000000_0
│ └── event_time=2016-12-04
│ └── 000000_0
└── file_dt=2016-12-05
├── event_time=2016-12-03
│ └── 000000_0
├── event_time=2016-12-04
│ └── 000000_0
└── event_time=2016-12-05
└── 000000_0