配置单元查询语法

0s7z1bwu  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(273)

我是新来的配置单元,请帮助语法..下面是表logstash中的2列(filepath,filesize(bytes))。。。。

/bns/ghi/cod/cob_def/abc                        | 10600
/sandbox/abc/def/xyz/ade                        | 1062659
/data/def/cag/tyz/gj/ibs                        | 457869
/tmp/cdb/def/ghik/new_data/2018-08-17           | 14565
/data/abc/def/ghi/new_data                      | 56453

我能够得到的总和文件大小到第一级,。。。。
类似地,如何提取第二级例如:(/data/,/bns/ghi,/tmp/cbd)例如;如果/data是100gb,我需要知道/data里面有什么,比如/data/def=20gb/data/efg=20gb。。。和类似的第三级


**select substr(filepathpath, 2, instr(substr(filepath,2), '/')-2) zone, 

   sum(filesize)from logstash group by substr(filepath, 2, instr(substr(filepath,2), '/')-2)**
qf9go6mv

qf9go6mv1#

@用户9314128;请尝试以下查询:希望对您有所帮助。谢谢

select filepath
,sum(filesize) as sumfilesize
from logstash 
where length(regexp_replace(filepath,'[^/]','')) = 1
group by filepath;

第二级;将where子句从=1改为=2

bfnvny8b

bfnvny8b2#

使用拆分和合并
1级

select split(filepath, '/')[0] as 1_level_path,filesize from logstash;

文件大小总和为1级。

select split(filepath, '/')[0] as 1_level_path,SUM(filesize) 
from logstash
group by split(filepath, '/')[0] ;

2级

select CONCAT_WS('/',split(filepath, '/')[0],split(filepath, '/')[1]),filesize from logstash;

3级

select CONCAT_WS('/',CONCAT_WS('/',split(filepath, '/')[0],split(filepath, '/')[1]),split(filepath, '/')[2])),filesize from logstash

相关问题