Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(hogql): Add retention queries in HogQL #18831

Merged
merged 60 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
51bdfd0
Set up retention query runnner
webjunkie Nov 21, 2023
d7d7c3f
Adjust date ranges
webjunkie Nov 22, 2023
53fb2cf
Fix date logic
webjunkie Nov 22, 2023
ebfb46c
Use and adapt existing code
webjunkie Nov 24, 2023
a9de5cc
Clean up use of properties and filters
webjunkie Nov 24, 2023
d035528
Streamline things by using HogQL AST
webjunkie Nov 28, 2023
bffc6e2
Add existing tests and adapt them
webjunkie Nov 28, 2023
c56b5fb
Adjust query date range
webjunkie Nov 29, 2023
8c06ef9
Adjust schema, remove alias
webjunkie Nov 29, 2023
594ee7a
Remove reliance on old filter
webjunkie Nov 29, 2023
2a4fcdc
Clean up
webjunkie Nov 29, 2023
b98d0e0
Merge branch 'master' into chore/hogql-retention
webjunkie Nov 30, 2023
fe4d1d8
Use more AST and clean up
webjunkie Nov 30, 2023
19413c3
Add feature flag for insights retention to frontend
webjunkie Dec 1, 2023
bece900
Clean up date filter
webjunkie Dec 1, 2023
4f08651
Make more tests work
webjunkie Dec 1, 2023
e6b7005
Make 100% of tests pass
webjunkie Dec 1, 2023
65f24f4
Remove use of old mixin
webjunkie Dec 1, 2023
67234a3
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 1, 2023
38af739
Add more types
webjunkie Dec 1, 2023
f47a920
Remove people_url from result
webjunkie Dec 1, 2023
7059ca8
Fix lifecycle timezone test
webjunkie Dec 1, 2023
22be1ce
Refactor self.event_query_type
webjunkie Dec 4, 2023
e0ccba4
Refactor
webjunkie Dec 4, 2023
55c7f08
Merge branch 'master' into chore/hogql-retention
webjunkie Dec 4, 2023
5076505
Fix types
webjunkie Dec 4, 2023
11cfaac
Update query snapshots
github-actions[bot] Dec 4, 2023
670fdba
Fix tests
webjunkie Dec 4, 2023
c3a117a
Fix tests
webjunkie Dec 4, 2023
5eb60e4
Move entity_to_expr
webjunkie Dec 4, 2023
59d9d69
Fix frontent type errors
webjunkie Dec 5, 2023
c95dee9
Fix test
webjunkie Dec 5, 2023
6bfa0d4
Add tests for QueryDateRangeWithIntervals
webjunkie Dec 5, 2023
3171d19
Add entity_to_expr tests
webjunkie Dec 5, 2023
e29e747
Change type to interface
webjunkie Dec 5, 2023
b0f8497
Make select query via AST
webjunkie Dec 5, 2023
e2e0fe5
Clean up use of returning and target entity
webjunkie Dec 5, 2023
c53639c
Add RetentionEntity type
webjunkie Dec 5, 2023
ec2f356
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 5, 2023
add7884
Fix regressions coming from putting more types 😭
webjunkie Dec 6, 2023
a8eb623
Merge branch 'master' into chore/hogql-retention
webjunkie Dec 6, 2023
7dbf660
Revert timezone stuff after merge
webjunkie Dec 6, 2023
dbb8f26
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
83dbf7e
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 6, 2023
cc72886
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
c6c8ce5
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 6, 2023
4cf65bd
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
e331782
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
02180eb
Merge branch 'master' into chore/hogql-retention
webjunkie Dec 6, 2023
fa20f1d
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
120b0bc
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
c943cab
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
3bcffbc
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
95930d9
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
226f3f2
Merge branch 'master' into chore/hogql-retention
webjunkie Dec 6, 2023
5d3ea7b
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 6, 2023
9c5e75e
Update UI snapshots for `chromium` (1)
github-actions[bot] Dec 6, 2023
8ec4112
Update UI snapshots for `chromium` (2)
github-actions[bot] Dec 6, 2023
55a8199
Merge branch 'master' into chore/hogql-retention
webjunkie Dec 6, 2023
2cb2e70
Fix type issues
webjunkie Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,7 @@
"type": "object"
},
"total_intervals": {
"type": "number"
"type": "integer"
}
},
"type": "object"
Expand Down Expand Up @@ -2560,6 +2560,9 @@
],
"description": "Property filters for all series"
},
"response": {
"$ref": "#/definitions/RetentionQueryResponse"
},
"retentionFilter": {
"$ref": "#/definitions/RetentionFilter",
"description": "Properties specific to the retention insight"
Expand All @@ -2572,6 +2575,35 @@
"required": ["kind"],
"type": "object"
},
"RetentionQueryResponse": {
"additionalProperties": false,
"properties": {
"hogql": {
"type": "string"
},
"is_cached": {
"type": "boolean"
},
"last_refresh": {
"type": "string"
},
"next_allowed_client_refresh": {
"type": "string"
},
"results": {
"items": {},
"type": "array"
},
"timings": {
"items": {
"$ref": "#/definitions/QueryTiming"
},
"type": "array"
}
},
"required": ["results"],
"type": "object"
},
"RetentionType": {
"enum": ["retention_recurring", "retention_first_time"],
"type": "string"
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,13 @@ export interface FunnelsQuery extends InsightsQueryBase {

/** `RetentionFilterType` minus everything inherited from `FilterType` */
export type RetentionFilter = Omit<RetentionFilterType, keyof FilterType>

export interface RetentionQueryResponse extends QueryResponse {
results: any[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have this a bit more complete

}
export interface RetentionQuery extends InsightsQueryBase {
kind: NodeKind.RetentionQuery
response?: RetentionQueryResponse
/** Properties specific to the retention insight */
retentionFilter?: RetentionFilter
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function isLifecycleQuery(node?: Node | null): node is LifecycleQuery {
}

export function isQueryWithHogQLSupport(node?: Node | null): node is LifecycleQuery {
return isLifecycleQuery(node) || isTrendsQuery(node)
return isLifecycleQuery(node) || isTrendsQuery(node) || isRetentionQuery(node)
}

export function isInsightQueryWithDisplay(node?: Node | null): node is TrendsQuery | StickinessQuery {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,7 @@ export interface PathsFilterType extends FilterType {
export interface RetentionFilterType extends FilterType {
retention_type?: RetentionType
retention_reference?: 'total' | 'previous' // retention wrt cohort size or previous period
/** @asType integer */
total_intervals?: number // retention total intervals
returning_entity?: Record<string, any>
target_entity?: Record<string, any>
Expand Down
1 change: 1 addition & 0 deletions posthog/api/services/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

QUERY_WITH_RUNNER = [
"LifecycleQuery",
"RetentionQuery",
"TrendsQuery",
"WebOverviewQuery",
"WebTopSourcesQuery",
Expand Down
Loading
Loading