From d448593c3b6cb24d9d1362a8b17c5072a86de7a4 Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Fri, 22 Dec 2023 07:08:19 +0000 Subject: [PATCH] chore(hogql): Rename PersonsQuery to ActorsQuery (#19441) --- .../src/queries/nodes/DataNode/LoadNext.tsx | 4 +- .../queries/nodes/DataNode/dataNodeLogic.ts | 18 +- .../src/queries/nodes/DataTable/DataTable.tsx | 21 +- .../queries/nodes/DataTable/queryFeatures.ts | 6 +- .../queries/nodes/DataTable/renderColumn.tsx | 8 +- frontend/src/queries/nodes/DataTable/utils.ts | 2 +- .../PersonsNode/PersonPropertyFilters.tsx | 10 +- .../nodes/PersonsNode/PersonsSearch.tsx | 8 +- frontend/src/queries/query.ts | 4 +- frontend/src/queries/schema.json | 270 +++++++++--------- frontend/src/queries/schema.ts | 26 +- frontend/src/queries/utils.ts | 20 +- .../src/scenes/cohorts/cohortEditLogic.ts | 6 +- .../notebooks/Nodes/NotebookNodeCohort.tsx | 2 +- .../tabs/personsSceneLogic.ts | 6 +- frontend/src/scenes/retention/queries.ts | 8 +- .../scenes/retention/retentionModalLogic.ts | 22 +- .../scenes/saved-insights/SavedInsights.tsx | 4 +- .../trends/persons-modal/PersonsModal.tsx | 8 +- .../trends/persons-modal/personsModalLogic.ts | 28 +- .../scenes/trends/viz/ActionsLineGraph.tsx | 2 +- posthog/api/cohort.py | 8 +- posthog/api/services/query.py | 2 +- posthog/api/test/test_cohort.py | 4 +- posthog/hogql/test/_test_parser.py | 4 +- posthog/hogql/test/test_resolver.py | 2 +- posthog/hogql_queries/actor_strategies.py | 4 +- ...query_runner.py => actors_query_runner.py} | 22 +- posthog/hogql_queries/hogql_query_runner.py | 2 +- ...nner.py => insight_actors_query_runner.py} | 18 +- .../insights/lifecycle_query_runner.py | 2 +- .../insights/retention_query_runner.py | 2 +- ...py => test_insight_actors_query_runner.py} | 26 +- .../insights/test/test_paginators.py | 24 +- .../test/test_retention_query_runner.py | 6 +- .../insights/trends/trends_query_runner.py | 2 +- posthog/hogql_queries/query_runner.py | 26 +- .../sessions_timeline_query_runner.py | 2 +- ..._runner.py => test_actors_query_runner.py} | 48 ++-- posthog/schema.py | 54 ++-- ...sion_recording_list_from_replay_summary.py | 6 +- 41 files changed, 373 insertions(+), 374 deletions(-) rename posthog/hogql_queries/{persons_query_runner.py => actors_query_runner.py} (93%) rename posthog/hogql_queries/insights/{insight_persons_query_runner.py => insight_actors_query_runner.py} (79%) rename posthog/hogql_queries/insights/test/{test_insight_persons_query_runner.py => test_insight_actors_query_runner.py} (85%) rename posthog/hogql_queries/test/{test_persons_query_runner.py => test_actors_query_runner.py} (83%) diff --git a/frontend/src/queries/nodes/DataNode/LoadNext.tsx b/frontend/src/queries/nodes/DataNode/LoadNext.tsx index 714d391ce4ba7..9bd1280e083bf 100644 --- a/frontend/src/queries/nodes/DataNode/LoadNext.tsx +++ b/frontend/src/queries/nodes/DataNode/LoadNext.tsx @@ -3,7 +3,7 @@ import { LemonButton } from 'lib/lemon-ui/LemonButton' import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic' import { DataNode } from '~/queries/schema' -import { isPersonsNode, isPersonsQuery } from '~/queries/utils' +import { isActorsQuery, isPersonsNode } from '~/queries/utils' interface LoadNextProps { query: DataNode @@ -17,7 +17,7 @@ export function LoadNext({ query }: LoadNextProps): JSX.Element { Showing {canLoadNextData || numberOfRows === 1 ? '' : 'all '} {numberOfRows === 1 ? 'one' : numberOfRows}{' '} - {isPersonsNode(query) || isPersonsQuery(query) + {isPersonsNode(query) || isActorsQuery(query) ? numberOfRows === 1 ? 'person' : 'people' diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts index c733efa7e3e75..1196a143c1de2 100644 --- a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts +++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts @@ -29,6 +29,8 @@ import { userLogic } from 'scenes/userLogic' import { removeExpressionComment } from '~/queries/nodes/DataTable/utils' import { query } from '~/queries/query' import { + ActorsQuery, + ActorsQueryResponse, AnyResponseType, DataNode, EventsQuery, @@ -36,18 +38,16 @@ import { InsightVizNode, NodeKind, PersonsNode, - PersonsQuery, - PersonsQueryResponse, QueryResponse, QueryTiming, } from '~/queries/schema' import { + isActorsQuery, isEventsQuery, - isInsightPersonsQuery, + isInsightActorsQuery, isInsightQueryNode, isLifecycleQuery, isPersonsNode, - isPersonsQuery, isTrendsQuery, } from '~/queries/utils' @@ -212,7 +212,7 @@ export const dataNodeLogic = kea([ } // TODO: unify when we use the same backend endpoint for both const now = performance.now() - if (isEventsQuery(props.query) || isPersonsQuery(props.query)) { + if (isEventsQuery(props.query) || isActorsQuery(props.query)) { const newResponse = (await query(values.nextQuery)) ?? null actions.setElapsedTime(performance.now() - now) const queryResponse = values.response as QueryResponse @@ -396,8 +396,8 @@ export const dataNodeLogic = kea([ return null } - if ((isEventsQuery(query) || isPersonsQuery(query)) && !responseError && !dataLoading) { - if ((response as EventsQueryResponse | PersonsQueryResponse)?.hasMore) { + if ((isEventsQuery(query) || isActorsQuery(query)) && !responseError && !dataLoading) { + if ((response as EventsQueryResponse | ActorsQueryResponse)?.hasMore) { const sortKey = query.orderBy?.[0] ?? 'timestamp DESC' const typedResults = (response as QueryResponse)?.results if (isEventsQuery(query) && sortKey === 'timestamp DESC') { @@ -423,7 +423,7 @@ export const dataNodeLogic = kea([ ...query, offset: typedResults?.length || 0, limit: Math.max(100, Math.min(2 * (typedResults?.length || 100), LOAD_MORE_ROWS_LIMIT)), - } as EventsQuery | PersonsQuery + } as EventsQuery | ActorsQuery } } } @@ -446,7 +446,7 @@ export const dataNodeLogic = kea([ backToSourceQuery: [ (s) => [s.query], (query): InsightVizNode | null => { - if (isPersonsQuery(query) && isInsightPersonsQuery(query.source) && !!query.source.source) { + if (isActorsQuery(query) && isInsightActorsQuery(query.source) && !!query.source.source) { const insightQuery = query.source.source const insightVizNode: InsightVizNode = { kind: NodeKind.InsightVizNode, diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsx index 7cfec3e91a888..b0a3c52382acb 100644 --- a/frontend/src/queries/nodes/DataTable/DataTable.tsx +++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx @@ -41,20 +41,20 @@ import { OpenEditorButton } from '~/queries/nodes/Node/OpenEditorButton' import { PersonPropertyFilters } from '~/queries/nodes/PersonsNode/PersonPropertyFilters' import { PersonsSearch } from '~/queries/nodes/PersonsNode/PersonsSearch' import { + ActorsQuery, AnyResponseType, DataTableNode, EventsNode, EventsQuery, HogQLQuery, PersonsNode, - PersonsQuery, } from '~/queries/schema' import { QueryContext } from '~/queries/types' import { + isActorsQuery, isEventsQuery, isHogQlAggregation, isHogQLQuery, - isPersonsQuery, taxonomicEventFilterToHogQL, taxonomicPersonFilterToHogQL, } from '~/queries/utils' @@ -138,8 +138,8 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } ? columnsInResponse ?? columnsInQuery : columnsInQuery - const groupTypes = isPersonsQuery(query.source) ? personGroupTypes : eventGroupTypes - const hogQLTable = isPersonsQuery(query.source) ? 'persons' : 'events' + const groupTypes = isActorsQuery(query.source) ? personGroupTypes : eventGroupTypes + const hogQLTable = isActorsQuery(query.source) ? 'persons' : 'events' const lemonColumns: LemonTableColumn[] = [ ...columnsInLemonTable.map((key, index) => ({ @@ -182,7 +182,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } type="tertiary" fullWidth onChange={(v, g) => { - const hogQl = isPersonsQuery(query.source) + const hogQl = isActorsQuery(query.source) ? taxonomicPersonFilterToHogQL(g, v) : taxonomicEventFilterToHogQL(g, v) if (setQuery && hogQl && sourceFeatures.has(QueryFeature.selectAndOrderByColumns)) { @@ -263,7 +263,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } type="tertiary" fullWidth onChange={(v, g) => { - const hogQl = isPersonsQuery(query.source) + const hogQl = isActorsQuery(query.source) ? taxonomicPersonFilterToHogQL(g, v) : taxonomicEventFilterToHogQL(g, v) if (setQuery && hogQl && sourceFeatures.has(QueryFeature.selectAndOrderByColumns)) { @@ -277,7 +277,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } select: [...columns.slice(0, index), hogQl, ...columns.slice(index)].filter( (c) => (isAggregation ? c !== '*' && c !== 'person.$delete' : true) ), - } as EventsQuery | PersonsQuery, + } as EventsQuery | ActorsQuery, }) } }} @@ -292,7 +292,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } type="tertiary" fullWidth onChange={(v, g) => { - const hogQl = isPersonsQuery(query.source) + const hogQl = isActorsQuery(query.source) ? taxonomicPersonFilterToHogQL(g, v) : taxonomicEventFilterToHogQL(g, v) if (setQuery && hogQl && sourceFeatures.has(QueryFeature.selectAndOrderByColumns)) { @@ -310,7 +310,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } ].filter((c) => isAggregation ? c !== '*' && c !== 'person.$delete' : true ), - } as EventsQuery | PersonsQuery, + } as EventsQuery | ActorsQuery, }) } }} @@ -370,8 +370,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults } ].filter((column) => !query.hiddenColumns?.includes(column.dataIndex) && column.dataIndex !== '*') const setQuerySource = useCallback( - (source: EventsNode | EventsQuery | PersonsNode | PersonsQuery | HogQLQuery) => - setQuery?.({ ...query, source }), + (source: EventsNode | EventsQuery | PersonsNode | ActorsQuery | HogQLQuery) => setQuery?.({ ...query, source }), [setQuery] ) diff --git a/frontend/src/queries/nodes/DataTable/queryFeatures.ts b/frontend/src/queries/nodes/DataTable/queryFeatures.ts index 4c2b4202ea539..560ee7424013a 100644 --- a/frontend/src/queries/nodes/DataTable/queryFeatures.ts +++ b/frontend/src/queries/nodes/DataTable/queryFeatures.ts @@ -1,9 +1,9 @@ import { Node } from '~/queries/schema' import { + isActorsQuery, isEventsQuery, isHogQLQuery, isPersonsNode, - isPersonsQuery, isWebOverviewQuery, isWebStatsTableQuery, isWebTopClicksQuery, @@ -43,11 +43,11 @@ export function getQueryFeatures(query: Node): Set { features.add(QueryFeature.selectAndOrderByColumns) } - if (isPersonsNode(query) || isPersonsQuery(query)) { + if (isPersonsNode(query) || isActorsQuery(query)) { features.add(QueryFeature.personPropertyFilters) features.add(QueryFeature.personsSearch) - if (isPersonsQuery(query)) { + if (isActorsQuery(query)) { features.add(QueryFeature.selectAndOrderByColumns) features.add(QueryFeature.columnsInResponse) features.add(QueryFeature.resultIsArrayOfArrays) diff --git a/frontend/src/queries/nodes/DataTable/renderColumn.tsx b/frontend/src/queries/nodes/DataTable/renderColumn.tsx index ac141f208630c..9079149cc2bfc 100644 --- a/frontend/src/queries/nodes/DataTable/renderColumn.tsx +++ b/frontend/src/queries/nodes/DataTable/renderColumn.tsx @@ -18,10 +18,10 @@ import { DeletePersonButton } from '~/queries/nodes/PersonsNode/DeletePersonButt import { DataTableNode, EventsQueryPersonColumn, HasPropertiesNode } from '~/queries/schema' import { QueryContext } from '~/queries/types' import { + isActorsQuery, isEventsQuery, isHogQLQuery, isPersonsNode, - isPersonsQuery, isTimeToSeeDataSessionsQuery, trimQuotes, } from '~/queries/utils' @@ -221,7 +221,7 @@ export function renderColumn( displayProps.href = urls.personByDistinctId(personRecord.distinct_ids[0]) } - if (isPersonsQuery(query.source) && value) { + if (isActorsQuery(query.source) && value) { displayProps.person = value displayProps.href = value.id ? urls.personByUUID(value.id) @@ -229,14 +229,14 @@ export function renderColumn( } return - } else if (key === 'person.$delete' && (isPersonsNode(query.source) || isPersonsQuery(query.source))) { + } else if (key === 'person.$delete' && (isPersonsNode(query.source) || isActorsQuery(query.source))) { const personRecord = record as PersonType return } else if (key.startsWith('context.columns.')) { const columnName = trimQuotes(key.substring(16)) // 16 = "context.columns.".length const Component = context?.columns?.[columnName]?.render return Component ? : '' - } else if (key === 'id' && (isPersonsNode(query.source) || isPersonsQuery(query.source))) { + } else if (key === 'id' && (isPersonsNode(query.source) || isActorsQuery(query.source))) { return ( void + query: PersonsNode | ActorsQuery + setQuery?: (query: PersonsNode | ActorsQuery) => void } let uniqueNode = 0 @@ -25,7 +25,7 @@ export function PersonPropertyFilters({ query, setQuery }: PersonPropertyFilters }} pageKey={`PersonPropertyFilters.${id}`} taxonomicGroupTypes={ - isPersonsQuery(query) + isActorsQuery(query) ? [ TaxonomicFilterGroupType.PersonProperties, TaxonomicFilterGroupType.Cohorts, diff --git a/frontend/src/queries/nodes/PersonsNode/PersonsSearch.tsx b/frontend/src/queries/nodes/PersonsNode/PersonsSearch.tsx index 8836b76cac7de..2dc4c7adece92 100644 --- a/frontend/src/queries/nodes/PersonsNode/PersonsSearch.tsx +++ b/frontend/src/queries/nodes/PersonsNode/PersonsSearch.tsx @@ -3,13 +3,13 @@ import { LemonInput } from 'lib/lemon-ui/LemonInput/LemonInput' import { Tooltip } from 'lib/lemon-ui/Tooltip' import { useDebouncedQuery } from '~/queries/hooks/useDebouncedQuery' -import { PersonsNode, PersonsQuery } from '~/queries/schema' +import { ActorsQuery, PersonsNode } from '~/queries/schema' import { isQueryForGroup } from '~/queries/utils' type ActorType = 'person' | 'group' interface PersonSearchProps { - query: PersonsNode | PersonsQuery - setQuery?: (query: PersonsNode | PersonsQuery) => void + query: PersonsNode | ActorsQuery + setQuery?: (query: PersonsNode | ActorsQuery) => void } interface LabelType { @@ -31,7 +31,7 @@ const labels: Record = { } export function PersonsSearch({ query, setQuery }: PersonSearchProps): JSX.Element { - const { value, onChange } = useDebouncedQuery( + const { value, onChange } = useDebouncedQuery( query, setQuery, (query) => query.search || '', diff --git a/frontend/src/queries/query.ts b/frontend/src/queries/query.ts index 5d9b63e1d151b..348a57059a2c3 100644 --- a/frontend/src/queries/query.ts +++ b/frontend/src/queries/query.ts @@ -21,6 +21,7 @@ import { AnyPartialFilterType, OnlineExportContext, QueryExportContext } from '~ import { queryNodeToFilter } from './nodes/InsightQuery/utils/queryNodeToFilter' import { DataNode, HogQLQuery, HogQLQueryResponse, NodeKind, PersonsNode } from './schema' import { + isActorsQuery, isDataTableNode, isDataVisualizationNode, isEventsQuery, @@ -29,7 +30,6 @@ import { isInsightVizNode, isLifecycleQuery, isPersonsNode, - isPersonsQuery, isRetentionQuery, isTimeToSeeDataQuery, isTimeToSeeDataSessionsNode, @@ -52,7 +52,7 @@ export function queryExportContext( return queryExportContext(query.source, methodOptions, refresh) } else if (isDataVisualizationNode(query)) { return queryExportContext(query.source, methodOptions, refresh) - } else if (isEventsQuery(query) || isPersonsQuery(query)) { + } else if (isEventsQuery(query) || isActorsQuery(query)) { return { source: query, } diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json index 529fdc752f618..d05ef08ea3e82 100644 --- a/frontend/src/queries/schema.json +++ b/frontend/src/queries/schema.json @@ -68,6 +68,109 @@ "required": ["id", "kind"], "type": "object" }, + "ActorsQuery": { + "additionalProperties": false, + "properties": { + "fixedProperties": { + "items": { + "$ref": "#/definitions/AnyPropertyFilter" + }, + "type": "array" + }, + "kind": { + "const": "ActorsQuery", + "type": "string" + }, + "limit": { + "type": "integer" + }, + "offset": { + "type": "integer" + }, + "orderBy": { + "items": { + "type": "string" + }, + "type": "array" + }, + "properties": { + "items": { + "$ref": "#/definitions/AnyPropertyFilter" + }, + "type": "array" + }, + "response": { + "$ref": "#/definitions/ActorsQueryResponse", + "description": "Cached query response" + }, + "search": { + "type": "string" + }, + "select": { + "items": { + "$ref": "#/definitions/HogQLExpression" + }, + "type": "array" + }, + "source": { + "anyOf": [ + { + "$ref": "#/definitions/InsightActorsQuery" + }, + { + "$ref": "#/definitions/HogQLQuery" + } + ] + } + }, + "required": ["kind"], + "type": "object" + }, + "ActorsQueryResponse": { + "additionalProperties": false, + "properties": { + "columns": { + "items": {}, + "type": "array" + }, + "hasMore": { + "type": "boolean" + }, + "hogql": { + "type": "string" + }, + "limit": { + "type": "integer" + }, + "missing_actors_count": { + "type": "integer" + }, + "offset": { + "type": "integer" + }, + "results": { + "items": { + "items": {}, + "type": "array" + }, + "type": "array" + }, + "timings": { + "items": { + "$ref": "#/definitions/QueryTiming" + }, + "type": "array" + }, + "types": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": ["results", "columns", "types", "hogql", "limit", "offset"], + "type": "object" + }, "AggregationAxisFormat": { "enum": ["numeric", "duration", "duration_ms", "percentage", "percentage_scaled"], "type": "string" @@ -90,10 +193,10 @@ "$ref": "#/definitions/EventsQuery" }, { - "$ref": "#/definitions/PersonsQuery" + "$ref": "#/definitions/ActorsQuery" }, { - "$ref": "#/definitions/InsightPersonsQuery" + "$ref": "#/definitions/InsightActorsQuery" }, { "$ref": "#/definitions/SessionsTimelineQuery" @@ -497,7 +600,7 @@ "$ref": "#/definitions/PersonsNode" }, { - "$ref": "#/definitions/PersonsQuery" + "$ref": "#/definitions/ActorsQuery" }, { "$ref": "#/definitions/HogQLQuery" @@ -1672,6 +1775,33 @@ }, "type": "object" }, + "InsightActorsQuery": { + "additionalProperties": false, + "properties": { + "day": { + "type": "string" + }, + "interval": { + "description": "An interval selected out of available intervals in source query", + "type": "integer" + }, + "kind": { + "const": "InsightActorsQuery", + "type": "string" + }, + "response": { + "$ref": "#/definitions/ActorsQueryResponse" + }, + "source": { + "$ref": "#/definitions/InsightQueryNode" + }, + "status": { + "type": "string" + } + }, + "required": ["kind", "source"], + "type": "object" + }, "InsightFilter": { "anyOf": [ { @@ -1716,33 +1846,6 @@ ], "type": "string" }, - "InsightPersonsQuery": { - "additionalProperties": false, - "properties": { - "day": { - "type": "string" - }, - "interval": { - "description": "An interval selected out of available intervals in source query", - "type": "integer" - }, - "kind": { - "const": "InsightPersonsQuery", - "type": "string" - }, - "response": { - "$ref": "#/definitions/PersonsQueryResponse" - }, - "source": { - "$ref": "#/definitions/InsightQueryNode" - }, - "status": { - "type": "string" - } - }, - "required": ["kind", "source"], - "type": "object" - }, "InsightQueryNode": { "anyOf": [ { @@ -2011,7 +2114,7 @@ "PersonsNode", "HogQLQuery", "HogQLMetadata", - "PersonsQuery", + "ActorsQuery", "SessionsTimelineQuery", "DataTableNode", "DataVisualizationNode", @@ -2023,7 +2126,7 @@ "PathsQuery", "StickinessQuery", "LifecycleQuery", - "InsightPersonsQuery", + "InsightActorsQuery", "WebOverviewQuery", "WebTopClicksQuery", "WebStatsTableQuery", @@ -2229,109 +2332,6 @@ "required": ["kind"], "type": "object" }, - "PersonsQuery": { - "additionalProperties": false, - "properties": { - "fixedProperties": { - "items": { - "$ref": "#/definitions/AnyPropertyFilter" - }, - "type": "array" - }, - "kind": { - "const": "PersonsQuery", - "type": "string" - }, - "limit": { - "type": "integer" - }, - "offset": { - "type": "integer" - }, - "orderBy": { - "items": { - "type": "string" - }, - "type": "array" - }, - "properties": { - "items": { - "$ref": "#/definitions/AnyPropertyFilter" - }, - "type": "array" - }, - "response": { - "$ref": "#/definitions/PersonsQueryResponse", - "description": "Cached query response" - }, - "search": { - "type": "string" - }, - "select": { - "items": { - "$ref": "#/definitions/HogQLExpression" - }, - "type": "array" - }, - "source": { - "anyOf": [ - { - "$ref": "#/definitions/InsightPersonsQuery" - }, - { - "$ref": "#/definitions/HogQLQuery" - } - ] - } - }, - "required": ["kind"], - "type": "object" - }, - "PersonsQueryResponse": { - "additionalProperties": false, - "properties": { - "columns": { - "items": {}, - "type": "array" - }, - "hasMore": { - "type": "boolean" - }, - "hogql": { - "type": "string" - }, - "limit": { - "type": "integer" - }, - "missing_actors_count": { - "type": "integer" - }, - "offset": { - "type": "integer" - }, - "results": { - "items": { - "items": {}, - "type": "array" - }, - "type": "array" - }, - "timings": { - "items": { - "$ref": "#/definitions/QueryTiming" - }, - "type": "array" - }, - "types": { - "items": { - "type": "string" - }, - "type": "array" - } - }, - "required": ["results", "columns", "types", "hogql", "limit", "offset"], - "type": "object" - }, "PropertyFilterType": { "enum": [ "meta", diff --git a/frontend/src/queries/schema.ts b/frontend/src/queries/schema.ts index 94b739a189871..16dd7d671115e 100644 --- a/frontend/src/queries/schema.ts +++ b/frontend/src/queries/schema.ts @@ -46,7 +46,7 @@ export enum NodeKind { PersonsNode = 'PersonsNode', HogQLQuery = 'HogQLQuery', HogQLMetadata = 'HogQLMetadata', - PersonsQuery = 'PersonsQuery', + ActorsQuery = 'ActorsQuery', SessionsTimelineQuery = 'SessionsTimelineQuery', // Interface nodes @@ -62,7 +62,7 @@ export enum NodeKind { PathsQuery = 'PathsQuery', StickinessQuery = 'StickinessQuery', LifecycleQuery = 'LifecycleQuery', - InsightPersonsQuery = 'InsightPersonsQuery', + InsightActorsQuery = 'InsightActorsQuery', // Web analytics queries WebOverviewQuery = 'WebOverviewQuery', @@ -85,8 +85,8 @@ export type AnyDataNode = | PersonsNode // old persons API endpoint | TimeToSeeDataSessionsQuery // old API | EventsQuery - | PersonsQuery - | InsightPersonsQuery + | ActorsQuery + | InsightActorsQuery | SessionsTimelineQuery | HogQLQuery | HogQLMetadata @@ -336,7 +336,7 @@ export interface DataTableNode extends Node, DataTableNodeViewProps { | EventsNode | EventsQuery | PersonsNode - | PersonsQuery + | ActorsQuery | HogQLQuery | TimeToSeeDataSessionsQuery | WebOverviewQuery @@ -631,7 +631,7 @@ export interface LifecycleQuery extends Omit { diff --git a/frontend/src/queries/utils.ts b/frontend/src/queries/utils.ts index 11dd7a60db071..c6c12e8a3a03f 100644 --- a/frontend/src/queries/utils.ts +++ b/frontend/src/queries/utils.ts @@ -4,6 +4,7 @@ import { teamLogic } from 'scenes/teamLogic' import { ActionsNode, + ActorsQuery, DatabaseSchemaQuery, DataTableNode, DataVisualizationNode, @@ -13,10 +14,10 @@ import { FunnelsQuery, HogQLMetadata, HogQLQuery, + InsightActorsQuery, InsightFilter, InsightFilterProperty, InsightNodeKind, - InsightPersonsQuery, InsightQueryNode, InsightVizNode, LifecycleQuery, @@ -24,7 +25,6 @@ import { NodeKind, PathsQuery, PersonsNode, - PersonsQuery, RetentionQuery, SavedInsightNode, StickinessQuery, @@ -46,7 +46,7 @@ export function isDataNode(node?: Node | null): node is EventsQuery | PersonsNod isPersonsNode(node) || isTimeToSeeDataSessionsQuery(node) || isEventsQuery(node) || - isPersonsQuery(node) || + isActorsQuery(node) || isHogQLQuery(node) || isHogQLMetadata(node) ) @@ -92,12 +92,12 @@ export function isPersonsNode(node?: Node | null): node is PersonsNode { return node?.kind === NodeKind.PersonsNode } -export function isPersonsQuery(node?: Node | null): node is PersonsQuery { - return node?.kind === NodeKind.PersonsQuery +export function isActorsQuery(node?: Node | null): node is ActorsQuery { + return node?.kind === NodeKind.ActorsQuery } -export function isInsightPersonsQuery(node?: Node | null): node is InsightPersonsQuery { - return node?.kind === NodeKind.InsightPersonsQuery +export function isInsightActorsQuery(node?: Node | null): node is InsightActorsQuery { + return node?.kind === NodeKind.InsightActorsQuery } export function isDataTableNode(node?: Node | null): node is DataTableNode { @@ -183,10 +183,10 @@ export function isDatabaseSchemaQuery(node?: Node): node is DatabaseSchemaQuery return node?.kind === NodeKind.DatabaseSchemaQuery } -export function isQueryForGroup(query: PersonsNode | PersonsQuery): boolean { +export function isQueryForGroup(query: PersonsNode | ActorsQuery): boolean { return ( - isPersonsQuery(query) && - isInsightPersonsQuery(query.source) && + isActorsQuery(query) && + isInsightActorsQuery(query.source) && isRetentionQuery(query.source.source) && query.source.source.aggregation_group_type_index !== undefined ) diff --git a/frontend/src/scenes/cohorts/cohortEditLogic.ts b/frontend/src/scenes/cohorts/cohortEditLogic.ts index ecfba636b35c8..8cd8b06f94dba 100644 --- a/frontend/src/scenes/cohorts/cohortEditLogic.ts +++ b/frontend/src/scenes/cohorts/cohortEditLogic.ts @@ -70,7 +70,7 @@ export const cohortEditLogic = kea([ }), selectors({ - usePersonsQuery: [(s) => [s.featureFlags], (featureFlags) => featureFlags[FEATURE_FLAGS.PERSONS_HOGQL_QUERY]], + useActorsQuery: [(s) => [s.featureFlags], (featureFlags) => featureFlags[FEATURE_FLAGS.PERSONS_HOGQL_QUERY]], }), reducers(({ props, selectors }) => ({ @@ -167,11 +167,11 @@ export const cohortEditLogic = kea([ ], query: [ ((state: Record) => - selectors.usePersonsQuery(state) + selectors.useActorsQuery(state) ? { kind: NodeKind.DataTableNode, source: { - kind: NodeKind.PersonsQuery, + kind: NodeKind.ActorsQuery, fixedProperties: [ { type: PropertyFilterType.Cohort, key: 'id', value: parseInt(String(props.id)) }, ], diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeCohort.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeCohort.tsx index fd5aad3420b5e..310ec587c8d14 100644 --- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeCohort.tsx +++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeCohort.tsx @@ -53,7 +53,7 @@ const Component = ({ attributes }: NotebookNodeProps ({ +const getDefaultQuery = (useActorsQuery = false): DataTableNode => ({ kind: NodeKind.DataTableNode, - source: usePersonsQuery - ? { kind: NodeKind.PersonsQuery, select: defaultDataTableColumns(NodeKind.PersonsQuery) } + source: useActorsQuery + ? { kind: NodeKind.ActorsQuery, select: defaultDataTableColumns(NodeKind.ActorsQuery) } : { kind: NodeKind.PersonsNode }, full: true, propertiesViaUrl: true, diff --git a/frontend/src/scenes/retention/queries.ts b/frontend/src/scenes/retention/queries.ts index 3bca06cca714e..7b8d738cc7109 100644 --- a/frontend/src/scenes/retention/queries.ts +++ b/frontend/src/scenes/retention/queries.ts @@ -1,17 +1,17 @@ import { RetentionTableAppearanceType, RetentionTablePeoplePayload } from 'scenes/retention/types' import { query } from '~/queries/query' -import { NodeKind, PersonsQuery, RetentionQuery } from '~/queries/schema' +import { ActorsQuery, NodeKind, RetentionQuery } from '~/queries/schema' -export function retentionToActorsQuery(query: RetentionQuery, selectedInterval: number, offset = 0): PersonsQuery { +export function retentionToActorsQuery(query: RetentionQuery, selectedInterval: number, offset = 0): ActorsQuery { const group = query.aggregation_group_type_index !== undefined const select = group ? 'group' : 'person' return { - kind: NodeKind.PersonsQuery, + kind: NodeKind.ActorsQuery, select: [select, 'appearances'], orderBy: ['length(appearances) DESC', 'actor_id'], source: { - kind: NodeKind.InsightPersonsQuery, + kind: NodeKind.InsightActorsQuery, interval: selectedInterval, source: { ...query, diff --git a/frontend/src/scenes/retention/retentionModalLogic.ts b/frontend/src/scenes/retention/retentionModalLogic.ts index 4ad79ea1407c4..ad605e13b1516 100644 --- a/frontend/src/scenes/retention/retentionModalLogic.ts +++ b/frontend/src/scenes/retention/retentionModalLogic.ts @@ -5,8 +5,8 @@ import { retentionToActorsQuery } from 'scenes/retention/queries' import { urls } from 'scenes/urls' import { groupsModel, Noun } from '~/models/groupsModel' -import { DataTableNode, NodeKind, PersonsQuery, RetentionQuery } from '~/queries/schema' -import { isInsightPersonsQuery, isLifecycleQuery, isRetentionQuery, isStickinessQuery } from '~/queries/utils' +import { ActorsQuery, DataTableNode, NodeKind, RetentionQuery } from '~/queries/schema' +import { isInsightActorsQuery, isLifecycleQuery, isRetentionQuery, isStickinessQuery } from '~/queries/utils' import { InsightLogicProps } from '~/types' import type { retentionModalLogicType } from './retentionModalLogicType' @@ -46,9 +46,9 @@ export const retentionModalLogic = kea([ return aggregationLabel(aggregation_group_type_index) }, ], - personsQuery: [ + actorsQuery: [ (s) => [s.querySource, s.selectedInterval], - (querySource: RetentionQuery, selectedInterval): PersonsQuery | null => { + (querySource: RetentionQuery, selectedInterval): ActorsQuery | null => { if (!querySource) { return null } @@ -56,20 +56,20 @@ export const retentionModalLogic = kea([ }, ], exploreUrl: [ - (s) => [s.personsQuery], - (personsQuery): string | null => { - if (!personsQuery) { + (s) => [s.actorsQuery], + (actorsQuery): string | null => { + if (!actorsQuery) { return null } const query: DataTableNode = { kind: NodeKind.DataTableNode, - source: personsQuery, + source: actorsQuery, full: true, } if ( - isInsightPersonsQuery(personsQuery.source) && - isRetentionQuery(personsQuery.source.source) && - personsQuery.source.source.aggregation_group_type_index !== undefined + isInsightActorsQuery(actorsQuery.source) && + isRetentionQuery(actorsQuery.source.source) && + actorsQuery.source.source.aggregation_group_type_index !== undefined ) { query.showPropertyFilter = false } diff --git a/frontend/src/scenes/saved-insights/SavedInsights.tsx b/frontend/src/scenes/saved-insights/SavedInsights.tsx index bf14cdad8854a..739499d6fa431 100644 --- a/frontend/src/scenes/saved-insights/SavedInsights.tsx +++ b/frontend/src/scenes/saved-insights/SavedInsights.tsx @@ -187,13 +187,13 @@ export const QUERY_TYPES_METADATA: Record = { icon: IconPerson, inMenu: true, }, - [NodeKind.PersonsQuery]: { + [NodeKind.ActorsQuery]: { name: 'Persons', description: 'List of persons matching specified conditions', icon: IconPerson, inMenu: false, }, - [NodeKind.InsightPersonsQuery]: { + [NodeKind.InsightActorsQuery]: { name: 'Persons', description: 'List of persons matching specified conditions, derived from an insight', icon: IconPerson, diff --git a/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx b/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx index bce7f2176b9db..d07dde60bf662 100644 --- a/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx +++ b/frontend/src/scenes/trends/persons-modal/PersonsModal.tsx @@ -25,7 +25,7 @@ import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/ import { teamLogic } from 'scenes/teamLogic' import { Noun } from '~/models/groupsModel' -import { InsightPersonsQuery } from '~/queries/schema' +import { InsightActorsQuery } from '~/queries/schema' import { ActorType, ExporterFormat, @@ -39,7 +39,7 @@ import { SaveCohortModal } from './SaveCohortModal' export interface PersonsModalProps extends Pick { onAfterClose?: () => void - query?: InsightPersonsQuery | null + query?: InsightActorsQuery | null url?: string | null urlsIndex?: number urls?: { @@ -77,7 +77,7 @@ export function PersonsModal({ missingActorsCount, propertiesTimelineFilterFromUrl, exploreUrl, - personsQuery, + ActorsQuery, } = useValues(logic) const { setSearchTerm, saveAsCohort, setIsCohortModalOpen, closeModal, loadNextActors } = useActions(logic) const { openSessionPlayer } = useActions(sessionPlayerModalLogic) @@ -191,7 +191,7 @@ export function PersonsModal({ void triggerExport({ export_format: ExporterFormat.CSV, export_context: query - ? { source: personsQuery as Record } + ? { source: ActorsQuery as Record } : { path: originalUrl }, }) }} diff --git a/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts b/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts index b8a54b03094d2..da64e7aadd17d 100644 --- a/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts +++ b/frontend/src/scenes/trends/persons-modal/personsModalLogic.ts @@ -11,7 +11,7 @@ import { urls } from 'scenes/urls' import { cohortsModel } from '~/models/cohortsModel' import { groupsModel } from '~/models/groupsModel' import { query as performQuery } from '~/queries/query' -import { DataTableNode, InsightPersonsQuery, NodeKind, PersonsQuery } from '~/queries/schema' +import { ActorsQuery, DataTableNode, InsightActorsQuery, NodeKind } from '~/queries/schema' import { ActorType, BreakdownType, @@ -26,7 +26,7 @@ import type { personsModalLogicType } from './personsModalLogicType' const RESULTS_PER_PAGE = 100 export interface PersonModalLogicProps { - query?: InsightPersonsQuery | null + query?: InsightActorsQuery | null url?: string | null } @@ -56,7 +56,7 @@ export const personsModalLogic = kea([ offset, }: { url?: string | null - query?: InsightPersonsQuery | null + query?: InsightActorsQuery | null clear?: boolean offset?: number }) => ({ @@ -92,10 +92,10 @@ export const personsModalLogic = kea([ return res } else if (query) { const response = await performQuery({ - ...values.personsQuery, + ...values.ActorsQuery, limit: RESULTS_PER_PAGE + 1, offset: offset || 0, - } as PersonsQuery) + } as ActorsQuery) const newResponse: ListActorsResponse = { results: [ { @@ -180,8 +180,8 @@ export const personsModalLogic = kea([ is_static: true, name: cohortName, } - if (values.personsQuery) { - const cohort = await api.create('api/cohort', { ...cohortParams, query: values.personsQuery }) + if (values.ActorsQuery) { + const cohort = await api.create('api/cohort', { ...cohortParams, query: values.ActorsQuery }) cohortsModel.actions.cohortCreated(cohort) lemonToast.success('Cohort saved', { toastId: `cohort-saved-${cohort.id}`, @@ -256,14 +256,14 @@ export const personsModalLogic = kea([ return cleanFilters(filter) }, ], - personsQuery: [ + ActorsQuery: [ (s) => [(_, p) => p.query, s.searchTerm], - (query, searchTerm): PersonsQuery | null => { + (query, searchTerm): ActorsQuery | null => { if (!query) { return null } return { - kind: NodeKind.PersonsQuery, + kind: NodeKind.ActorsQuery, source: query, select: ['person', 'created_at'], orderBy: ['created_at DESC'], @@ -272,12 +272,12 @@ export const personsModalLogic = kea([ }, ], exploreUrl: [ - (s) => [s.personsQuery], - (personsQuery): string | null => { - if (!personsQuery) { + (s) => [s.ActorsQuery], + (ActorsQuery): string | null => { + if (!ActorsQuery) { return null } - const { select: _select, ...source } = personsQuery + const { select: _select, ...source } = ActorsQuery const query: DataTableNode = { kind: NodeKind.DataTableNode, source, diff --git a/frontend/src/scenes/trends/viz/ActionsLineGraph.tsx b/frontend/src/scenes/trends/viz/ActionsLineGraph.tsx index 42d31f40ea631..a80f2cdd279b1 100644 --- a/frontend/src/scenes/trends/viz/ActionsLineGraph.tsx +++ b/frontend/src/scenes/trends/viz/ActionsLineGraph.tsx @@ -119,7 +119,7 @@ export function ActionsLineGraph({ openPersonsModal({ title, query: { - kind: NodeKind.InsightPersonsQuery, + kind: NodeKind.InsightActorsQuery, source: query.source, day, status: dataset.status, diff --git a/posthog/api/cohort.py b/posthog/api/cohort.py index 68f2809f6a484..713bb733de220 100644 --- a/posthog/api/cohort.py +++ b/posthog/api/cohort.py @@ -79,7 +79,7 @@ from posthog.queries.trends.trends_actors import TrendsActors from posthog.queries.trends.lifecycle_actors import LifecycleActors from posthog.queries.util import get_earliest_timestamp -from posthog.schema import PersonsQuery +from posthog.schema import ActorsQuery from posthog.tasks.calculate_cohort import ( calculate_cohort_from_list, insert_cohort_from_feature_flag, @@ -180,9 +180,9 @@ def validate_query(self, query: Optional[Dict]) -> Optional[Dict]: return None if not isinstance(query, dict): raise ValidationError("Query must be a dictionary.") - if query.get("kind") != "PersonsQuery": - raise ValidationError(f"Query must be a PersonsQuery. Got: {query.get('kind')}") - PersonsQuery.model_validate(query) + if query.get("kind") != "ActorsQuery": + raise ValidationError(f"Query must be a ActorsQuery. Got: {query.get('kind')}") + ActorsQuery.model_validate(query) return query def validate_filters(self, request_filters: Dict): diff --git a/posthog/api/services/query.py b/posthog/api/services/query.py index b5ca456ee985e..aaca464af51a7 100644 --- a/posthog/api/services/query.py +++ b/posthog/api/services/query.py @@ -30,7 +30,7 @@ QUERY_WITH_RUNNER_NO_CACHE = [ "HogQLQuery", "EventsQuery", - "PersonsQuery", + "ActorsQuery", "SessionsTimelineQuery", ] diff --git a/posthog/api/test/test_cohort.py b/posthog/api/test/test_cohort.py index f9e03897b599f..33128b639d03f 100644 --- a/posthog/api/test/test_cohort.py +++ b/posthog/api/test/test_cohort.py @@ -725,7 +725,7 @@ def test_creating_update_and_calculating_with_new_cohort_query(self, patch_captu "name": "cohort A", "is_static": True, "query": { - "kind": "PersonsQuery", + "kind": "ActorsQuery", "properties": [ { "key": "$some_prop", @@ -755,7 +755,7 @@ def test_creating_update_and_calculating_with_new_cohort_query_dynamic_error(sel data={ "name": "cohort A", "query": { - "kind": "PersonsQuery", + "kind": "ActorsQuery", "properties": [ { "key": "$some_prop", diff --git a/posthog/hogql/test/_test_parser.py b/posthog/hogql/test/_test_parser.py index 16d4654397088..1071f10aa8a0f 100644 --- a/posthog/hogql/test/_test_parser.py +++ b/posthog/hogql/test/_test_parser.py @@ -1561,7 +1561,7 @@ def test_visit_hogqlx_tag_alias(self): def test_visit_hogqlx_tag_source(self): query = """ select id, email from ( - @@ -1572,7 +1572,7 @@ def test_visit_hogqlx_tag_source(self): node = self._select(query) table_node = cast(ast.SelectQuery, node).select_from.table assert table_node == ast.HogQLXTag( - kind="PersonsQuery", + kind="ActorsQuery", attributes=[ ast.HogQLXAttribute( name="select", diff --git a/posthog/hogql/test/test_resolver.py b/posthog/hogql/test/test_resolver.py index 266a8cdeb65cc..1a7b2f6b7f99a 100644 --- a/posthog/hogql/test/test_resolver.py +++ b/posthog/hogql/test/test_resolver.py @@ -338,7 +338,7 @@ def test_visit_hogqlx_tag_alias(self): def test_visit_hogqlx_tag_source(self): query = """ select id, email from ( - diff --git a/posthog/hogql_queries/actor_strategies.py b/posthog/hogql_queries/actor_strategies.py index 466b52ff18d79..747c7e15da362 100644 --- a/posthog/hogql_queries/actor_strategies.py +++ b/posthog/hogql_queries/actor_strategies.py @@ -6,7 +6,7 @@ from posthog.hogql.property import property_to_expr from posthog.hogql_queries.insights.paginators import HogQLHasMorePaginator from posthog.models import Team, Person, Group -from posthog.schema import PersonsQuery +from posthog.schema import ActorsQuery class ActorStrategy: @@ -14,7 +14,7 @@ class ActorStrategy: origin: str origin_id: str - def __init__(self, team: Team, query: PersonsQuery, paginator: HogQLHasMorePaginator): + def __init__(self, team: Team, query: ActorsQuery, paginator: HogQLHasMorePaginator): self.team = team self.paginator = paginator self.query = query diff --git a/posthog/hogql_queries/persons_query_runner.py b/posthog/hogql_queries/actors_query_runner.py similarity index 93% rename from posthog/hogql_queries/persons_query_runner.py rename to posthog/hogql_queries/actors_query_runner.py index 2b97a21811f65..b0fd3b96c1ae3 100644 --- a/posthog/hogql_queries/persons_query_runner.py +++ b/posthog/hogql_queries/actors_query_runner.py @@ -4,15 +4,15 @@ from posthog.hogql.parser import parse_expr, parse_order_expr from posthog.hogql.property import has_aggregation from posthog.hogql_queries.actor_strategies import ActorStrategy, PersonStrategy, GroupStrategy -from posthog.hogql_queries.insights.insight_persons_query_runner import InsightPersonsQueryRunner +from posthog.hogql_queries.insights.insight_actors_query_runner import InsightActorsQueryRunner from posthog.hogql_queries.insights.paginators import HogQLHasMorePaginator from posthog.hogql_queries.query_runner import QueryRunner, get_query_runner -from posthog.schema import PersonsQuery, PersonsQueryResponse +from posthog.schema import ActorsQuery, ActorsQueryResponse -class PersonsQueryRunner(QueryRunner): - query: PersonsQuery - query_type = PersonsQuery +class ActorsQueryRunner(QueryRunner): + query: ActorsQuery + query_type = ActorsQuery def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -28,7 +28,7 @@ def __init__(self, *args, **kwargs): @property def group_type_index(self) -> int | None: - if not self.source_query_runner or not isinstance(self.source_query_runner, InsightPersonsQueryRunner): + if not self.source_query_runner or not isinstance(self.source_query_runner, InsightActorsQueryRunner): return None return self.source_query_runner.group_type_index @@ -46,9 +46,9 @@ def enrich_with_actors(self, results, actor_column_index, actors_lookup) -> Gene new_row[actor_column_index] = actor if actor else {"id": actor_id} yield new_row - def calculate(self) -> PersonsQueryResponse: + def calculate(self) -> ActorsQueryResponse: response = self.paginator.execute_hogql_query( - query_type="PersonsQuery", + query_type="ActorsQuery", query=self.to_query(), team=self.team, timings=self.timings, @@ -65,7 +65,7 @@ def calculate(self) -> PersonsQueryResponse: missing_actors_count = len(self.paginator.results) - len(actors_lookup) results = self.enrich_with_actors(results, input_columns.index(column_name), actors_lookup) - return PersonsQueryResponse( + return ActorsQueryResponse( results=results, timings=response.timings, types=[t for _, t in response.types] if response.types else None, @@ -90,7 +90,7 @@ def source_id_column(self, source_query: ast.SelectQuery) -> List[str]: def source_table_join(self) -> ast.JoinExpr: assert self.source_query_runner is not None # For type checking - source_query = self.source_query_runner.to_persons_query() + source_query = self.source_query_runner.to_actors_query() source_id_chain = self.source_id_column(source_query) source_alias = "source" @@ -182,7 +182,7 @@ def to_query(self) -> ast.SelectQuery: return stmt - def to_persons_query(self) -> ast.SelectQuery: + def to_actors_query(self) -> ast.SelectQuery: return self.to_query() def _is_stale(self, cached_result_package): diff --git a/posthog/hogql_queries/hogql_query_runner.py b/posthog/hogql_queries/hogql_query_runner.py index 1a6bcc89c730c..853022c266aa0 100644 --- a/posthog/hogql_queries/hogql_query_runner.py +++ b/posthog/hogql_queries/hogql_query_runner.py @@ -37,7 +37,7 @@ def to_query(self) -> ast.SelectQuery: parsed_select = replace_filters(parsed_select, self.query.filters, self.team) return parsed_select - def to_persons_query(self) -> ast.SelectQuery: + def to_actors_query(self) -> ast.SelectQuery: return self.to_query() def calculate(self) -> HogQLQueryResponse: diff --git a/posthog/hogql_queries/insights/insight_persons_query_runner.py b/posthog/hogql_queries/insights/insight_actors_query_runner.py similarity index 79% rename from posthog/hogql_queries/insights/insight_persons_query_runner.py rename to posthog/hogql_queries/insights/insight_actors_query_runner.py index de14b029cc1ac..4a5c437824d7e 100644 --- a/posthog/hogql_queries/insights/insight_persons_query_runner.py +++ b/posthog/hogql_queries/insights/insight_actors_query_runner.py @@ -8,12 +8,12 @@ from posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner from posthog.hogql_queries.query_runner import QueryRunner, get_query_runner from posthog.models.filters.mixins.utils import cached_property -from posthog.schema import InsightPersonsQuery, HogQLQueryResponse +from posthog.schema import InsightActorsQuery, HogQLQueryResponse -class InsightPersonsQueryRunner(QueryRunner): - query: InsightPersonsQuery - query_type = InsightPersonsQuery +class InsightActorsQueryRunner(QueryRunner): + query: InsightActorsQuery + query_type = InsightActorsQuery @cached_property def source_runner(self) -> QueryRunner: @@ -24,17 +24,17 @@ def to_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: lifecycle_runner = cast(LifecycleQueryRunner, self.source_runner) day = self.query.day status = self.query.status - return lifecycle_runner.to_persons_query(day=day, status=status) + return lifecycle_runner.to_actors_query(day=day, status=status) elif isinstance(self.source_runner, TrendsQueryRunner): trends_runner = cast(TrendsQueryRunner, self.source_runner) - return trends_runner.to_persons_query() + return trends_runner.to_actors_query() elif isinstance(self.source_runner, RetentionQueryRunner): retention_runner = cast(RetentionQueryRunner, self.source_runner) - return retention_runner.to_persons_query(interval=self.query.interval) + return retention_runner.to_actors_query(interval=self.query.interval) raise ValueError(f"Cannot convert source query of type {self.query.source.kind} to persons query") - def to_persons_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: + def to_actors_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: return self.to_query() @property @@ -46,7 +46,7 @@ def group_type_index(self) -> int | None: def calculate(self) -> HogQLQueryResponse: return execute_hogql_query( - query_type="InsightPersonsQuery", + query_type="InsightActorsQuery", query=self.to_query(), team=self.team, timings=self.timings, diff --git a/posthog/hogql_queries/insights/lifecycle_query_runner.py b/posthog/hogql_queries/insights/lifecycle_query_runner.py index 92cf4e23704cb..2657b1cebc6a6 100644 --- a/posthog/hogql_queries/insights/lifecycle_query_runner.py +++ b/posthog/hogql_queries/insights/lifecycle_query_runner.py @@ -90,7 +90,7 @@ def to_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: ) return lifecycle_query - def to_persons_query( + def to_actors_query( self, day: Optional[str] = None, status: Optional[str] = None ) -> ast.SelectQuery | ast.SelectUnionQuery: with self.timings.measure("persons_query"): diff --git a/posthog/hogql_queries/insights/retention_query_runner.py b/posthog/hogql_queries/insights/retention_query_runner.py index 1920d70ee3d5e..0a2c7abb117c4 100644 --- a/posthog/hogql_queries/insights/retention_query_runner.py +++ b/posthog/hogql_queries/insights/retention_query_runner.py @@ -329,7 +329,7 @@ def calculate(self) -> RetentionQueryResponse: return RetentionQueryResponse(results=results, timings=response.timings, hogql=hogql) - def to_persons_query(self, interval: Optional[int] = None) -> ast.SelectQuery: + def to_actors_query(self, interval: Optional[int] = None) -> ast.SelectQuery: with self.timings.measure("retention_query"): retention_query = parse_select( """ diff --git a/posthog/hogql_queries/insights/test/test_insight_persons_query_runner.py b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py similarity index 85% rename from posthog/hogql_queries/insights/test/test_insight_persons_query_runner.py rename to posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py index 61afd1c3eae30..933c8fdf85114 100644 --- a/posthog/hogql_queries/insights/test/test_insight_persons_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_insight_actors_query_runner.py @@ -13,7 +13,7 @@ ) -class TestInsightPersonsQueryRunner(ClickhouseTestMixin, APIBaseTest): +class TestInsightActorsQueryRunner(ClickhouseTestMixin, APIBaseTest): maxDiff = None def _create_events(self, data, event="$pageview"): @@ -72,14 +72,14 @@ def test_insight_persons_lifecycle_query(self): response = self.select( """ select * from ( - - + + } series={[]} /> - - + + ) """, {"date_from": ast.Constant(value=date_from), "date_to": ast.Constant(value=date_to)}, @@ -99,15 +99,15 @@ def test_insight_persons_lifecycle_query_week_monday(self): response = self.select( """ select * from ( - - + + } series={[]} /> - - + + ) """, {"date_from": ast.Constant(value=date_from), "date_to": ast.Constant(value=date_to)}, @@ -127,15 +127,15 @@ def test_insight_persons_lifecycle_query_week_sunday(self): response = self.select( """ select * from ( - - + + } series={[]} /> - - + + ) """, {"date_from": ast.Constant(value=date_from), "date_to": ast.Constant(value=date_to)}, diff --git a/posthog/hogql_queries/insights/test/test_paginators.py b/posthog/hogql_queries/insights/test/test_paginators.py index 7954f35daf7f2..ac83efb45b353 100644 --- a/posthog/hogql_queries/insights/test/test_paginators.py +++ b/posthog/hogql_queries/insights/test/test_paginators.py @@ -6,10 +6,10 @@ ) from posthog.hogql.parser import parse_select from posthog.hogql_queries.insights.paginators import HogQLHasMorePaginator -from posthog.hogql_queries.persons_query_runner import PersonsQueryRunner +from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner from posthog.models.utils import UUIDT from posthog.schema import ( - PersonsQuery, + ActorsQuery, PersonPropertyFilter, PropertyOperator, ) @@ -49,8 +49,8 @@ def _create_random_persons(self) -> str: flush_persons_and_events() return random_uuid - def _create_runner(self, query: PersonsQuery) -> PersonsQueryRunner: - return PersonsQueryRunner(team=self.team, query=query) + def _create_runner(self, query: ActorsQuery) -> ActorsQueryRunner: + return ActorsQueryRunner(team=self.team, query=query) def setUp(self): super().setUp() @@ -58,14 +58,14 @@ def setUp(self): def test_persons_query_limit(self): runner = self._create_runner( - PersonsQuery(select=["properties.email"], orderBy=["properties.email DESC"], limit=1) + ActorsQuery(select=["properties.email"], orderBy=["properties.email DESC"], limit=1) ) response = runner.calculate() self.assertEqual(response.results, [[f"jacob9@{self.random_uuid}.posthog.com"]]) self.assertEqual(response.hasMore, True) runner = self._create_runner( - PersonsQuery( + ActorsQuery( select=["properties.email"], orderBy=["properties.email DESC"], limit=1, @@ -78,7 +78,7 @@ def test_persons_query_limit(self): def test_zero_limit(self): """Test behavior with limit set to zero.""" - runner = self._create_runner(PersonsQuery(select=["properties.email"], limit=0)) + runner = self._create_runner(ActorsQuery(select=["properties.email"], limit=0)) response = runner.calculate() self.assertEqual(runner.paginator.limit, 100) self.assertEqual(response.limit, 100) @@ -87,7 +87,7 @@ def test_zero_limit(self): def test_negative_limit(self): """Test behavior with negative limit value.""" - runner = self._create_runner(PersonsQuery(select=["properties.email"], limit=-1)) + runner = self._create_runner(ActorsQuery(select=["properties.email"], limit=-1)) response = runner.calculate() self.assertEqual(runner.paginator.limit, 100) self.assertEqual(response.limit, 100) @@ -96,7 +96,7 @@ def test_negative_limit(self): def test_exact_limit_match(self): """Test when available items equal the limit.""" - runner = self._create_runner(PersonsQuery(select=["properties.email"], limit=10)) + runner = self._create_runner(ActorsQuery(select=["properties.email"], limit=10)) response = runner.calculate() self.assertEqual(len(response.results), 10) self.assertFalse(response.hasMore) @@ -104,7 +104,7 @@ def test_exact_limit_match(self): def test_empty_result_set(self): """Test behavior when query returns no results.""" runner = self._create_runner( - PersonsQuery( + ActorsQuery( select=["properties.email"], limit=10, properties=[ @@ -119,14 +119,14 @@ def test_empty_result_set(self): def test_large_offset(self): """Test behavior with offset larger than the total number of items.""" self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery(select=["properties.email"], limit=5, offset=100)) + runner = self._create_runner(ActorsQuery(select=["properties.email"], limit=5, offset=100)) response = runner.calculate() self.assertEqual(len(response.results), 0) self.assertFalse(response.hasMore) def test_offset_plus_limit_exceeding_total(self): """Test when sum of offset and limit exceeds total items.""" - runner = self._create_runner(PersonsQuery(select=["properties.email"], limit=10, offset=5)) + runner = self._create_runner(ActorsQuery(select=["properties.email"], limit=10, offset=5)) response = runner.calculate() self.assertEqual(runner.paginator.offset, 5) self.assertEqual(len(response.results), 5) diff --git a/posthog/hogql_queries/insights/test/test_retention_query_runner.py b/posthog/hogql_queries/insights/test/test_retention_query_runner.py index eacf27a5021bf..999c93f57e71e 100644 --- a/posthog/hogql_queries/insights/test/test_retention_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_retention_query_runner.py @@ -11,7 +11,7 @@ TREND_FILTER_TYPE_EVENTS, ) from posthog.hogql_queries.insights.retention_query_runner import RetentionQueryRunner -from posthog.hogql_queries.persons_query_runner import PersonsQueryRunner +from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner from posthog.models import Action, ActionStep from posthog.test.base import ( APIBaseTest, @@ -74,13 +74,13 @@ def run_actors_query(self, interval, query): query["kind"] = "RetentionQuery" if not query.get("retentionFilter"): query["retentionFilter"] = {} - runner = PersonsQueryRunner( + runner = ActorsQueryRunner( team=self.team, query={ "select": ["person", "appearances"], "orderBy": ["length(appearances) DESC", "actor_id"], "source": { - "kind": "InsightPersonsQuery", + "kind": "InsightActorsQuery", "interval": interval, "source": query, }, diff --git a/posthog/hogql_queries/insights/trends/trends_query_runner.py b/posthog/hogql_queries/insights/trends/trends_query_runner.py index 25ca4a8870457..a2fd1b49bd0fc 100644 --- a/posthog/hogql_queries/insights/trends/trends_query_runner.py +++ b/posthog/hogql_queries/insights/trends/trends_query_runner.py @@ -98,7 +98,7 @@ def to_query(self) -> List[ast.SelectQuery]: return queries - def to_persons_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: + def to_actors_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: queries = [] with self.timings.measure("trends_persons_query"): for series in self.series: diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py index afe2b0aa84544..6dbb93b661fef 100644 --- a/posthog/hogql_queries/query_runner.py +++ b/posthog/hogql_queries/query_runner.py @@ -23,11 +23,11 @@ LifecycleQuery, WebTopClicksQuery, WebOverviewQuery, - PersonsQuery, + ActorsQuery, EventsQuery, WebStatsTableQuery, HogQLQuery, - InsightPersonsQuery, + InsightActorsQuery, DashboardFilter, HogQLQueryModifiers, RetentionQuery, @@ -78,9 +78,9 @@ class CachedQueryResponse(QueryResponse): HogQLQuery, TrendsQuery, LifecycleQuery, - InsightPersonsQuery, + InsightActorsQuery, EventsQuery, - PersonsQuery, + ActorsQuery, RetentionQuery, SessionsTimelineQuery, WebOverviewQuery, @@ -144,21 +144,21 @@ def get_query_runner( limit_context=limit_context, modifiers=modifiers, ) - if kind == "PersonsQuery": - from .persons_query_runner import PersonsQueryRunner + if kind == "ActorsQuery": + from .actors_query_runner import ActorsQueryRunner - return PersonsQueryRunner( - query=cast(PersonsQuery | Dict[str, Any], query), + return ActorsQueryRunner( + query=cast(ActorsQuery | Dict[str, Any], query), team=team, timings=timings, limit_context=limit_context, modifiers=modifiers, ) - if kind == "InsightPersonsQuery": - from .insights.insight_persons_query_runner import InsightPersonsQueryRunner + if kind == "InsightActorsQuery": + from .insights.insight_actors_query_runner import InsightActorsQueryRunner - return InsightPersonsQueryRunner( - query=cast(InsightPersonsQuery | Dict[str, Any], query), + return InsightActorsQueryRunner( + query=cast(InsightActorsQuery | Dict[str, Any], query), team=team, timings=timings, limit_context=limit_context, @@ -263,7 +263,7 @@ def run(self, refresh_requested: Optional[bool] = None) -> CachedQueryResponse: def to_query(self) -> ast.SelectQuery: raise NotImplementedError() - def to_persons_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: + def to_actors_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: # TODO: add support for selecting and filtering by breakdowns raise NotImplementedError() diff --git a/posthog/hogql_queries/sessions_timeline_query_runner.py b/posthog/hogql_queries/sessions_timeline_query_runner.py index 54f024900ff06..d920ec7cf94fd 100644 --- a/posthog/hogql_queries/sessions_timeline_query_runner.py +++ b/posthog/hogql_queries/sessions_timeline_query_runner.py @@ -122,7 +122,7 @@ def to_query(self) -> ast.SelectQuery: ) return cast(ast.SelectQuery, select_query) - def to_persons_query(self): + def to_actors_query(self): return parse_select( """SELECT DISTINCT person_id FROM {events_subquery}""", {"events_subquery": self._get_events_subquery()} ) diff --git a/posthog/hogql_queries/test/test_persons_query_runner.py b/posthog/hogql_queries/test/test_actors_query_runner.py similarity index 83% rename from posthog/hogql_queries/test/test_persons_query_runner.py rename to posthog/hogql_queries/test/test_actors_query_runner.py index e25bf67166b81..da9ea4ff35382 100644 --- a/posthog/hogql_queries/test/test_persons_query_runner.py +++ b/posthog/hogql_queries/test/test_actors_query_runner.py @@ -1,9 +1,9 @@ from posthog.hogql import ast from posthog.hogql.visitor import clear_locations -from posthog.hogql_queries.persons_query_runner import PersonsQueryRunner +from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner from posthog.models.utils import UUIDT from posthog.schema import ( - PersonsQuery, + ActorsQuery, PersonPropertyFilter, HogQLPropertyFilter, PropertyOperator, @@ -12,7 +12,7 @@ DateRange, EventsNode, IntervalType, - InsightPersonsQuery, + InsightActorsQuery, ) from posthog.test.base import ( APIBaseTest, @@ -25,7 +25,7 @@ from django.test import override_settings -class TestPersonsQueryRunner(ClickhouseTestMixin, APIBaseTest): +class TestActorsQueryRunner(ClickhouseTestMixin, APIBaseTest): maxDiff = None random_uuid: str @@ -52,15 +52,15 @@ def _create_random_persons(self) -> str: flush_persons_and_events() return random_uuid - def _create_runner(self, query: PersonsQuery) -> PersonsQueryRunner: - return PersonsQueryRunner(team=self.team, query=query) + def _create_runner(self, query: ActorsQuery) -> ActorsQueryRunner: + return ActorsQueryRunner(team=self.team, query=query) def setUp(self): super().setUp() def test_default_persons_query(self): self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery()) + runner = self._create_runner(ActorsQuery()) query = runner.to_query() query = clear_locations(query) @@ -86,7 +86,7 @@ def test_default_persons_query(self): def test_persons_query_properties(self): self.random_uuid = self._create_random_persons() runner = self._create_runner( - PersonsQuery( + ActorsQuery( properties=[ PersonPropertyFilter( key="random_uuid", @@ -102,7 +102,7 @@ def test_persons_query_properties(self): def test_persons_query_fixed_properties(self): self.random_uuid = self._create_random_persons() runner = self._create_runner( - PersonsQuery( + ActorsQuery( fixedProperties=[ PersonPropertyFilter( key="random_uuid", @@ -118,55 +118,55 @@ def test_persons_query_fixed_properties(self): def test_persons_query_search_email(self): self.random_uuid = self._create_random_persons() self._create_random_persons() - runner = self._create_runner(PersonsQuery(search=f"jacob4@{self.random_uuid}.posthog")) + runner = self._create_runner(ActorsQuery(search=f"jacob4@{self.random_uuid}.posthog")) self.assertEqual(len(runner.calculate().results), 1) - runner = self._create_runner(PersonsQuery(search=f"JACOB4@{self.random_uuid}.posthog")) + runner = self._create_runner(ActorsQuery(search=f"JACOB4@{self.random_uuid}.posthog")) self.assertEqual(len(runner.calculate().results), 1) def test_persons_query_search_name(self): self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery(search=f"Mr Jacob {self.random_uuid}")) + runner = self._create_runner(ActorsQuery(search=f"Mr Jacob {self.random_uuid}")) self.assertEqual(len(runner.calculate().results), 10) - runner = self._create_runner(PersonsQuery(search=f"MR JACOB {self.random_uuid}")) + runner = self._create_runner(ActorsQuery(search=f"MR JACOB {self.random_uuid}")) self.assertEqual(len(runner.calculate().results), 10) def test_persons_query_search_distinct_id(self): self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery(search=f"id-{self.random_uuid}-9")) + runner = self._create_runner(ActorsQuery(search=f"id-{self.random_uuid}-9")) self.assertEqual(len(runner.calculate().results), 1) - runner = self._create_runner(PersonsQuery(search=f"id-{self.random_uuid}-9")) + runner = self._create_runner(ActorsQuery(search=f"id-{self.random_uuid}-9")) self.assertEqual(len(runner.calculate().results), 1) def test_persons_query_aggregation_select_having(self): self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery(select=["properties.name", "count()"])) + runner = self._create_runner(ActorsQuery(select=["properties.name", "count()"])) results = runner.calculate().results self.assertEqual(results, [[f"Mr Jacob {self.random_uuid}", 10]]) def test_persons_query_order_by(self): self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery(select=["properties.email"], orderBy=["properties.email DESC"])) + runner = self._create_runner(ActorsQuery(select=["properties.email"], orderBy=["properties.email DESC"])) results = runner.calculate().results self.assertEqual(results[0], [f"jacob9@{self.random_uuid}.posthog.com"]) def test_persons_query_order_by_with_aliases(self): # We use the first column by default as an order key. It used to cause "error redefining alias" errors. self.random_uuid = self._create_random_persons() - runner = self._create_runner(PersonsQuery(select=["properties.email as email"])) + runner = self._create_runner(ActorsQuery(select=["properties.email as email"])) results = runner.calculate().results self.assertEqual(results[0], [f"jacob0@{self.random_uuid}.posthog.com"]) def test_persons_query_limit(self): self.random_uuid = self._create_random_persons() runner = self._create_runner( - PersonsQuery(select=["properties.email"], orderBy=["properties.email DESC"], limit=1) + ActorsQuery(select=["properties.email"], orderBy=["properties.email DESC"], limit=1) ) response = runner.calculate() self.assertEqual(response.results, [[f"jacob9@{self.random_uuid}.posthog.com"]]) self.assertEqual(response.hasMore, True) runner = self._create_runner( - PersonsQuery( + ActorsQuery( select=["properties.email"], orderBy=["properties.email DESC"], limit=1, @@ -181,7 +181,7 @@ def test_persons_query_limit(self): def test_source_hogql_query_poe_on(self): self.random_uuid = self._create_random_persons() source_query = HogQLQuery(query="SELECT distinct person_id FROM events WHERE event='clicky-4'") - query = PersonsQuery( + query = ActorsQuery( select=["properties.email"], orderBy=["properties.email DESC"], source=source_query, @@ -194,7 +194,7 @@ def test_source_hogql_query_poe_on(self): def test_source_hogql_query_poe_off(self): self.random_uuid = self._create_random_persons() source_query = HogQLQuery(query="SELECT distinct person_id FROM events WHERE event='clicky-4'") - query = PersonsQuery( + query = ActorsQuery( select=["properties.email"], orderBy=["properties.email DESC"], source=source_query, @@ -219,10 +219,10 @@ def test_source_lifecycle_query(self): interval=IntervalType.day, dateRange=DateRange(date_from="-7d"), ) - query = PersonsQuery( + query = ActorsQuery( select=["properties.email"], orderBy=["properties.email DESC"], - source=InsightPersonsQuery(source=source_query), + source=InsightActorsQuery(source=source_query), ) runner = self._create_runner(query) response = runner.calculate() diff --git a/posthog/schema.py b/posthog/schema.py index 4bdd25e88378d..f1d0df047b4b9 100644 --- a/posthog/schema.py +++ b/posthog/schema.py @@ -351,7 +351,7 @@ class NodeKind(str, Enum): PersonsNode = "PersonsNode" HogQLQuery = "HogQLQuery" HogQLMetadata = "HogQLMetadata" - PersonsQuery = "PersonsQuery" + ActorsQuery = "ActorsQuery" SessionsTimelineQuery = "SessionsTimelineQuery" DataTableNode = "DataTableNode" DataVisualizationNode = "DataVisualizationNode" @@ -363,7 +363,7 @@ class NodeKind(str, Enum): PathsQuery = "PathsQuery" StickinessQuery = "StickinessQuery" LifecycleQuery = "LifecycleQuery" - InsightPersonsQuery = "InsightPersonsQuery" + InsightActorsQuery = "InsightActorsQuery" WebOverviewQuery = "WebOverviewQuery" WebTopClicksQuery = "WebTopClicksQuery" WebStatsTableQuery = "WebStatsTableQuery" @@ -733,6 +733,21 @@ class WebTopClicksQueryResponse(BaseModel): types: Optional[List] = None +class ActorsQueryResponse(BaseModel): + model_config = ConfigDict( + extra="forbid", + ) + columns: List + hasMore: Optional[bool] = None + hogql: str + limit: int + missing_actors_count: Optional[int] = None + offset: int + results: List[List] + timings: Optional[List[QueryTiming]] = None + types: List[str] + + class AnyResponseTypeItem(BaseModel): model_config = ConfigDict( extra="forbid", @@ -943,21 +958,6 @@ class PersonPropertyFilter(BaseModel): value: Optional[Union[str, float, List[Union[str, float]]]] = None -class PersonsQueryResponse(BaseModel): - model_config = ConfigDict( - extra="forbid", - ) - columns: List - hasMore: Optional[bool] = None - hogql: str - limit: int - missing_actors_count: Optional[int] = None - offset: int - results: List[List] - timings: Optional[List[QueryTiming]] = None - types: List[str] - - class QueryResponse(BaseModel): model_config = ConfigDict( extra="forbid", @@ -1877,7 +1877,7 @@ class InsightVizNode(BaseModel): vizSpecificOptions: Optional[VizSpecificOptions] = None -class InsightPersonsQuery(BaseModel): +class InsightActorsQuery(BaseModel): model_config = ConfigDict( extra="forbid", ) @@ -1885,13 +1885,13 @@ class InsightPersonsQuery(BaseModel): interval: Optional[int] = Field( default=None, description="An interval selected out of available intervals in source query" ) - kind: Literal["InsightPersonsQuery"] = "InsightPersonsQuery" - response: Optional[PersonsQueryResponse] = None + kind: Literal["InsightActorsQuery"] = "InsightActorsQuery" + response: Optional[ActorsQueryResponse] = None source: Union[TrendsQuery, FunnelsQuery, RetentionQuery, PathsQuery, StickinessQuery, LifecycleQuery] status: Optional[str] = None -class PersonsQuery(BaseModel): +class ActorsQuery(BaseModel): model_config = ConfigDict( extra="forbid", ) @@ -1911,7 +1911,7 @@ class PersonsQuery(BaseModel): ] ] ] = None - kind: Literal["PersonsQuery"] = "PersonsQuery" + kind: Literal["ActorsQuery"] = "ActorsQuery" limit: Optional[int] = None offset: Optional[int] = None orderBy: Optional[List[str]] = None @@ -1931,10 +1931,10 @@ class PersonsQuery(BaseModel): ] ] ] = None - response: Optional[PersonsQueryResponse] = Field(default=None, description="Cached query response") + response: Optional[ActorsQueryResponse] = Field(default=None, description="Cached query response") search: Optional[str] = None select: Optional[List[str]] = None - source: Optional[Union[InsightPersonsQuery, HogQLQuery]] = None + source: Optional[Union[InsightActorsQuery, HogQLQuery]] = None class DataTableNode(BaseModel): @@ -1984,7 +1984,7 @@ class DataTableNode(BaseModel): EventsNode, EventsQuery, PersonsNode, - PersonsQuery, + ActorsQuery, HogQLQuery, TimeToSeeDataSessionsQuery, WebOverviewQuery, @@ -2013,8 +2013,8 @@ class QuerySchema(RootModel): PersonsNode, TimeToSeeDataSessionsQuery, EventsQuery, - PersonsQuery, - InsightPersonsQuery, + ActorsQuery, + InsightActorsQuery, SessionsTimelineQuery, HogQLQuery, HogQLMetadata, diff --git a/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py b/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py index f4b6135805845..57c7a8864193f 100644 --- a/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py +++ b/posthog/session_recordings/queries/session_recording_list_from_replay_summary.py @@ -151,7 +151,7 @@ def get_query(self) -> Tuple[str, Dict]: } -class PersonsQuery(EventQuery): +class ActorsQuery(EventQuery): _filter: SessionRecordingsFilter # we have to implement this from EventQuery but don't need it @@ -459,7 +459,7 @@ def get_query(self, select_event_ids: bool = False) -> Tuple[str, Dict[str, Any] ) def _persons_join_or_subquery(self, event_filters, prop_query): - persons_select, persons_select_params = PersonsQuery(filter=self._filter, team=self._team).get_query() + persons_select, persons_select_params = ActorsQuery(filter=self._filter, team=self._team).get_query() persons_join = "" persons_sub_query = "" if persons_select: @@ -632,7 +632,7 @@ def get_query(self) -> Tuple[str, Dict[str, Any]]: if events_select: events_select = f"AND s.session_id in (select `$session_id` as session_id from ({events_select}) as session_events_sub_query)" - persons_select, persons_select_params = PersonsQuery(filter=self._filter, team=self._team).get_query() + persons_select, persons_select_params = ActorsQuery(filter=self._filter, team=self._team).get_query() if persons_select: persons_select = ( f"AND s.distinct_id in (select distinct_id from ({persons_select}) as session_persons_sub_query)"