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

fix(queries): standardise on "results" over "result" #17798

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
24 changes: 12 additions & 12 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@
"next_allowed_client_refresh": {
"type": "string"
},
"result": {
"results": {
"items": {
"type": "object"
},
Expand All @@ -1437,7 +1437,7 @@
"type": "array"
}
},
"required": ["result"],
"required": ["results"],
"type": "object"
},
"LifecycleToggle": {
Expand Down Expand Up @@ -2288,7 +2288,7 @@
"next_allowed_client_refresh": {
"type": "string"
},
"result": {
"results": {
"items": {
"type": "object"
},
Expand All @@ -2301,7 +2301,7 @@
"type": "array"
}
},
"required": ["result"],
"required": ["results"],
"type": "object"
},
"WebAnalyticsFilters": {},
Expand Down Expand Up @@ -2341,7 +2341,7 @@
"next_allowed_client_refresh": {
"type": "string"
},
"result": {
"results": {
"items": {},
"type": "array"
},
Expand All @@ -2356,7 +2356,7 @@
"type": "array"
}
},
"required": ["result"],
"required": ["results"],
"type": "object"
},
"WebTopClicksQuery": {
Expand Down Expand Up @@ -2395,7 +2395,7 @@
"next_allowed_client_refresh": {
"type": "string"
},
"result": {
"results": {
"items": {},
"type": "array"
},
Expand All @@ -2410,7 +2410,7 @@
"type": "array"
}
},
"required": ["result"],
"required": ["results"],
"type": "object"
},
"WebTopPagesQuery": {
Expand Down Expand Up @@ -2449,7 +2449,7 @@
"next_allowed_client_refresh": {
"type": "string"
},
"result": {
"results": {
"items": {},
"type": "array"
},
Expand All @@ -2464,7 +2464,7 @@
"type": "array"
}
},
"required": ["result"],
"required": ["results"],
"type": "object"
},
"WebTopSourcesQuery": {
Expand Down Expand Up @@ -2503,7 +2503,7 @@
"next_allowed_client_refresh": {
"type": "string"
},
"result": {
"results": {
"items": {},
"type": "array"
},
Expand All @@ -2518,7 +2518,7 @@
"type": "array"
}
},
"required": ["result"],
"required": ["results"],
"type": "object"
}
}
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export type TrendsFilter = Omit<
>

export interface TrendsQueryResponse extends QueryResponse {
result: Record<string, any>[]
results: Record<string, any>[]
}

export interface TrendsQuery extends InsightsQueryBase {
Expand Down Expand Up @@ -486,15 +486,15 @@ export type LifecycleFilter = Omit<LifecycleFilterType, keyof FilterType> & {
} // using everything except what it inherits from FilterType

export interface QueryResponse {
result: unknown
results: unknown
timings?: QueryTiming[]
is_cached?: boolean
last_refresh?: string
next_allowed_client_refresh?: string
}

export interface LifecycleQueryResponse extends QueryResponse {
result: Record<string, any>[]
results: Record<string, any>[]
}

export interface LifecycleQuery extends InsightsQueryBase {
Expand All @@ -521,7 +521,7 @@ export interface WebOverviewStatsQuery extends WebAnalyticsQueryBase {
}

export interface WebOverviewStatsQueryResponse extends QueryResponse {
result: unknown[]
results: unknown[]
types?: unknown[]
columns?: unknown[]
}
Expand All @@ -531,7 +531,7 @@ export interface WebTopSourcesQuery extends WebAnalyticsQueryBase {
response?: WebTopSourcesQueryResponse
}
export interface WebTopSourcesQueryResponse extends QueryResponse {
result: unknown[]
results: unknown[]
types?: unknown[]
columns?: unknown[]
}
Expand All @@ -542,7 +542,7 @@ export interface WebTopClicksQuery extends WebAnalyticsQueryBase {
response?: WebTopClicksQueryResponse
}
export interface WebTopClicksQueryResponse extends QueryResponse {
result: unknown[]
results: unknown[]
types?: unknown[]
columns?: unknown[]
}
Expand All @@ -553,7 +553,7 @@ export interface WebTopPagesQuery extends WebAnalyticsQueryBase {
response?: WebTopPagesQueryResponse
}
export interface WebTopPagesQueryResponse extends QueryResponse {
result: unknown[]
results: unknown[]
types?: unknown[]
columns?: unknown[]
}
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/scenes/insights/insightDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const insightDataLogic = kea<insightDataLogicType>([
dataNodeLogic({ key: insightVizDataNodeKey(props) } as DataNodeLogicProps),
[
'query as insightQuery',
'response as insightData',
'response as insightDataRaw',
'dataLoading as insightDataLoading',
'responseErrorObject as insightDataError',
'getInsightRefreshButtonDisabledReason',
Expand Down Expand Up @@ -147,6 +147,14 @@ export const insightDataLogic = kea<insightDataLogicType>([
}
},
],

insightData: [
(s) => [s.insightDataRaw],
(insightDataRaw): Record<string, any> => {
// :TRICKY: The queries return reuslts as `results`, but insights expect `result`
mariusandra marked this conversation as resolved.
Show resolved Hide resolved
return { ...insightDataRaw, result: insightDataRaw?.results ?? insightDataRaw?.result }
},
],
}),

listeners(({ actions, values }) => ({
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/insights/lifecycle_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def calculate(self):
}
)

return LifecycleQueryResponse(result=res, timings=response.timings)
return LifecycleQueryResponse(results=res, timings=response.timings)

@cached_property
def query_date_range(self):
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/insights/trends_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def calculate(self):
if self.query.trendsFilter is not None and self.query.trendsFilter.formula is not None:
res = self.apply_formula(self.query.trendsFilter.formula, res)

return TrendsQueryResponse(result=res, timings=timings)
return TrendsQueryResponse(results=res, timings=timings)

def build_series_response(self, response: HogQLQueryResponse, series: SeriesWithExtras):
if response.results is None:
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class QueryResponse(BaseModel, Generic[DataT]):
model_config = ConfigDict(
extra="forbid",
)
result: DataT
results: DataT
timings: Optional[List[QueryTiming]] = None
types: Optional[List[Tuple[str, str]]] = None
columns: Optional[List[str]] = None
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/test/test_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestQueryRunner(QueryRunner):
query_type = query_class

def calculate(self) -> QueryResponse:
return QueryResponse(result=list())
return QueryResponse(results=list())

def _refresh_frequency(self) -> timedelta:
return timedelta(minutes=4)
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/web_analytics/overview_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def calculate(self):
)

return WebOverviewStatsQueryResponse(
columns=response.columns, result=response.results, timings=response.timings, types=response.types
columns=response.columns, results=response.results, timings=response.timings, types=response.types
)

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/web_analytics/top_clicks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def calculate(self):
)

return WebTopClicksQueryResponse(
columns=response.columns, result=response.results, timings=response.timings, types=response.types
columns=response.columns, results=response.results, timings=response.timings, types=response.types
)

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/web_analytics/top_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def calculate(self):
)

return WebTopPagesQueryResponse(
columns=response.columns, result=response.results, timings=response.timings, types=response.types
columns=response.columns, results=response.results, timings=response.timings, types=response.types
)

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/web_analytics/top_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def calculate(self):
)

return WebTopSourcesQueryResponse(
columns=response.columns, result=response.results, timings=response.timings, types=response.types
columns=response.columns, results=response.results, timings=response.timings, types=response.types
)

@cached_property
Expand Down
12 changes: 6 additions & 6 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class TrendsQueryResponse(BaseModel):
is_cached: Optional[bool] = None
last_refresh: Optional[str] = None
next_allowed_client_refresh: Optional[str] = None
result: List[Dict[str, Any]]
results: List[Dict[str, Any]]
timings: Optional[List[QueryTiming]] = None


Expand All @@ -476,7 +476,7 @@ class WebOverviewStatsQueryResponse(BaseModel):
is_cached: Optional[bool] = None
last_refresh: Optional[str] = None
next_allowed_client_refresh: Optional[str] = None
result: List
results: List
timings: Optional[List[QueryTiming]] = None
types: Optional[List] = None

Expand All @@ -489,7 +489,7 @@ class WebTopClicksQueryResponse(BaseModel):
is_cached: Optional[bool] = None
last_refresh: Optional[str] = None
next_allowed_client_refresh: Optional[str] = None
result: List
results: List
timings: Optional[List[QueryTiming]] = None
types: Optional[List] = None

Expand All @@ -502,7 +502,7 @@ class WebTopPagesQueryResponse(BaseModel):
is_cached: Optional[bool] = None
last_refresh: Optional[str] = None
next_allowed_client_refresh: Optional[str] = None
result: List
results: List
timings: Optional[List[QueryTiming]] = None
types: Optional[List] = None

Expand All @@ -515,7 +515,7 @@ class WebTopSourcesQueryResponse(BaseModel):
is_cached: Optional[bool] = None
last_refresh: Optional[str] = None
next_allowed_client_refresh: Optional[str] = None
result: List
results: List
timings: Optional[List[QueryTiming]] = None
types: Optional[List] = None

Expand Down Expand Up @@ -669,7 +669,7 @@ class LifecycleQueryResponse(BaseModel):
is_cached: Optional[bool] = None
last_refresh: Optional[str] = None
next_allowed_client_refresh: Optional[str] = None
result: List[Dict[str, Any]]
results: List[Dict[str, Any]]
timings: Optional[List[QueryTiming]] = None


Expand Down