mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
143 lines
6.7 KiB
Markdown
143 lines
6.7 KiB
Markdown
Create a table in PostgreSQL:
|
|
|
|
```
|
|
CREATE TABLE hits_100m_pg
|
|
(
|
|
WatchID BIGINT NOT NULL,
|
|
JavaEnable SMALLINT NOT NULL,
|
|
Title TEXT NOT NULL,
|
|
GoodEvent SMALLINT NOT NULL,
|
|
EventTime TIMESTAMP NOT NULL,
|
|
EventDate Date NOT NULL,
|
|
CounterID INTEGER NOT NULL,
|
|
ClientIP INTEGER NOT NULL,
|
|
RegionID INTEGER NOT NULL,
|
|
UserID BIGINT NOT NULL,
|
|
CounterClass SMALLINT NOT NULL,
|
|
OS SMALLINT NOT NULL,
|
|
UserAgent SMALLINT NOT NULL,
|
|
URL TEXT NOT NULL,
|
|
Referer TEXT NOT NULL,
|
|
Refresh SMALLINT NOT NULL,
|
|
RefererCategoryID SMALLINT NOT NULL,
|
|
RefererRegionID INTEGER NOT NULL,
|
|
URLCategoryID SMALLINT NOT NULL,
|
|
URLRegionID INTEGER NOT NULL,
|
|
ResolutionWidth SMALLINT NOT NULL,
|
|
ResolutionHeight SMALLINT NOT NULL,
|
|
ResolutionDepth SMALLINT NOT NULL,
|
|
FlashMajor SMALLINT NOT NULL,
|
|
FlashMinor SMALLINT NOT NULL,
|
|
FlashMinor2 TEXT NOT NULL,
|
|
NetMajor SMALLINT NOT NULL,
|
|
NetMinor SMALLINT NOT NULL,
|
|
UserAgentMajor SMALLINT NOT NULL,
|
|
UserAgentMinor CHAR(2) NOT NULL,
|
|
CookieEnable SMALLINT NOT NULL,
|
|
JavascriptEnable SMALLINT NOT NULL,
|
|
IsMobile SMALLINT NOT NULL,
|
|
MobilePhone SMALLINT NOT NULL,
|
|
MobilePhoneModel TEXT NOT NULL,
|
|
Params TEXT NOT NULL,
|
|
IPNetworkID INTEGER NOT NULL,
|
|
TraficSourceID SMALLINT NOT NULL,
|
|
SearchEngineID SMALLINT NOT NULL,
|
|
SearchPhrase TEXT NOT NULL,
|
|
AdvEngineID SMALLINT NOT NULL,
|
|
IsArtifical SMALLINT NOT NULL,
|
|
WindowClientWidth SMALLINT NOT NULL,
|
|
WindowClientHeight SMALLINT NOT NULL,
|
|
ClientTimeZone SMALLINT NOT NULL,
|
|
ClientEventTime TIMESTAMP NOT NULL,
|
|
SilverlightVersion1 SMALLINT NOT NULL,
|
|
SilverlightVersion2 SMALLINT NOT NULL,
|
|
SilverlightVersion3 INTEGER NOT NULL,
|
|
SilverlightVersion4 SMALLINT NOT NULL,
|
|
PageCharset TEXT NOT NULL,
|
|
CodeVersion INTEGER NOT NULL,
|
|
IsLink SMALLINT NOT NULL,
|
|
IsDownload SMALLINT NOT NULL,
|
|
IsNotBounce SMALLINT NOT NULL,
|
|
FUniqID BIGINT NOT NULL,
|
|
OriginalURL TEXT NOT NULL,
|
|
HID INTEGER NOT NULL,
|
|
IsOldCounter SMALLINT NOT NULL,
|
|
IsEvent SMALLINT NOT NULL,
|
|
IsParameter SMALLINT NOT NULL,
|
|
DontCountHits SMALLINT NOT NULL,
|
|
WithHash SMALLINT NOT NULL,
|
|
HitColor CHAR NOT NULL,
|
|
LocalEventTime TIMESTAMP NOT NULL,
|
|
Age SMALLINT NOT NULL,
|
|
Sex SMALLINT NOT NULL,
|
|
Income SMALLINT NOT NULL,
|
|
Interests SMALLINT NOT NULL,
|
|
Robotness SMALLINT NOT NULL,
|
|
RemoteIP INTEGER NOT NULL,
|
|
WindowName INTEGER NOT NULL,
|
|
OpenerName INTEGER NOT NULL,
|
|
HistoryLength SMALLINT NOT NULL,
|
|
BrowserLanguage TEXT NOT NULL,
|
|
BrowserCountry TEXT NOT NULL,
|
|
SocialNetwork TEXT NOT NULL,
|
|
SocialAction TEXT NOT NULL,
|
|
HTTPError SMALLINT NOT NULL,
|
|
SendTiming INTEGER NOT NULL,
|
|
DNSTiming INTEGER NOT NULL,
|
|
ConnectTiming INTEGER NOT NULL,
|
|
ResponseStartTiming INTEGER NOT NULL,
|
|
ResponseEndTiming INTEGER NOT NULL,
|
|
FetchTiming INTEGER NOT NULL,
|
|
SocialSourceNetworkID SMALLINT NOT NULL,
|
|
SocialSourcePage TEXT NOT NULL,
|
|
ParamPrice BIGINT NOT NULL,
|
|
ParamOrderID TEXT NOT NULL,
|
|
ParamCurrency TEXT NOT NULL,
|
|
ParamCurrencyID SMALLINT NOT NULL,
|
|
OpenstatServiceName TEXT NOT NULL,
|
|
OpenstatCampaignID TEXT NOT NULL,
|
|
OpenstatAdID TEXT NOT NULL,
|
|
OpenstatSourceID TEXT NOT NULL,
|
|
UTMSource TEXT NOT NULL,
|
|
UTMMedium TEXT NOT NULL,
|
|
UTMCampaign TEXT NOT NULL,
|
|
UTMContent TEXT NOT NULL,
|
|
UTMTerm TEXT NOT NULL,
|
|
FromTag TEXT NOT NULL,
|
|
HasGCLID SMALLINT NOT NULL,
|
|
RefererHash BIGINT NOT NULL,
|
|
URLHash BIGINT NOT NULL,
|
|
CLID INTEGER NOT NULL
|
|
);
|
|
```
|
|
|
|
Create a dump from ClickHouse:
|
|
|
|
```
|
|
SELECT WatchID::Int64, JavaEnable, replaceAll(replaceAll(replaceAll(toValidUTF8(Title), '\0', ''), '"', ''), '\\', ''), GoodEvent, EventTime, EventDate, CounterID::Int32, ClientIP::Int32, RegionID::Int32,
|
|
UserID::Int64, CounterClass, OS, UserAgent, replaceAll(replaceAll(replaceAll(toValidUTF8(URL), '\0', ''), '"', ''), '\\', ''), replaceAll(replaceAll(replaceAll(toValidUTF8(Referer), '\0', ''), '"', ''), '\\', ''), Refresh, RefererCategoryID::Int16, RefererRegionID::Int32,
|
|
URLCategoryID::Int16, URLRegionID::Int32, ResolutionWidth::Int16, ResolutionHeight::Int16, ResolutionDepth, FlashMajor, FlashMinor,
|
|
FlashMinor2, NetMajor, NetMinor, UserAgentMajor::Int16, replaceAll(replaceAll(replaceAll(toValidUTF8(UserAgentMinor::String), '\0', ''), '"', ''), '\\', ''), CookieEnable, JavascriptEnable, IsMobile, MobilePhone,
|
|
replaceAll(replaceAll(replaceAll(toValidUTF8(MobilePhoneModel), '\0', ''), '"', ''), '\\', ''), replaceAll(replaceAll(replaceAll(toValidUTF8(Params), '\0', ''), '"', ''), '\\', ''), IPNetworkID::Int32, TraficSourceID, SearchEngineID::Int16, replaceAll(replaceAll(replaceAll(toValidUTF8(SearchPhrase), '\0', ''), '"', ''), '\\', ''),
|
|
AdvEngineID, IsArtifical, WindowClientWidth::Int16, WindowClientHeight::Int16, ClientTimeZone, ClientEventTime,
|
|
SilverlightVersion1, SilverlightVersion2, SilverlightVersion3::Int32, SilverlightVersion4::Int16, replaceAll(replaceAll(replaceAll(toValidUTF8(PageCharset), '\0', ''), '"', ''), '\\', ''),
|
|
CodeVersion::Int32, IsLink, IsDownload, IsNotBounce, FUniqID::Int64, replaceAll(replaceAll(replaceAll(toValidUTF8(OriginalURL), '\0', ''), '"', ''), '\\', ''), HID::Int32, IsOldCounter, IsEvent,
|
|
IsParameter, DontCountHits, WithHash, replaceAll(replaceAll(replaceAll(toValidUTF8(HitColor::String), '\0', ''), '"', ''), '\\', ''), LocalEventTime, Age, Sex, Income, Interests::Int16, Robotness, RemoteIP::Int32,
|
|
WindowName, OpenerName, HistoryLength, replaceAll(replaceAll(replaceAll(toValidUTF8(BrowserLanguage::String), '\0', ''), '"', ''), '\\', ''), replaceAll(replaceAll(replaceAll(toValidUTF8(BrowserCountry::String), '\0', ''), '"', ''), '\\', ''),
|
|
replaceAll(replaceAll(replaceAll(toValidUTF8(SocialNetwork), '\0', ''), '"', ''), '\\', ''), replaceAll(replaceAll(replaceAll(toValidUTF8(SocialAction), '\0', ''), '"', ''), '\\', ''),
|
|
HTTPError, least(SendTiming, 30000), least(DNSTiming, 30000), least(ConnectTiming, 30000), least(ResponseStartTiming, 30000),
|
|
least(ResponseEndTiming, 30000), least(FetchTiming, 30000), SocialSourceNetworkID,
|
|
replaceAll(replaceAll(replaceAll(toValidUTF8(SocialSourcePage), '\0', ''), '"', ''), '\\', ''), ParamPrice, replaceAll(replaceAll(replaceAll(toValidUTF8(ParamOrderID), '\0', ''), '"', ''), '\\', ''), replaceAll(replaceAll(replaceAll(toValidUTF8(ParamCurrency::String), '\0', ''), '"', ''), '\\', ''),
|
|
ParamCurrencyID::Int16, OpenstatServiceName, OpenstatCampaignID, OpenstatAdID, OpenstatSourceID,
|
|
UTMSource, UTMMedium, UTMCampaign, UTMContent, UTMTerm, FromTag, HasGCLID, RefererHash::Int64, URLHash::Int64, CLID::Int32
|
|
FROM hits_100m_obfuscated
|
|
INTO OUTFILE 'dump.tsv'
|
|
FORMAT TSV
|
|
```
|
|
|
|
Insert data into PostgreSQL:
|
|
|
|
```
|
|
\copy hits_100m_pg FROM 'dump.tsv';
|
|
```
|