首先,Hive事务表所产生的的路径信息如下:
PS:其中路径信息格式为
/user/hive/warehouse/${database_name}.db/${table_name}/*
/user/hive/warehouse/test.db/tran_ts/delete_delta_0000002_0000002_0000
/user/hive/warehouse/test.db/tran_ts/delta_0000001_0000001_0000
/user/hive/warehouse/test.db/tran_ts/delta_0000002_0000002_0000
然后,需求为:我们需要分库表统计目录数量。
接下来,拆分需求:
因为hive没有获取第几个字符的相关UDF函数,所以只能通过多个函数组合的方式进行处理。结果如下:
select location,
substr(location, 1, length(location) - length(split(reverse(location), '/')[0]) - 1) as db_table_path,
reverse(split(reverse(location), '/')[0]) as last_subpath_name
from
(
select "/user/hive/warehouse/test.db/tran_ts/delete_delta_0000002_0000002_0000" as location
) t

解析: