-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hogql): basic pretty print (#18086)
- Loading branch information
1 parent
360957f
commit 2a4bd69
Showing
3 changed files
with
218 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# name: TestPrinter.test_large_pretty_print | ||
' | ||
SELECT | ||
groupArray(start_of_period) AS date, | ||
groupArray(counts) AS total, | ||
status | ||
FROM | ||
(SELECT | ||
if(equals(status, 'dormant'), negate(sum(counts)), negate(negate(sum(counts)))) AS counts, | ||
start_of_period, | ||
status | ||
FROM | ||
(SELECT | ||
periods.start_of_period AS start_of_period, | ||
0 AS counts, | ||
status | ||
FROM | ||
(SELECT | ||
minus(dateTrunc('day', assumeNotNull(toDateTime('2023-10-19 23:59:59'))), toIntervalDay(number)) AS start_of_period | ||
FROM | ||
numbers(dateDiff('day', dateTrunc('day', assumeNotNull(toDateTime('2023-09-19 00:00:00'))), dateTrunc('day', plus(assumeNotNull(toDateTime('2023-10-19 23:59:59')), toIntervalDay(1))))) AS numbers) AS periods CROSS JOIN (SELECT | ||
status | ||
FROM | ||
(SELECT | ||
1) | ||
ARRAY JOIN ['new', 'returning', 'resurrecting', 'dormant'] AS status) AS sec | ||
ORDER BY | ||
status ASC, | ||
start_of_period ASC | ||
UNION ALL | ||
SELECT | ||
start_of_period, | ||
count(DISTINCT person_id) AS counts, | ||
status | ||
FROM | ||
(SELECT | ||
events.person.id AS person_id, | ||
min(events.person.created_at) AS created_at, | ||
arraySort(groupUniqArray(dateTrunc('day', events.timestamp))) AS all_activity, | ||
arrayPopBack(arrayPushFront(all_activity, dateTrunc('day', created_at))) AS previous_activity, | ||
arrayPopFront(arrayPushBack(all_activity, dateTrunc('day', toDateTime('1970-01-01 00:00:00')))) AS following_activity, | ||
arrayMap((previous, current, index) -> if(equals(previous, current), 'new', if(and(equals(minus(current, toIntervalDay(1)), previous), notEquals(index, 1)), 'returning', 'resurrecting')), previous_activity, all_activity, arrayEnumerate(all_activity)) AS initial_status, | ||
arrayMap((current, next) -> if(equals(plus(current, toIntervalDay(1)), next), '', 'dormant'), all_activity, following_activity) AS dormant_status, | ||
arrayMap(x -> plus(x, toIntervalDay(1)), arrayFilter((current, is_dormant) -> equals(is_dormant, 'dormant'), all_activity, dormant_status)) AS dormant_periods, | ||
arrayMap(x -> 'dormant', dormant_periods) AS dormant_label, | ||
arrayConcat(arrayZip(all_activity, initial_status), arrayZip(dormant_periods, dormant_label)) AS temp_concat, | ||
arrayJoin(temp_concat) AS period_status_pairs, | ||
period_status_pairs.1 AS start_of_period, | ||
period_status_pairs.2 AS status | ||
FROM | ||
events | ||
WHERE | ||
and(greaterOrEquals(timestamp, minus(dateTrunc('day', assumeNotNull(toDateTime('2023-09-19 00:00:00'))), toIntervalDay(1))), less(timestamp, plus(dateTrunc('day', assumeNotNull(toDateTime('2023-10-19 23:59:59'))), toIntervalDay(1))), equals(event, '$pageview')) | ||
GROUP BY | ||
person_id) | ||
GROUP BY | ||
start_of_period, | ||
status) | ||
WHERE | ||
and(lessOrEquals(start_of_period, dateTrunc('day', assumeNotNull(toDateTime('2023-10-19 23:59:59')))), greaterOrEquals(start_of_period, dateTrunc('day', assumeNotNull(toDateTime('2023-09-19 00:00:00'))))) | ||
GROUP BY | ||
start_of_period, | ||
status | ||
ORDER BY | ||
start_of_period ASC) | ||
GROUP BY | ||
status | ||
LIMIT 10000 | ||
' | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters