ClickHouse数据导入
参照ClickHouse官方教程来导入样本数据:
下载样本数据
curl https://clickhouse-datasets.s3.yandex.net/hits/tsv/hits_v1.tsv.xz | unxz --threads=`nproc` > hits_v1.tsv
curl https://clickhouse-datasets.s3.yandex.net/visits/tsv/visits_v1.tsv.xz | unxz --threads=`nproc` > visits_v1.tsv
其中,hits_v1.tsv约7.3G,visits_v1.tsv约2.5G。
创建数据库
-- 创建数据库
create database if not exists tutorial
-- 查看数据库
show databases
-- 切换数据库
use tutorial
创建数据表
因为官方文档中的建表语句有换行,因此需要在文本编辑器中先在每行末尾添加
\
,再复制到clickhouse-client执行,。VS Code在每行末尾添加
\
的做法:
打开VS Code,复制粘贴内容到一个新的文件中。
按下
Alt
+Command
+F
,选中Use Regular Expression,将\n
替换为\ \n
。
创建hits_v1表:
CREATE TABLE tutorial.hits_v1 \
( \
`WatchID` UInt64, \
`JavaEnable` UInt8, \
`Title` String, \
`GoodEvent` Int16, \
`EventTime` DateTime, \
`EventDate` Date, \
`CounterID` UInt32, \
`ClientIP` UInt32, \
`ClientIP6` FixedString(16), \
`RegionID` UInt32, \
`UserID` UInt64, \
`CounterClass` Int8, \
`OS` UInt8, \
`UserAgent` UInt8, \
`URL` String, \
`Referer` String, \
`URLDomain` String, \
`RefererDomain` String, \
`Refresh` UInt8, \
`IsRobot` UInt8, \
`RefererCategories` Array(UInt16), \
`URLCategories` Array(UInt16), \
`URLRegions` Array(UInt32), \
`RefererRegions` Array(UInt32), \
`ResolutionWidth` UInt16, \
`ResolutionHeight` UInt16, \
`ResolutionDepth` UInt8, \
`FlashMajor` UInt8, \
`FlashMinor` UInt8, \
`FlashMinor2` String, \
`NetMajor` UInt8, \
`NetMinor` UInt8, \
`UserAgentMajor` UInt16, \
`UserAgentMinor` FixedString(2), \
`CookieEnable` UInt8, \
`JavascriptEnable` UInt8, \
`IsMobile` UInt8, \
`MobilePhone` UInt8, \
`MobilePhoneModel` String, \
`Params` String, \
`IPNetworkID` UInt32, \
`TraficSourceID` Int8, \
`SearchEngineID` UInt16, \
`SearchPhrase` String, \
`AdvEngineID` UInt8, \
`IsArtifical` UInt8, \
`WindowClientWidth` UInt16, \
`WindowClientHeight` UInt16, \
`ClientTimeZone` Int16, \
`ClientEventTime` DateTime, \
`SilverlightVersion1` UInt8, \
`SilverlightVersion2` UInt8, \
`SilverlightVersion3` UInt32, \
`SilverlightVersion4` UInt16, \
`PageCharset` String, \
`CodeVersion` UInt32, \
`IsLink` UInt8, \
`IsDownload` UInt8, \
`IsNotBounce` UInt8, \
`FUniqID` UInt64, \
`HID` UInt32, \
`IsOldCounter` UInt8, \
`IsEvent` UInt8, \
`IsParameter` UInt8, \
`DontCountHits` UInt8, \
`WithHash` UInt8