环境:
centos 6.3,32G内存,24核
下载脚本:
#!/bin/bash for s in `seq 1987 2017` do for m in `seq 1 12` do mwget -n 128 http://transtats.bts.gov/PREZIP/On_Time_On_Time_Performance_${s}_${m}.zip done done
这里采用的是mwget,128个线程,mwget是wget的多线程版本。wget太慢了。关于mwget的安装,请参考:https://my.oschina.net/766/blog/156807
下载以后的数据是zip压缩包,如下:
下载完数据以后建表:
客户端登录: clickhouse-client -m,如果不加-m启用多行,那么将会报错:
View Code
导入数据:
for i in *.zip; do echo $i; unzip -cq $i '*.csv' | sed 's/.00//g' | clickhouse-client --query="INSERT INTO ontime FORMAT CSVWithNames"; done
开始查询测试:
可以看见1.7亿数据,count用了0.034秒,当然列存储数据库count都不快还搞毛。
继续测试其他的语句
从2000年到2016年每天的航班统计
SELECT DayOfWeek, count(*) AS c FROM ontime WHERE Year >= 2000 AND Year <= 2016 GROUP BY DayOfWeek ORDER BY c DESC;
2000 - 2008年度机场延误数
SELECT Origin, count(*) AS c FROM ontime WHERE DepDelay>10 AND Year >= 2000 AND Year <= 2008 GROUP BY Origin ORDER BY c DESC LIMIT 10
这些查询都有一个范围限制,那么全部查完呢?
比如:
SELECT OriginCityName, DestCityName, count() AS c FROM ontime GROUP BY OriginCityName, DestCityName ORDER BY c DESC LIMIT 10;
可以看见依然快的不像话,哈哈。心动了没?心动了就动手安装,导入数据测试一下吧。
参考资料:
https://raw.githubusercontent.com/yandex/ClickHouse/master/doc/example_datasets/1_ontime.txt