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

feat(hogql): Events table based on hogql #14315

Merged
merged 209 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 193 commits
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
7e44195
feat(hogql): select statements
mariusandra Feb 8, 2023
a87115f
visitor
mariusandra Feb 8, 2023
c55f170
cleanup
mariusandra Feb 8, 2023
d47bc61
parse limit by
mariusandra Feb 8, 2023
839d505
parse limit by
mariusandra Feb 8, 2023
fef9463
merge limit clauses
mariusandra Feb 8, 2023
9cd96bc
Update snapshots
github-actions[bot] Feb 8, 2023
2d0d1e8
fix placeholders
mariusandra Feb 8, 2023
5064dad
resolve symbols for events table
mariusandra Feb 9, 2023
62dd464
resolve aliases
mariusandra Feb 9, 2023
6c04d20
refactor column and table aliases
mariusandra Feb 9, 2023
c550147
column resolver
mariusandra Feb 9, 2023
2253f41
make sure some things error
mariusandra Feb 9, 2023
a006872
annotate
mariusandra Feb 9, 2023
b7b5521
constants
mariusandra Feb 9, 2023
60376dd
simple sql query
mariusandra Feb 9, 2023
9683e92
Update snapshots
github-actions[bot] Feb 9, 2023
ac3048e
introduce "print name"
mariusandra Feb 10, 2023
86ddae5
visit_unknown
mariusandra Feb 10, 2023
c48024c
basic printer via a visitor
mariusandra Feb 10, 2023
afe485d
completely redo printing
mariusandra Feb 13, 2023
761a398
Merge branch 'hogql-symbol-resolution' of github.com:PostHog/posthog …
mariusandra Feb 13, 2023
fb35bc7
Merge branch 'master' into hogql-further-improvements
mariusandra Feb 13, 2023
8af1c79
Merge branch 'hogql-further-improvements' into hogql-symbol-resolution
mariusandra Feb 13, 2023
076916e
some sample queries
mariusandra Feb 13, 2023
f1cbd94
Merge branch 'master' into hogql-symbol-resolution
mariusandra Feb 13, 2023
fd271dd
query tests
mariusandra Feb 13, 2023
b41055e
test selecting from persons and distinct id table
mariusandra Feb 13, 2023
309a764
document current join ast
mariusandra Feb 13, 2023
592a18c
children, joins and aliases
mariusandra Feb 13, 2023
72da1d9
turn joins around
mariusandra Feb 13, 2023
54e5539
get some actual joins working
mariusandra Feb 13, 2023
95b6a5e
query aliases
mariusandra Feb 13, 2023
da83eec
errors, cleanup, recordings
mariusandra Feb 13, 2023
2e27c1e
resolver tests
mariusandra Feb 14, 2023
78caa57
cleanup
mariusandra Feb 14, 2023
48f684f
more tiny cleanup
mariusandra Feb 14, 2023
5cea7bd
resolver cleanup
mariusandra Feb 14, 2023
9e995fb
bit of printer cleanup
mariusandra Feb 14, 2023
0522eb5
Merge branch 'master' into hogql-symbol-resolution
mariusandra Feb 14, 2023
166e7fe
placeholders in query
mariusandra Feb 14, 2023
2287c07
changes
mariusandra Feb 14, 2023
92983fb
person properties fake table
mariusandra Feb 14, 2023
66b47ab
pass two more tests
mariusandra Feb 14, 2023
fa22ddd
legacy person properties
mariusandra Feb 15, 2023
3004248
Update snapshots
github-actions[bot] Feb 15, 2023
e7efe0a
Update snapshots
github-actions[bot] Feb 15, 2023
b075bc2
simple splash and table property printing
mariusandra Feb 15, 2023
74957e0
Merge remote-tracking branch 'origin/hogql-symbol-resolution' into ho…
mariusandra Feb 15, 2023
e59ef94
Update snapshots
github-actions[bot] Feb 15, 2023
f095fec
fix pp
mariusandra Feb 15, 2023
ff60757
Merge remote-tracking branch 'origin/hogql-symbol-resolution' into ho…
mariusandra Feb 15, 2023
4715e8a
revert what was different about hogql access logs
mariusandra Feb 15, 2023
07204aa
explicit names for person non properties
mariusandra Feb 15, 2023
1002382
consolidate into print_ast
mariusandra Feb 15, 2023
1d681f8
merge symbol printer into printer
mariusandra Feb 15, 2023
b32cb4b
move it up
mariusandra Feb 15, 2023
425a02e
Update snapshots
github-actions[bot] Feb 15, 2023
0d17eb7
Update snapshots
github-actions[bot] Feb 15, 2023
4851b8f
Update snapshots
github-actions[bot] Feb 15, 2023
d17d725
basic hogql node
mariusandra Feb 16, 2023
cc17eff
no need to discard resolved symbols... we use them again and again
mariusandra Feb 16, 2023
f3e7900
actual sql editor
mariusandra Feb 16, 2023
d731524
hide query editor if opening a hogql table
mariusandra Feb 16, 2023
0759e08
Update snapshots
github-actions[bot] Feb 16, 2023
5605a94
Update snapshots
github-actions[bot] Feb 16, 2023
1b02f02
query into snapshot data
mariusandra Feb 16, 2023
b59cf91
splash expander
mariusandra Feb 16, 2023
5cf6e77
code quality issues
mariusandra Feb 16, 2023
af86159
Merge branch 'hogql-node' into hogql-transforms
mariusandra Feb 16, 2023
44ff1a4
error if unexpected splash
mariusandra Feb 16, 2023
fdf1861
bandage
mariusandra Feb 16, 2023
a0e0dce
lazy table joins
mariusandra Feb 16, 2023
750f165
test
mariusandra Feb 16, 2023
aee30ae
pdi for session_recording_events
mariusandra Feb 16, 2023
b8f1793
Update snapshots
github-actions[bot] Feb 16, 2023
5d015fd
replace old fake table joins with lazy table joins - resolver makes s…
mariusandra Feb 19, 2023
66a0e05
access joined subtables correctly
mariusandra Feb 19, 2023
8763040
resolve lazy tables
mariusandra Feb 19, 2023
b97bcc6
fix bug
mariusandra Feb 19, 2023
1978c27
add groups table
mariusandra Feb 19, 2023
f81e9fe
support intervals
mariusandra Feb 19, 2023
4c0e109
prettier for sql
mariusandra Feb 19, 2023
3fd47f4
prettier for sql
mariusandra Feb 19, 2023
d6b8d3e
add failing test
mariusandra Feb 19, 2023
f72bf63
support dollars
mariusandra Feb 19, 2023
e24402d
events query via hogql as its base
mariusandra Feb 20, 2023
2f7d3df
Merge branch 'master' into hogql-symbol-resolution
mariusandra Feb 20, 2023
947e7bf
asterisk and obelisk
mariusandra Feb 20, 2023
74bf09c
yeet
mariusandra Feb 20, 2023
d8eb091
class is for internal use only
mariusandra Feb 20, 2023
9f1ae92
fix aliases
mariusandra Feb 20, 2023
c767159
not needed
mariusandra Feb 20, 2023
e496907
fix a few fields
mariusandra Feb 20, 2023
b5cd169
Merge branch 'hogql-symbol-resolution' into hogql-node
mariusandra Feb 20, 2023
4e3830c
pretty printing
mariusandra Feb 20, 2023
b25fd20
update sample query
mariusandra Feb 20, 2023
bf29398
Update snapshots
github-actions[bot] Feb 20, 2023
f21c928
update sample query
mariusandra Feb 20, 2023
b35777f
Update snapshots
github-actions[bot] Feb 20, 2023
7271431
fix webpack build for storybook
mariusandra Feb 21, 2023
edcbbb6
Merge remote-tracking branch 'origin/hogql-node' into hogql-node
mariusandra Feb 21, 2023
c05d7b0
Merge branch 'hogql-node' into hogql-transforms
mariusandra Feb 21, 2023
55ba79e
asterisks work again
mariusandra Feb 21, 2023
f739980
Update snapshots
github-actions[bot] Feb 21, 2023
02468b7
test splotch desplotcher
mariusandra Feb 21, 2023
88d1a19
Merge branch 'hogql-transforms' of github.com:PostHog/posthog into ho…
mariusandra Feb 21, 2023
2ad909c
Merge branch 'hogql-transforms' into person-table-joins
mariusandra Feb 21, 2023
837ff1d
fix test
mariusandra Feb 21, 2023
ecdc8ae
field traverser
mariusandra Feb 21, 2023
36c5491
Merge branch 'master' into hogql-node
mariusandra Feb 21, 2023
e844256
revert tiny changes lost in merge
mariusandra Feb 21, 2023
3ef7f29
Merge branch 'hogql-node' into hogql-transforms
mariusandra Feb 21, 2023
59ac65f
Merge branch 'master' into hogql-node
mariusandra Feb 21, 2023
8fc4e70
Merge branch 'hogql-node' into hogql-transforms
mariusandra Feb 21, 2023
69b78be
Merge branch 'hogql-transforms' into person-table-joins
mariusandra Feb 21, 2023
986aa91
make sure lazy tables also get resolved
mariusandra Feb 21, 2023
98e05c2
get rid of field access logs
mariusandra Feb 21, 2023
e7c38ff
fix bad merge
mariusandra Feb 21, 2023
a6836f7
switch to explicit materialised person props
mariusandra Feb 21, 2023
7c0ff20
revert
mariusandra Feb 21, 2023
aa8eed7
mat column does not make sense in this context on this field
mariusandra Feb 21, 2023
83107f5
few fixes
mariusandra Feb 21, 2023
a87a737
indicate legacy queries
mariusandra Feb 21, 2023
3150c50
move the kludge
mariusandra Feb 21, 2023
5530a5e
move the kludge
mariusandra Feb 21, 2023
b4cc8f2
Merge branch 'master' into hogql-transforms
mariusandra Feb 22, 2023
b7b60c2
Merge branch 'hogql-transforms' into person-table-joins
mariusandra Feb 22, 2023
0456203
support nested splotches
mariusandra Feb 22, 2023
4d97e25
Merge branch 'hogql-transforms' into person-table-joins
mariusandra Feb 22, 2023
873b54c
actually fix the test
mariusandra Feb 22, 2023
5112392
Merge branch 'hogql-transforms' into person-table-joins
mariusandra Feb 22, 2023
6199e2a
fix person properties if part of a legacy insight context
mariusandra Feb 22, 2023
10b9339
also if PoE is on
mariusandra Feb 22, 2023
52334ce
not exposing team_id
mariusandra Feb 22, 2023
940f294
lazy table tests and split files
mariusandra Feb 22, 2023
a2dcdd6
Merge branch 'master' into person-table-joins
mariusandra Feb 22, 2023
2e75217
simplify
mariusandra Feb 22, 2023
ef8d352
example
mariusandra Feb 22, 2023
d8a4791
feat(hogql): support intervals
mariusandra Feb 22, 2023
0e23667
Merge branch 'hogql-interval' into person-table-joins
mariusandra Feb 22, 2023
bde6e9f
rename
mariusandra Feb 22, 2023
f8669d4
this file was split in two
mariusandra Feb 22, 2023
6e3844b
not adding this yet
mariusandra Feb 22, 2023
02602c2
klean kludge
mariusandra Feb 22, 2023
d3bb2cd
explicitly no funny business with the title
mariusandra Feb 22, 2023
b40c41f
best guess JSON parsing
mariusandra Feb 22, 2023
2eddaae
remove funny changes
mariusandra Feb 22, 2023
057e654
remove funny changes
mariusandra Feb 22, 2023
b45811f
rename joined table to lazy table
mariusandra Feb 22, 2023
030c1dc
refactor
mariusandra Feb 22, 2023
d796232
rename field for clarity
mariusandra Feb 22, 2023
e7599f3
easier this way
mariusandra Feb 22, 2023
5024a42
more comments and renames
mariusandra Feb 22, 2023
fe582b4
keep name in alignment with other similar objects, remove code that's…
mariusandra Feb 22, 2023
9d1cb00
reduce duplication
mariusandra Feb 22, 2023
9a51249
put it back, too much noise to remove
mariusandra Feb 22, 2023
70a5338
add virtual tables
mariusandra Feb 22, 2023
417682a
test for selecting from "poe"
mariusandra Feb 23, 2023
30589c9
Merge branch 'master' into person-table-joins
mariusandra Feb 23, 2023
3e5b96e
Update snapshots
github-actions[bot] Feb 23, 2023
8c58dcd
Like -> Base
mariusandra Feb 23, 2023
e549890
Merge branch 'person-table-joins' into events-table-based-on-hogql
mariusandra Feb 23, 2023
bcb305c
add back person select
mariusandra Feb 23, 2023
2eced41
remove old query, fix person handling
mariusandra Feb 23, 2023
541bb84
default limit to 100
mariusandra Feb 23, 2023
065455f
only for events that exist
mariusandra Feb 23, 2023
00f3e94
few comments
mariusandra Feb 23, 2023
2871291
fix ordering
mariusandra Feb 23, 2023
7818492
Update snapshots
github-actions[bot] Feb 23, 2023
0f8962c
way too eager
mariusandra Feb 23, 2023
003bc23
Merge remote-tracking branch 'origin/events-table-based-on-hogql' int…
mariusandra Feb 23, 2023
5648df4
Update snapshots
github-actions[bot] Feb 23, 2023
10c68c7
Update snapshots
github-actions[bot] Feb 23, 2023
f24b593
test for order_expr parsing
mariusandra Feb 23, 2023
74f6d33
make the order predictable
mariusandra Feb 23, 2023
9420e36
Merge branch 'events-table-based-on-hogql' of github.com:PostHog/post…
mariusandra Feb 23, 2023
ff9c5aa
support property groups
mariusandra Feb 23, 2023
f59b8c5
support property groups
mariusandra Feb 23, 2023
8a43443
support all comparisons
mariusandra Feb 23, 2023
09ac7bb
action_to_expr
mariusandra Feb 23, 2023
d68df6f
nicer property tests
mariusandra Feb 24, 2023
53fa484
simplify if command, add not
mariusandra Feb 24, 2023
918e7be
elements filter
mariusandra Feb 24, 2023
c04a5e0
tag-name only supports is_not and exact
mariusandra Feb 24, 2023
20610dd
fix typing
mariusandra Feb 24, 2023
092bd0c
Update snapshots
github-actions[bot] Feb 24, 2023
48ffb25
tests for elements regex
mariusandra Feb 24, 2023
272915f
better tests
mariusandra Feb 24, 2023
4d01276
has_aggregation test
mariusandra Feb 24, 2023
31d883b
test action steps
mariusandra Feb 24, 2023
8cdb4d6
remove pass
mariusandra Feb 24, 2023
5ac1c39
Merge remote-tracking branch 'origin/events-table-based-on-hogql' int…
mariusandra Feb 24, 2023
176ed16
fix old call
mariusandra Feb 24, 2023
ab2c994
array values
mariusandra Feb 24, 2023
c5e27fe
Merge branch 'master' into person-table-joins
mariusandra Feb 24, 2023
f288e68
small fixes
mariusandra Feb 24, 2023
5775ab2
Merge branch 'person-table-joins' into events-table-based-on-hogql
mariusandra Feb 24, 2023
e76a85b
Update snapshots
github-actions[bot] Feb 24, 2023
c02edcb
Merge branch 'master' into person-table-joins
mariusandra Feb 24, 2023
165e691
Merge branch 'person-table-joins' into events-table-based-on-hogql
mariusandra Feb 24, 2023
182ff11
Merge branch 'master' into events-table-based-on-hogql
mariusandra Feb 28, 2023
f176dff
Update query snapshots
github-actions[bot] Feb 28, 2023
547463d
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 28, 2023
f8dd9c1
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 28, 2023
7ef5272
Merge branch 'master' into events-table-based-on-hogql
mariusandra Feb 28, 2023
f6a97e5
fix regression (thanks visual regression tests!)
mariusandra Feb 28, 2023
9287598
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 28, 2023
d45dfd8
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ export function OperatorValueSelect({

const [operators, setOperators] = useState([] as Array<PropertyOperator>)
useEffect(() => {
const isAutocaptureElementProperty = propkey === 'selector'
const operatorMapping: Record<string, string> = chooseOperatorMap(
isAutocaptureElementProperty ? PropertyType.Selector : propertyDefinition?.property_type
propkey === 'selector' || propkey === 'tag_name' ? PropertyType.Selector : propertyDefinition?.property_type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was wrong. Not only selector, but also tag_name only support a narrowed down list of options (just == and !=). Instead of adding PropertyType.TagName, I did this hack, as PropertyType is something that's synced from the plugin server's types 🤯. We'll need to revisit this anyway, so I hope the fix is good enough...

)
setOperators(Object.keys(operatorMapping) as Array<PropertyOperator>)
const operators = Object.keys(operatorMapping) as Array<PropertyOperator>
setOperators(operators)
if (currentOperator !== operator) {
setCurrentOperator(startingOperator)
}
if (isAutocaptureElementProperty) {
} else if (!operators.includes(currentOperator)) {
setCurrentOperator(PropertyOperator.Exact)
}
}, [propertyDefinition, propkey, operator])
Expand Down
16 changes: 15 additions & 1 deletion frontend/src/queries/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,21 @@ const HogQL: HogQLQuery = {
const HogQLTable: DataTableNode = {
kind: NodeKind.DataTableNode,
full: true,
source: HogQL,
source: {
kind: NodeKind.HogQLQuery,
query: ` select event,
person.properties.email,
properties.$browser,
count()
from events
where timestamp > now () - interval 1 month
and person.properties.email is not null
group by event,
properties.$browser,
person.properties.email
order by count() desc
limit 100`,
},
}

export const examples: Record<string, Node> = {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
return null
}
if (isEventsQuery(query) && !query.before) {
const sortKey = query.orderBy?.[0] ?? '-timestamp'
if (sortKey === '-timestamp') {
const sortKey = query.orderBy?.[0] ?? 'timestamp DESC'
if (sortKey === 'timestamp DESC') {
const sortColumnIndex = query.select
.map((hql) => removeExpressionComment(hql))
.indexOf('timestamp')
Expand All @@ -249,9 +249,9 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
(query, response, responseError, dataLoading): DataNode | null => {
if (isEventsQuery(query) && !responseError && !dataLoading) {
if ((response as EventsQuery['response'])?.hasMore) {
const sortKey = query.orderBy?.[0] ?? '-timestamp'
const sortKey = query.orderBy?.[0] ?? 'timestamp DESC'
const typedResults = (response as EventsQuery['response'])?.results
if (sortKey === '-timestamp') {
if (sortKey === 'timestamp DESC') {
const sortColumnIndex = query.select
.map((hql) => removeExpressionComment(hql))
.indexOf('timestamp')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function ColumnConfigurator({ query, setQuery }: ColumnConfiguratorProps)
let orderBy = query.source.orderBy
if (orderBy && orderBy.length > 0) {
const orderColumn = removeExpressionComment(
orderBy[0].startsWith('-') ? orderBy[0].slice(1) : orderBy[0]
orderBy[0].endsWith(' DESC') ? orderBy[0].replace(/ DESC$/, '') : orderBy[0]
)
// the old orderBy column was removed, so remove it from the new query
if (!columns.some((c) => removeExpressionComment(c) === orderColumn)) {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/queries/nodes/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function DataTable({ query, setQuery, context }: DataTableProps): JSX.Ele
if (hogQl && isEventsQuery(query.source)) {
const isAggregation = isHogQlAggregation(hogQl)
const isOrderBy = query.source?.orderBy?.[0] === key
const isDescOrderBy = query.source?.orderBy?.[0] === `-${key}`
const isDescOrderBy = query.source?.orderBy?.[0] === `${key} DESC`
setQuery?.({
...query,
source: {
Expand All @@ -143,7 +143,7 @@ export function DataTable({ query, setQuery, context }: DataTableProps): JSX.Ele
.filter((c) => (isAggregation ? c !== '*' : true)),
orderBy:
isOrderBy || isDescOrderBy
? [isDescOrderBy ? `-${hogQl}` : hogQl]
? [isDescOrderBy ? `${hogQl} DESC` : hogQl]
: query.source?.orderBy,
},
})
Expand Down Expand Up @@ -173,14 +173,14 @@ export function DataTable({ query, setQuery, context }: DataTableProps): JSX.Ele
</LemonButton>
<LemonButton
fullWidth
status={query.source?.orderBy?.[0] === `-${key}` ? 'primary' : 'stealth'}
status={query.source?.orderBy?.[0] === `${key} DESC` ? 'primary' : 'stealth'}
data-attr="datatable-sort-desc"
onClick={() => {
setQuery?.({
...query,
source: {
...query.source,
orderBy: [`-${key}`],
orderBy: [`${key} DESC`],
} as EventsQuery,
})
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('dataTableLogic', () => {
logic.mount()
await expectLogic(logic).toMatchValues({
sourceKind: NodeKind.EventsQuery,
orderBy: ['-timestamp'],
orderBy: ['timestamp DESC'],
})

// change props
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/queries/nodes/DataTable/dataTableLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const dataTableLogic = kea<dataTableLogicType>([
sourceKind: [(_, p) => [p.query], (query): NodeKind | null => query.source?.kind],
orderBy: [
(_, p) => [p.query],
(query): string[] | null => (isEventsQuery(query.source) ? query.source.orderBy || ['-timestamp'] : null),
(query): string[] | null =>
isEventsQuery(query.source) ? query.source.orderBy || ['timestamp DESC'] : null,
{ resultEqualityCheck: objectsEqual },
],
columnsInResponse: [
Expand All @@ -79,7 +80,9 @@ export const dataTableLogic = kea<dataTableLogicType>([
}

const { results } = eventsQueryResponse
const orderKey = orderBy?.[0]?.startsWith('-') ? orderBy[0].slice(1) : orderBy?.[0]
const orderKey = orderBy?.[0]?.endsWith(' DESC')
? orderBy[0].replace(/ DESC$/, '')
: orderBy?.[0]
const orderKeyIndex =
columnsInResponse?.findIndex(
(column) =>
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/queries/nodes/DataTable/renderColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Property } from 'lib/components/Property'
import { urls } from 'scenes/urls'
import { PersonHeader } from 'scenes/persons/PersonHeader'
import { DataTableNode, HasPropertiesNode, QueryContext } from '~/queries/schema'
import { isEventsQuery, isPersonsNode } from '~/queries/utils'
import { isEventsQuery, isHogQLQuery, isPersonsNode } from '~/queries/utils'
import { combineUrl, router } from 'kea-router'
import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'
import { DeletePersonButton } from '~/queries/nodes/PersonsNode/DeletePersonButton'
Expand All @@ -28,6 +28,18 @@ export function renderColumn(
return <Spinner />
} else if (value === errorColumn) {
return <LemonTag color="red">Error</LemonTag>
} else if (isHogQLQuery(query.source)) {
if (typeof value === 'string') {
try {
if ((value.startsWith('{') && value.endsWith('}')) || (value.startsWith('[') && value.endsWith(']'))) {
return <ReactJson src={JSON.parse(value)} name={key} collapsed={1} />
}
} catch (e) {}
if (value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}/)) {
return <TZLabel time={value} showSeconds />
}
}
return <Property value={value} />
} else if (key === 'event' && isEventsQuery(query.source)) {
const resultRow = record as any[]
const eventRecord = query.source.select.includes('*') ? resultRow[query.source.select.indexOf('*')] : null
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/queries/nodes/DataTable/renderColumnMeta.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PropertyFilterType } from '~/types'
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
import { QueryContext, DataTableNode } from '~/queries/schema'
import { isEventsQuery } from '~/queries/utils'
import { isEventsQuery, isHogQLQuery } from '~/queries/utils'
import { extractExpressionComment } from '~/queries/nodes/DataTable/utils'
import { SortingIndicator } from 'lib/lemon-ui/LemonTable/sorting'

Expand All @@ -14,7 +14,9 @@ export function renderColumnMeta(key: string, query: DataTableNode, context?: Qu
let width: number | undefined
let title: JSX.Element | string | undefined

if (key === 'timestamp') {
if (isHogQLQuery(query.source)) {
title = key
} else if (key === 'timestamp') {
title = 'Time'
} else if (key === 'created_at') {
title = 'First seen'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/nodes/DataTable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isEventsQuery } from '~/queries/utils'
export const defaultDataTableEventColumns: HogQLExpression[] = [
'*',
'event',
'distinct_id',
'person',
'coalesce(properties.$current_url, properties.$screen_name) -- Url / Screen',
'properties.$lib',
'timestamp',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/events/eventsSceneLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getDefaultEventsSceneQuery = (): DataTableNode => ({
source: {
kind: NodeKind.EventsQuery,
select: defaultDataTableColumns(NodeKind.EventsQuery),
orderBy: ['-timestamp'],
orderBy: ['timestamp DESC'],
after: '-24h',
limit: 100,
},
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def people(self, request: request.Request, *args: Any, **kwargs: Any) -> Respons
def count(self, request: request.Request, **kwargs) -> Response:
action = self.get_object()
# NOTE: never accepts cohort parameters so no need for explicit person_id_joined_alias
hogql_context = HogQLContext()
hogql_context = HogQLContext(legacy_person_property_handling=True)
query, params = format_action_filter(team_id=action.team_id, action=action, hogql_context=hogql_context)
if query == "":
return Response({"count": 0})
Expand Down
8 changes: 2 additions & 6 deletions posthog/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
from posthog.api.routing import StructuredViewSetMixin
from posthog.client import query_with_columns, sync_execute
from posthog.models import Element, Filter, Person
from posthog.models.event.query_event_list import (
QUERY_DEFAULT_EXPORT_LIMIT,
QUERY_DEFAULT_LIMIT,
QUERY_MAXIMUM_LIMIT,
query_events_list,
)
from posthog.models.event.events_query import QUERY_DEFAULT_EXPORT_LIMIT, QUERY_DEFAULT_LIMIT, QUERY_MAXIMUM_LIMIT
from posthog.models.event.query_event_list import query_events_list
from posthog.models.event.sql import GET_CUSTOM_EVENTS, SELECT_ONE_EVENT_SQL
from posthog.models.event.util import ClickhouseEventSerializer
from posthog.models.person.util import get_persons_by_distinct_ids
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from posthog.cloud_utils import is_cloud
from posthog.hogql.query import execute_hogql_query
from posthog.models import Team, User
from posthog.models.event.query_event_list import run_events_query
from posthog.models.event.events_query import run_events_query
from posthog.permissions import ProjectMembershipNecessaryPermissions, TeamMemberAccessPermission
from posthog.rate_limit import ClickHouseBurstRateThrottle, ClickHouseSustainedRateThrottle
from posthog.schema import EventsQuery, HogQLQuery
Expand Down
Loading