配置单元:查询中不显示任何结果

olhwl3o2  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(365)

我正在这个表上写一个查询,以获得所有目录的大小之和,按日期为昨天的目录分组。下面的查询没有输出。

test.id        test.path           test.size     test.date
1   this/is/the/path1/fil.txt      232.24           2019-06-01
2   this/is/the/path2/test.txt     324.0            2016-06-01
3   this/is/the/path3/index.txt    12.3             2017-05-01
4   this/is/the/path4/test2.txt    134.0            2019-03-23
5   this/is/the/path1/files.json   2.23             2018-07-23
6   this/is/the/path1/code.java    1.34             2014-03-23
7   this/is/the/path2/data.csv     23.42            2016-06-23
8   this/is/the/path3/test.html    1.33             2018-09-23
9   this/is/the/path4/prog.js      6.356            2019-06-23
4   this/is/the/path4/test2.txt    134.0            2019-04-23
SELECT regexp_replace(path,'[^/]+$',''), sum(cast(size as decimal)) 
from test WHERE date > date_sub(current_date, 1) GROUP BY path,size;
kpbwa7wx

kpbwa7wx1#

你可能想要 WHERE date >= '2019-01-01' . 使用 % 在匹配字符串中,例如 2019% ,只适用于like,不适用于不等式匹配。
您给出的示例似乎希望在2019日历年中包含所有行。
昨天,你想要什么

WHERE date >= DATE_SUB(current_date, -1)
    AND date < current_date

即使你的 date 列包含时间戳。

i7uaboj4

i7uaboj42#

你不能这样 group by size ,仅限 regexp_replace(path,'[^/]+$','') .
还有,既然你只想要昨天的那一行,为什么要用 WHERE date > '2019% ?
你可以和我订昨天的约会 date_sub(current_date, 1) :

select 
  regexp_replace(path,'[^/]+$',''), 
  sum(cast(size as decimal)) 
from test 
where date = date_sub(current_date, 1) 
group by regexp_replace(path,'[^/]+$','');

相关问题