aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/s-expressions/suites/ManyYamrOperations/Bug1465.sql
blob: f8488fb2e1dc46bd4b03a3ad9f8cde216da43700 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
USE hahn;

$minus_date = Python::minus_date(
    @@(String?,String?)->Int64@@,
    @@
from datetime import datetime, timedelta
def minus_date(date1, date2):
    return (datetime.strptime(date1, "%Y-%m-%d") - datetime.strptime(date2, "%Y-%m-%d")).days
    @@
);

$normalize_list = Python::normalize_list(
    @@(List<Tuple<Int64,Int64?>>)->List<Tuple<Int64,Int64>>@@,
    @@
def normalize_list(values):
    return sorted((x, y) for x, y in values if y)
    @@
);

$urls = (
FROM hits
SELECT url AS Url, "2016-10-25" AS Date
GROUP BY url
);

$flatten_factors = (
FROM $urls AS target
INNER JOIN hits AS history
ON target.Url == history.url
SELECT
    target.Url AS Url,
    target.Date AS Date,
    history.*
);

INSERT INTO [Out1] WITH TRUNCATE FROM $flatten_factors SELECT *;
COMMIT;

$pool = (
FROM [Out1]
SELECT
    Url,
    Date,
    Url::GetHost(Url) AS Host
/*    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_all_total]))) AS metrika_all_total
/*    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.yabro_mobile_unique]))) AS yabro_mobile_unique,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_counter_count]))) AS metrika_counter_count,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_yabro_desktop_total]))) AS metrika_yabro_desktop_total,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_yabro_desktop_unique]))) AS metrika_yabro_desktop_unique,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_all_unique]))) AS metrika_all_unique,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_yabro_mobile_unique]))) AS metrika_yabro_mobile_unique,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.yabro_desktop_total]))) AS yabro_desktop_total,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.yabro_desktop_unique]))) AS yabro_desktop_unique,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.yabro_mobile_total]))) AS yabro_mobile_total,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.metrika_yabro_mobile_total]))) AS metrika_yabro_mobile_total,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.cs_clicks]))) AS cs_clicks,
    $normalize_list(LIST(($minus_date(Date, [history.date]), [history.cs_shows]))) AS cs_shows*/
GROUP BY Url, Date
);

$hosts = (
FROM $pool
SELECT Host, "2016-10-25" AS Date
GROUP BY Host
);

$host_features = (
FROM $hosts AS hosts
LEFT JOIN hits AS all_hits
ON hosts.Host == Url::GetHost(all_hits.url)
SELECT
    hosts.Host AS Host,
    hosts.Date AS Date,
/*    SUM(all_hits.metrika_all_total) AS metrika_all_total_sum7,
/*    MAX(all_hits.metrika_all_total) AS metrika_all_total_max7,
--     STDDEV(all_hits.metrika_all_total) AS metrika_all_total_stddev7,
    MEDIAN(all_hits.metrika_all_total) AS metrika_all_total_median7,
    PERCENTILE(all_hits.metrika_all_total, 0.25) AS metrika_all_total_25perc7,
    PERCENTILE(all_hits.metrika_all_total, 0.75) AS metrika_all_total_75perc7,
    COUNT_IF(all_hits.metrika_all_total > 0) AS metrika_all_total_nonzero7,
    SUM(all_hits.yabro_mobile_unique) AS yabro_mobile_unique_sum7,
    MAX(all_hits.yabro_mobile_unique) AS yabro_mobile_unique_max7,
--     STDDEV(all_hits.yabro_mobile_unique) AS yabro_mobile_unique_stddev7,
    MEDIAN(all_hits.yabro_mobile_unique) AS yabro_mobile_unique_median7,
    PERCENTILE(all_hits.yabro_mobile_unique, 0.25) AS yabro_mobile_unique_25perc7,
    PERCENTILE(all_hits.yabro_mobile_unique, 0.75) AS yabro_mobile_unique_75perc7,
    COUNT_IF(all_hits.yabro_mobile_unique > 0) AS yabro_mobile_unique_nonzero7,
    SUM(all_hits.metrika_counter_count) AS metrika_counter_count_sum7,
    MAX(all_hits.metrika_counter_count) AS metrika_counter_count_max7,
--     STDDEV(all_hits.metrika_counter_count) AS metrika_counter_count_stddev7,
    MEDIAN(all_hits.metrika_counter_count) AS metrika_counter_count_median7,
    PERCENTILE(all_hits.metrika_counter_count, 0.25) AS metrika_counter_count_25perc7,
    PERCENTILE(all_hits.metrika_counter_count, 0.75) AS metrika_counter_count_75perc7,
    COUNT_IF(all_hits.metrika_counter_count > 0) AS metrika_counter_count_nonzero7,
    SUM(all_hits.metrika_yabro_desktop_total) AS metrika_yabro_desktop_total_sum7,
    MAX(all_hits.metrika_yabro_desktop_total) AS metrika_yabro_desktop_total_max7,
--     STDDEV(all_hits.metrika_yabro_desktop_total) AS metrika_yabro_desktop_total_stddev7,
    MEDIAN(all_hits.metrika_yabro_desktop_total) AS metrika_yabro_desktop_total_median7,
    PERCENTILE(all_hits.metrika_yabro_desktop_total, 0.25) AS metrika_yabro_desktop_total_25perc7,
    PERCENTILE(all_hits.metrika_yabro_desktop_total, 0.75) AS metrika_yabro_desktop_total_75perc7,
    COUNT_IF(all_hits.metrika_yabro_desktop_total > 0) AS metrika_yabro_desktop_total_nonzero7,
    SUM(all_hits.metrika_yabro_desktop_unique) AS metrika_yabro_desktop_unique_sum7,
    MAX(all_hits.metrika_yabro_desktop_unique) AS metrika_yabro_desktop_unique_max7,
--     STDDEV(all_hits.metrika_yabro_desktop_unique) AS metrika_yabro_desktop_unique_stddev7,
    MEDIAN(all_hits.metrika_yabro_desktop_unique) AS metrika_yabro_desktop_unique_median7,
    PERCENTILE(all_hits.metrika_yabro_desktop_unique, 0.25) AS metrika_yabro_desktop_unique_25perc7,
    PERCENTILE(all_hits.metrika_yabro_desktop_unique, 0.75) AS metrika_yabro_desktop_unique_75perc7,
    COUNT_IF(all_hits.metrika_yabro_desktop_unique > 0) AS metrika_yabro_desktop_unique_nonzero7,
    SUM(all_hits.metrika_all_unique) AS metrika_all_unique_sum7,
    MAX(all_hits.metrika_all_unique) AS metrika_all_unique_max7,
--     STDDEV(all_hits.metrika_all_unique) AS metrika_all_unique_stddev7,
    MEDIAN(all_hits.metrika_all_unique) AS metrika_all_unique_median7,
    PERCENTILE(all_hits.metrika_all_unique, 0.25) AS metrika_all_unique_25perc7,
    PERCENTILE(all_hits.metrika_all_unique, 0.75) AS metrika_all_unique_75perc7,
    COUNT_IF(all_hits.metrika_all_unique > 0) AS metrika_all_unique_nonzero7,
    SUM(all_hits.metrika_yabro_mobile_unique) AS metrika_yabro_mobile_unique_sum7,
    MAX(all_hits.metrika_yabro_mobile_unique) AS metrika_yabro_mobile_unique_max7,
--     STDDEV(all_hits.metrika_yabro_mobile_unique) AS metrika_yabro_mobile_unique_stddev7,
    MEDIAN(all_hits.metrika_yabro_mobile_unique) AS metrika_yabro_mobile_unique_median7,
    PERCENTILE(all_hits.metrika_yabro_mobile_unique, 0.25) AS metrika_yabro_mobile_unique_25perc7,
    PERCENTILE(all_hits.metrika_yabro_mobile_unique, 0.75) AS metrika_yabro_mobile_unique_75perc7,
    COUNT_IF(all_hits.metrika_yabro_mobile_unique > 0) AS metrika_yabro_mobile_unique_nonzero7,
    SUM(all_hits.yabro_desktop_total) AS yabro_desktop_total_sum7,
    MAX(all_hits.yabro_desktop_total) AS yabro_desktop_total_max7,
--     STDDEV(all_hits.yabro_desktop_total) AS yabro_desktop_total_stddev7,
    MEDIAN(all_hits.yabro_desktop_total) AS yabro_desktop_total_median7,
    PERCENTILE(all_hits.yabro_desktop_total, 0.25) AS yabro_desktop_total_25perc7,
    PERCENTILE(all_hits.yabro_desktop_total, 0.75) AS yabro_desktop_total_75perc7,
    COUNT_IF(all_hits.yabro_desktop_total > 0) AS yabro_desktop_total_nonzero7,
    SUM(all_hits.yabro_desktop_unique) AS yabro_desktop_unique_sum7,
    MAX(all_hits.yabro_desktop_unique) AS yabro_desktop_unique_max7,
--     STDDEV(all_hits.yabro_desktop_unique) AS yabro_desktop_unique_stddev7,
    MEDIAN(all_hits.yabro_desktop_unique) AS yabro_desktop_unique_median7,
    PERCENTILE(all_hits.yabro_desktop_unique, 0.25) AS yabro_desktop_unique_25perc7,
    PERCENTILE(all_hits.yabro_desktop_unique, 0.75) AS yabro_desktop_unique_75perc7,
    COUNT_IF(all_hits.yabro_desktop_unique > 0) AS yabro_desktop_unique_nonzero7,
    SUM(all_hits.yabro_mobile_total) AS yabro_mobile_total_sum7,
    MAX(all_hits.yabro_mobile_total) AS yabro_mobile_total_max7,
--     STDDEV(all_hits.yabro_mobile_total) AS yabro_mobile_total_stddev7,
    MEDIAN(all_hits.yabro_mobile_total) AS yabro_mobile_total_median7,
    PERCENTILE(all_hits.yabro_mobile_total, 0.25) AS yabro_mobile_total_25perc7,
    PERCENTILE(all_hits.yabro_mobile_total, 0.75) AS yabro_mobile_total_75perc7,
    COUNT_IF(all_hits.yabro_mobile_total > 0) AS yabro_mobile_total_nonzero7,
    SUM(all_hits.metrika_yabro_mobile_total) AS metrika_yabro_mobile_total_sum7,
    MAX(all_hits.metrika_yabro_mobile_total) AS metrika_yabro_mobile_total_max7,
--     STDDEV(all_hits.metrika_yabro_mobile_total) AS metrika_yabro_mobile_total_stddev7,
    MEDIAN(all_hits.metrika_yabro_mobile_total) AS metrika_yabro_mobile_total_median7,
    PERCENTILE(all_hits.metrika_yabro_mobile_total, 0.25) AS metrika_yabro_mobile_total_25perc7,
    PERCENTILE(all_hits.metrika_yabro_mobile_total, 0.75) AS metrika_yabro_mobile_total_75perc7,
    COUNT_IF(all_hits.metrika_yabro_mobile_total > 0) AS metrika_yabro_mobile_total_nonzero7,*/
    COUNT(*) AS url_day_count,
    COUNT(DISTINCT(all_hits.url)) AS url_count
GROUP BY hosts.Host, hosts.Date
);

INSERT INTO [Out2] WITH TRUNCATE
FROM $pool AS pool
LEFT JOIN $host_features AS host
ON Url::GetHost(pool.Url) == host.Host AND pool.Date == host.Date
SELECT *;
/*    pool.Date AS Date,
    pool.yabro_mobile_unique AS yabro_mobile_unique,
    pool.Url AS Url,
    pool.cs_clicks AS cs_clicks,
    pool.cs_shows AS cs_shows,
    pool.metrika_all_total AS metrika_all_total,
    pool.metrika_all_unique AS metrika_all_unique,
    pool.Host AS Host,
    pool.metrika_yabro_desktop_total AS metrika_yabro_desktop_total,
    pool.metrika_yabro_desktop_unique AS metrika_yabro_desktop_unique,
    pool.metrika_yabro_mobile_total AS metrika_yabro_mobile_total,
    pool.metrika_yabro_mobile_unique AS metrika_yabro_mobile_unique,
    pool.yabro_desktop_total AS yabro_desktop_total,
    pool.yabro_desktop_unique AS yabro_desktop_unique,
    pool.yabro_mobile_total AS yabro_mobile_total,
    pool.metrika_counter_count AS metrika_counter_count,
    host.*;*/

COMMIT;
DROP TABLE [Out1];