Skip to content

Commit

Permalink
HogQLQueryResponse results -> result, in line with other response types
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Sep 28, 2023
1 parent fdb32e2 commit 305b59e
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const versionCheckerLogic = kea<versionCheckerLogicType>([
const res = await api.query(query)

return (
res.results?.map((x) => ({
res.result?.map((x) => ({
version: x[0],
timestamp: x[1],
})) ?? null
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/nodes/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
}
footer={
canLoadNextData &&
((response as any).results.length > 0 || !responseLoading) && (
((response as any).result.length > 0 || !responseLoading) && (
<LoadNext query={query.source} />
)
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/queries/nodes/DataTable/dataTableLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export const dataTableLogic = kea<dataTableLogicType>([
}))
}

return response && 'results' in response && Array.isArray(response.results)
? response.results.map((result: any) => ({ result })) ?? null
return response && 'result' in response && Array.isArray(response.result)
? response.result.map((result: any) => ({ result })) ?? null
: null
},
],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@
"query": {
"type": "string"
},
"results": {
"result": {
"items": {},
"type": "array"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export interface HogQLQueryResponse {
query?: string
hogql?: string
clickhouse?: string
results?: any[]
result?: any[]
types?: any[]
columns?: any[]
timings?: QueryTiming[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const sessionRecordingsListPropertiesLogic = kea<sessionRecordingsListPro
actions.reportRecordingsListPropertiesFetched(loadTimeMs)

breakpoint()
return (response.results || []).map(
return (response.result || []).map(
(x: any): SessionRecordingPropertiesType => ({
id: x[0],
properties: JSON.parse(x[1] || '{}'),
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/functions/test/test_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_in_cohort_dynamic(self):
response.hogql,
f"SELECT event FROM events WHERE and(in(person_id, (SELECT person_id FROM cohort_people WHERE equals(cohort_id, {cohort.pk}) GROUP BY person_id, cohort_id, version HAVING greater(sum(sign), 0))), equals(event, '{random_uuid}')) LIMIT 100",
)
self.assertEqual(len(response.results), 1)
self.assertEqual(len(response.result), 1)
self.assertEqual(response.results[0][0], random_uuid)

@override_settings(PERSON_ON_EVENTS_OVERRIDE=True, PERSON_ON_EVENTS_V2_OVERRIDE=True)
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/functions/test/test_sparkline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_sparkline(self):
response.hogql,
f"SELECT tuple('__hogql_chart_type', 'sparkline', 'results', [1, 2, 3]) LIMIT 100",
)
self.assertEqual(response.results[0][0], ("__hogql_chart_type", "sparkline", "results", [1, 2, 3]))
self.assertEqual(response.result[0][0], ("__hogql_chart_type", "sparkline", "results", [1, 2, 3]))

def test_sparkline_error(self):
with self.assertRaises(HogQLException) as e:
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def execute_hogql_query(
hogql=hogql,
clickhouse=clickhouse_sql,
timings=timings.to_list(),
results=results,
result=results,
columns=print_columns,
types=types,
)
12 changes: 6 additions & 6 deletions posthog/hogql/test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def test_hogql_lambdas(self):
"SELECT arrayMap(x -> x * 2, [1, 2, 3]), 1",
team=self.team,
)
self.assertEqual(response.results, [([2, 4, 6], 1)])
self.assertEqual(response.result, [([2, 4, 6], 1)])
self.assertEqual(
response.clickhouse,
f"SELECT arrayMap(x -> multiply(x, 2), [1, 2, 3]), 1 LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=True",
Expand All @@ -686,7 +686,7 @@ def test_hogql_arrays(self):
team=self.team,
)
# Following SQL tradition, ClickHouse array indexes start at 1, not from zero.
self.assertEqual(response.results, [([1, 2, 3], 10)])
self.assertEqual(response.result, [([1, 2, 3], 10)])
self.assertEqual(
response.clickhouse,
f"SELECT [1, 2, 3], [10, 11, 12][1] LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=True",
Expand Down Expand Up @@ -1432,7 +1432,7 @@ def test_view_link(self):

response = execute_hogql_query("SELECT event_view.fake FROM events", team=self.team)

self.assertEqual(response.results, [("bla",), ("bla",), ("bla",), ("bla",)])
self.assertEqual(response.result, [("bla",), ("bla",), ("bla",), ("bla",)])

def test_hogql_query_filters(self):
with freeze_time("2020-01-10"):
Expand Down Expand Up @@ -1470,11 +1470,11 @@ def test_hogql_query_filters(self):
response.clickhouse,
f"SELECT events.event, events.distinct_id FROM events WHERE and(equals(events.team_id, {self.team.pk}), equals(events.distinct_id, %(hogql_val_0)s), and(ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_1)s), ''), 'null'), '^\"|\"$', ''), %(hogql_val_2)s), 0), ifNull(less(toTimeZone(events.timestamp, %(hogql_val_3)s), toDateTime64('2020-01-02 00:00:00.000000', 6, 'UTC')), 0), ifNull(greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_4)s), toDateTime64('2020-01-01 00:00:00.000000', 6, 'UTC')), 0))) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=True",
)
self.assertEqual(len(response.results), 0)
self.assertEqual(len(response.result), 0)

filters.dateRange = DateRange(date_from="2020-01-01", date_to="2020-02-02")
response = execute_hogql_query(query, team=self.team, filters=filters, placeholders=placeholders)
self.assertEqual(len(response.results), 1)
self.assertEqual(len(response.result), 1)

def test_hogql_query_filters_empty_true(self):
query = "SELECT event from events where {filters}"
Expand Down Expand Up @@ -1508,7 +1508,7 @@ def test_hogql_query_filters_alias(self):
response.clickhouse,
f"SELECT e.event, e.distinct_id FROM events AS e WHERE and(equals(e.team_id, {self.team.pk}), ifNull(equals(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, %(hogql_val_0)s), ''), 'null'), '^\"|\"$', ''), %(hogql_val_1)s), 0)) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=True",
)
self.assertEqual(len(response.results), 2)
self.assertEqual(len(response.result), 2)

def test_hogql_union_all_limits(self):
query = "SELECT event FROM events UNION ALL SELECT event FROM events"
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/lifecycle_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def calculate(self):

# ensure that the items are in a deterministic order
order = {"new": 1, "returning": 2, "resurrecting": 3, "dormant": 4}
results = sorted(response.results, key=lambda result: order.get(result[2], 5))
results = sorted(response.result, key=lambda result: order.get(result[2], 5))

res = []
for val in results:
Expand Down
4 changes: 2 additions & 2 deletions posthog/hogql_queries/trends_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def calculate(self):
return TrendsQueryResponse(result=res, timings=timings)

def build_series_response(self, response: HogQLQueryResponse, series: SeriesWithExtras):
if response.results is None:
if response.result is None:
return []

res = []
for val in response.results:
for val in response.result:
series_object = {
"data": val[1],
"labels": [item.strftime("%-d-%b-%Y") for item in val[0]], # Add back in hour formatting
Expand Down
2 changes: 1 addition & 1 deletion posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class HogQLQueryResponse(BaseModel):
columns: Optional[List] = None
hogql: Optional[str] = None
query: Optional[str] = None
results: Optional[List] = None
result: Optional[List] = None
timings: Optional[List[QueryTiming]] = None
types: Optional[List] = None

Expand Down

0 comments on commit 305b59e

Please sign in to comment.