创建行满足条件的 Impala 文本 table

Create an Impala text table where rows meet a condition

我正在尝试在 Impala (SQL) 中创建一个 table,它从镶木地板 table 中获取行。数据表示城市中的自行车骑行情况。如果起始代码(字符串,例如:'6100')在第一个 table 中出现超过 100 次,行将被导入到新的 table 中。这是我目前所拥有的:

#I am using Apache Impala via the Hue Editor

invalidate metadata;
set compression_codec=none;

invalidate metadata;
Set compression_codec=gzip;

create table bixirides_parquet (
start_date string, start_station_code string, 
end_date string, end_station_code string, 
duration_sec int, is_member int)
stored as parquet;


Insert overwrite table bixirides_parquet select * from bixirides_avro;


invalidate metadata;
set compression_codec=none;

create table impala_out stored as textfile as select start_date, start_station_code, end_date, end_station_code, duration_sec, is_member, count(start_station_code) as count
from bixirides_parquet
having count(start_station_code)>100;

出于某种原因,该语句将 运行,但不会在新的 table 中插入任何行。如果该行起始代码在原始 table 中出现超过 100 次,它应该将一行导入新的 table。我认为我的 select 声明措辞不当,但我不确定具体情况如何。

我认为你想要的最终查询是:

select start_date, start_station_code, end_date, 
       end_station_code, duration_sec, is_member, cnt
from (select bp.*,
             count(*) over (partition by start_station_code) as cnt
      from bixirides_parquet bp
     ) bp
where cnt > 100;