2022-02-18 16:37:24 +00:00
|
|
|
<test>
|
|
|
|
<query>
|
|
|
|
SELECT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
RegionID,
|
|
|
|
toDateTime(EventDate) AS date,
|
|
|
|
count() AS quantity
|
|
|
|
FROM test.hits
|
|
|
|
GROUP BY
|
|
|
|
RegionID,
|
|
|
|
date
|
|
|
|
) AS regions
|
|
|
|
ASOF LEFT JOIN
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
RegionID,
|
|
|
|
EventTime
|
|
|
|
FROM test.hits
|
|
|
|
) AS ids ON (regions.RegionID = ids.RegionID) AND (regions.date < ids.EventTime)
|
|
|
|
</query>
|
|
|
|
|
2022-03-17 18:48:25 +00:00
|
|
|
<query>
|
|
|
|
SELECT * FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
toStartOfDay(now()) + INTERVAL (seconds_since_start_of_day % 86000) SECOND AS date,
|
|
|
|
fingerprint % 50 as fingerprint,
|
|
|
|
multiIf(browserId % 3 == 0, 'firefox', browserId % 3 == 1, 'edge', 'chrome') as browser
|
|
|
|
FROM generateRandom('seconds_since_start_of_day UInt32, fingerprint UInt8, browserId UInt8') LIMIT 100000
|
|
|
|
) AS origins
|
|
|
|
ASOF LEFT JOIN
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
toStartOfDay(now()) + INTERVAL (seconds_since_start_of_day % 86000) SECOND AS date,
|
|
|
|
fingerprint % 50 as fingerprint,
|
|
|
|
multiIf(language % 2 == 0, 'es', 'en') as lang
|
|
|
|
FROM generateRandom('seconds_since_start_of_day UInt32, fingerprint UInt8, language UInt8') LIMIT 5000000
|
|
|
|
) AS visits
|
|
|
|
ON (visits.fingerprint = origins.fingerprint AND visits.date >= origins.date)
|
|
|
|
FORMAT Null
|
|
|
|
</query>
|
2023-03-18 22:53:00 +00:00
|
|
|
|
|
|
|
<substitutions>
|
2024-02-07 17:31:53 +00:00
|
|
|
<substitution>
|
|
|
|
<name>num_unique_sessions</name>
|
|
|
|
<values>
|
|
|
|
<value>1000</value>
|
|
|
|
<value>1000000</value>
|
|
|
|
</values>
|
|
|
|
</substitution>
|
2023-03-18 22:53:00 +00:00
|
|
|
<substitution>
|
|
|
|
<name>num_rows</name>
|
|
|
|
<values>
|
|
|
|
<value>1000000</value>
|
|
|
|
</values>
|
|
|
|
</substitution>
|
|
|
|
</substitutions>
|
|
|
|
|
|
|
|
<query>
|
|
|
|
SELECT COUNT(*) AS count
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
2024-02-07 17:31:53 +00:00
|
|
|
(number % {num_unique_sessions}) AS visitor_id,
|
2024-02-08 17:29:47 +00:00
|
|
|
number AS id
|
2023-03-18 22:53:00 +00:00
|
|
|
FROM system.numbers
|
|
|
|
LIMIT {num_rows}
|
|
|
|
) AS sessions
|
|
|
|
ASOF LEFT JOIN
|
|
|
|
(
|
|
|
|
SELECT
|
2024-02-07 17:31:53 +00:00
|
|
|
(number % {num_unique_sessions}) AS visitor_id,
|
2023-03-18 22:53:00 +00:00
|
|
|
number AS starting_session_id
|
|
|
|
FROM system.numbers
|
|
|
|
LIMIT {num_rows}
|
|
|
|
) AS visitors
|
|
|
|
ON visitors.visitor_id = sessions.visitor_id AND visitors.starting_session_id < sessions.id
|
|
|
|
</query>
|
2022-02-18 16:37:24 +00:00
|
|
|
</test>
|