Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(batch-exports): choose the timestamp timezone for hogql exports (#113210)

Rossad9fa1b1a74e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index c04bf12a910a..1f258613b535 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9067,9 +9067,9 @@ snapshots:
scenes-app-batchexports--existing-big-query-export--light:
hash: v1.k794b7964.169c050ced77823af76847e5b432e37172733b51a52fa3e4046ab9ef586d40eb.QA_BL0dNaL6VSVaB5YMB03s3-F4U4WQjVKyOY_xGux4
scenes-app-batchexports--existing-hog-ql-export--dark:
- hash: v1.k794b7964.d5e31173e3e69b7a063b65c63239e8aab0eb7458470b6ab09673d92f7c9bbf11.s1usBPTk3SLC9lrQaQsFVDvYXGsS6-M9NbIxYuROncc
+ hash: v1.k794b7964.3028ec55dc1e12c741fcd70a26fc5c7de9ebdba0e25ce909d3d17b9d823896aa.KMHqAyH_LdiZxc6OBJ6bfU46OuxzGVrwR6rtpCwMb4g
scenes-app-batchexports--existing-hog-ql-export--light:
- hash: v1.k794b7964.b6ba4512c7721d653ea7c8fa2b9fa755894f0071ea904835e44f4ae6434624da.Wb198vJBtGeUMQhPPJxJuSsNVtnhoHiMOlF2QFfqFwc
+ hash: v1.k794b7964.4f1f050474ec4cf054d9e54877efb256cfeb204c9499231f7d0fde886cfac23a.s2E5rLFxdqHeoXrEIrMLGVICQM_7O8WKx-4qjyeEvsM
scenes-app-batchexports--history-empty--dark:
hash: v1.k794b7964.4876ed69bc9129528181a8a663b41e0fb1350b95e3f3a6077a9db2857b081cc4.N_l9zIvhsX-G07IjsNfoWtmuyYaV-o88xTxZz3_w4rM
scenes-app-batchexports--history-empty--light:
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx
index b70b0433ae9f..b463cc1baa43 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx
+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportConfiguration.tsx
@@ -39,6 +39,7 @@ import {
} from './BatchExportConfigurationButtons'
import { BatchExportGeneralEditFields, BatchExportsEditFields } from './BatchExportEditForm'
import { BatchExportHogQLQueryEditor } from './BatchExportHogQLQueryEditor'
+import { BatchExportQueryTimezoneSelector } from './BatchExportQueryTimezoneSelector'
import { EVENT_FIELD_DESCRIPTIONS } from './destinations/common'
import { BatchExportConfigurationForm } from './types'
import { dayOptions, hourOptions } from './utils'
@@ -405,6 +406,9 @@ export function BatchExportConfiguration(): JSX.Element {
Write the SQL query whose results each run exports. Run it here to preview the data.
</p>
</div>
+ <div className="max-w-160 mb-2">
+ <BatchExportQueryTimezoneSelector />
+ </div>
<LemonField name="hogql_query">
<BatchExportHogQLQueryEditor />
</LemonField>
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportHogQLQueryEditor.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportHogQLQueryEditor.tsx
index ab4060dcf476..3954a1b9b851 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportHogQLQueryEditor.tsx
+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportHogQLQueryEditor.tsx
@@ -14,7 +14,7 @@ import {
export function BatchExportHogQLQueryEditor(): JSX.Element {
const { props: formLogicProps } = useMountedLogic(batchExportConfigFormLogic)
- const { previewStart, previewEnd, projectTimezone, usesIntervalPlaceholders } = useValues(
+ const { previewStart, previewEnd, queryTimezone, usesIntervalPlaceholders } = useValues(
batchExportHogQLQueryLogic(formLogicProps)
)
@@ -42,7 +42,7 @@ export function BatchExportHogQLQueryEditor(): JSX.Element {
<p className="text-xs text-secondary mb-0">
When you run the query here, the placeholders cover the last complete interval:{' '}
<span translate="no">{`'${previewStart}'`}</span> to <span translate="no">{`'${previewEnd}'`}</span>{' '}
- <span translate="no">{`(${projectTimezone})`}</span>. Each export run fills them with its own interval.
+ <span translate="no">{`(${queryTimezone})`}</span>. Each export run fills them with its own interval.
</p>
</div>
)
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportQueryTimezoneSelector.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportQueryTimezoneSelector.tsx
new file mode 100644
index 000000000000..d2d59c724da6
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportQueryTimezoneSelector.tsx
@@ -0,0 +1,68 @@
+import { useActions, useMountedLogic, useValues } from 'kea'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+import { LemonSelect } from 'lib/lemon-ui/LemonSelect'
+import { Link } from 'lib/lemon-ui/Link'
+import { urls } from 'scenes/urls'
+
+import { batchExportConfigFormLogic } from './batchExportConfigFormLogic'
+import { QueryTimezoneChoice, batchExportHogQLQueryLogic } from './batchExportHogQLQueryLogic'
+
+export function BatchExportQueryTimezoneSelector(): JSX.Element {
+ const formLogic = useMountedLogic(batchExportConfigFormLogic)
+ const { configurationErrors } = useValues(formLogic)
+ const logic = batchExportHogQLQueryLogic(formLogic.props)
+ const { projectTimezone, defaultTimezone, teamConvertToProjectTimezone, queryTimezoneChoice } = useValues(logic)
+ const { setQueryTimezone } = useActions(logic)
+
+ let help: React.ReactNode = null
+ if (queryTimezoneChoice === 'project_timezone') {
+ help = (
+ <>
+ If the project timezone changes in{' '}
+ <Link to={urls.settings('environment-customization', 'date-and-time')} target="_blank">
+ project settings
+ </Link>
+ , this export uses the new timezone from its next run.
+ </>
+ )
+ } else if (queryTimezoneChoice === 'default' && teamConvertToProjectTimezone === null) {
+ help =
+ 'The default is the project timezone. If the default or the project timezone changes, this export uses the new one from its next run.'
+ } else if (queryTimezoneChoice === 'default') {
+ help = (
+ <>
+ This project's <code>convertToProjectTimezone</code> modifier was set to{' '}
+ <code>{String(teamConvertToProjectTimezone)}</code> through the API, so the default is{' '}
+ <span>{teamConvertToProjectTimezone ? 'the project timezone' : 'UTC'}</span>. If it changes, this export
+ uses the new default from its next run.
+ </>
+ )
+ }
+
+ return (
+ <LemonField.Pure
+ label="Query timezone"
+ info={
+ <>
+ Sets the timezone for timestamps in the export and for date functions in the query. A timezone set
+ in the query, such as with <code>toTimeZone(timestamp, 'UTC')</code>, takes precedence.
+ </>
+ }
+ help={help}
+ error={configurationErrors.hogql_modifiers}
+ >
+ <LemonSelect<QueryTimezoneChoice>
+ fullWidth
+ value={queryTimezoneChoice}
+ onChange={setQueryTimezone}
+ options={[
+ { value: 'default', label: `Use default (${defaultTimezone})` },
+ { value: 'utc', label: 'Always use UTC' },
+ { value: 'project_timezone', label: `Always use project timezone (${projectTimezone})` },
+ ]}
+ data-attr="batch-export-hogql-query-timezone"
+ />
+ </LemonField.Pure>
+ )
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
index 74f2ef3c52f4..b200557ac1a7 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
@@ -385,6 +385,7 @@ const HOGQL_BATCH_EXPORT: BatchExportConfiguration = {
...fixture('test-hogql-id', 'HogQL Export', { type: 'AwsS3', integration: 31, config: AWS_S3_CONFIG }),
model: 'hogql',
hogql_query: 'SELECT event FROM events WHERE timestamp >= {data_interval_start}',
+ hogql_modifiers: { convertToProjectTimezone: false },
}
// Single map keyed by id; used to register GET + PATCH mocks dynamically below.
@@ -1376,8 +1377,9 @@ describe('batchExportConfigFormLogic', () => {
const body = patchBodiesById[fixture.id]
expect(body).not.toBeUndefined()
expect(body.destination).toEqual(fixture.destination)
- // Only the 'hogql' model edits the query, so other models must not send one
+ // Only the 'hogql' model edits the query and its modifiers, so other models must not send them
expect(body.hogql_query).toEqual(fixture.hogql_query)
+ expect(body.hogql_modifiers).toEqual(fixture.hogql_modifiers)
})
it.each([
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
index 8265f7b68f1f..fca8957bd78b 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
@@ -48,6 +48,7 @@ const TOP_LEVEL_FORM_FIELDS = new Set([
'end_at',
'model',
'hogql_query',
+ 'hogql_modifiers',
'filters',
'integration_id',
])
@@ -105,8 +106,10 @@ function buildBatchExportPayload(formValues: Record<string, any>): Partial<Batch
offset_day: interval === 'week' ? formValues.offset_day : null,
offset_hour: interval === 'day' || interval === 'week' ? formValues.offset_hour : null,
model: formValues.model,
- // Only the 'hogql' model edits the query. The events model would save a query as its export schema.
+ // Only the 'hogql' model edits the query and its modifiers. The events model would save a query as its
+ // export schema, and the API rejects modifiers for every other model.
hogql_query: formValues.model === BatchExportModelEnumApi.Hogql ? formValues.hogql_query : undefined,
+ hogql_modifiers: formValues.model === BatchExportModelEnumApi.Hogql ? formValues.hogql_modifiers : undefined,
// Filters only apply to the events model: the API rejects them for 'hogql' and runs ignore them otherwise
filters: formValues.model === BatchExportModelEnumApi.Events ? formValues.filters : undefined,
destination: buildDestinationPayload(formValues) as any,
@@ -131,6 +134,7 @@ function getConfigurationFromBatchExportConfig(batchExportConfig: BatchExportCon
offset_hour: (batchExportConfig as any).offset_hour ?? null,
model: batchExportConfig.model,
hogql_query: batchExportConfig.hogql_query ?? null,
+ hogql_modifiers: batchExportConfig.hogql_modifiers ?? null,
filters: batchExportConfig.filters,
...flatConfig,
}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.test.ts b/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.test.ts
index 7402411acf01..72fe11abdfdb 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.test.ts
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.test.ts
@@ -2,18 +2,25 @@ import { expectLogic } from 'kea-test-utils'
import { sqlEditorLogic } from 'scenes/data-warehouse/editor/sqlEditorLogic'
import { SQLEditorMode } from 'scenes/data-warehouse/editor/sqlEditorModes'
+import { teamLogic } from 'scenes/teamLogic'
import { useMocks } from '~/mocks/jest'
+import { HogQLQueryModifiers } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { BatchExportConfiguration } from '~/types'
import { BatchExportConfigFormLogicProps, batchExportConfigFormLogic } from './batchExportConfigFormLogic'
-import { batchExportHogQLEditorTabId, batchExportHogQLQueryLogic } from './batchExportHogQLQueryLogic'
+import {
+ QueryTimezoneChoice,
+ batchExportHogQLEditorTabId,
+ batchExportHogQLQueryLogic,
+} from './batchExportHogQLQueryLogic'
const EXPORT_ID = 'test-hogql-export-id'
const PROPS: BatchExportConfigFormLogicProps = { id: EXPORT_ID, service: null }
+const PROJECT_TIMEZONE = 'Europe/Berlin'
-function hogqlExport(): BatchExportConfiguration {
+function hogqlExport(hogqlModifiers: HogQLQueryModifiers | null): BatchExportConfiguration {
return {
id: EXPORT_ID,
team_id: 997,
@@ -44,6 +51,7 @@ function hogqlExport(): BatchExportConfiguration {
paused: false,
model: 'hogql',
hogql_query: 'SELECT event FROM events WHERE timestamp >= {data_interval_start}',
+ hogql_modifiers: hogqlModifiers,
filters: [],
}
}
@@ -51,11 +59,24 @@ function hogqlExport(): BatchExportConfiguration {
describe('batchExportHogQLQueryLogic', () => {
let logic: ReturnType<typeof batchExportHogQLQueryLogic.build>
let formLogic: ReturnType<typeof batchExportConfigFormLogic.build>
+ // The saved export's `hogql_modifiers`, which the mocked GET returns. Each test sets it through initLogic.
+ let savedExportModifiers: HogQLQueryModifiers | null = null
const editorLogic = (props: BatchExportConfigFormLogicProps = PROPS): ReturnType<typeof sqlEditorLogic.build> =>
sqlEditorLogic({ tabId: batchExportHogQLEditorTabId(props), mode: SQLEditorMode.Embedded })
- async function initLogic(props: BatchExportConfigFormLogicProps = PROPS): Promise<void> {
+ async function initLogic(
+ teamModifiers: HogQLQueryModifiers | undefined,
+ exportModifiers: HogQLQueryModifiers | null,
+ props: BatchExportConfigFormLogicProps = PROPS
+ ): Promise<void> {
+ savedExportModifiers = exportModifiers
+ await expectLogic(teamLogic).toFinishAllListeners()
+ teamLogic.actions.loadCurrentTeamSuccess({
+ ...teamLogic.values.currentTeam!,
+ timezone: PROJECT_TIMEZONE,
+ modifiers: teamModifiers,
+ })
formLogic = batchExportConfigFormLogic(props)
formLogic.mount()
await expectLogic(formLogic).toFinishAllListeners()
@@ -67,7 +88,10 @@ describe('batchExportHogQLQueryLogic', () => {
beforeEach(() => {
useMocks({
get: {
- [`/api/environments/:team_id/batch_exports/${EXPORT_ID}`]: hogqlExport(),
+ [`/api/environments/:team_id/batch_exports/${EXPORT_ID}`]: () => [
+ 200,
+ hogqlExport(savedExportModifiers),
+ ],
'/api/environments/:team_id/batch_exports/test': { steps: [] },
'/api/projects/:team_id/integrations/': { count: 0, results: [] },
},
@@ -75,10 +99,81 @@ describe('batchExportHogQLQueryLogic', () => {
initKeaTests()
})
+ // The backend resolves `convertToProjectTimezone` from the export's modifiers, then `team.modifiers`, then
+ // `true`. The form label and the preview's placeholder timezone must follow the same order. If the logic skips
+ // `team.modifiers`, a team that turned the modifier off through the API sees its project timezone in the form
+ // while its exports run in UTC.
+ test.each<
+ [string, HogQLQueryModifiers | undefined, HogQLQueryModifiers | null, QueryTimezoneChoice, string, string]
+ >([
+ ['the team leaves it unset', undefined, null, 'default', PROJECT_TIMEZONE, PROJECT_TIMEZONE],
+ ['the team turns it off', { convertToProjectTimezone: false }, null, 'default', 'UTC', 'UTC'],
+ [
+ 'the export turns it on over the team',
+ { convertToProjectTimezone: false },
+ { convertToProjectTimezone: true },
+ 'project_timezone',
+ 'UTC',
+ PROJECT_TIMEZONE,
+ ],
+ [
+ 'the export turns it off over the default',
+ undefined,
+ { convertToProjectTimezone: false },
+ 'utc',
+ PROJECT_TIMEZONE,
+ 'UTC',
+ ],
+ ])(
+ 'resolves the query timezone when %s',
+ async (_, teamModifiers, exportModifiers, choice, defaultTimezone, queryTimezone) => {
+ await initLogic(teamModifiers, exportModifiers)
+
+ await expectLogic(logic).toMatchValues({
+ queryTimezoneChoice: choice,
+ defaultTimezone,
+ queryTimezone,
+ })
+ const { start, end } = logic.values.previewInterval
+ expect(editorLogic().values.placeholders.map((placeholder) => placeholder.previewValue)).toEqual([
+ start.tz(queryTimezone).format('YYYY-MM-DD HH:mm:ss'),
+ end.tz(queryTimezone).format('YYYY-MM-DD HH:mm:ss'),
+ ])
+ }
+ )
+
+ // The form controls only `convertToProjectTimezone`. Other keys can come from the API, and the backend replaces
+ // the whole `hogql_modifiers` object on save, so changing the choice must keep them. The editor must get the
+ // same modifiers, or the preview runs with different settings from the export.
+ test.each<[string, HogQLQueryModifiers | null, QueryTimezoneChoice, HogQLQueryModifiers | null]>([
+ [
+ 'keeps other modifiers when it unsets the key',
+ { personsOnEventsMode: 'person_id_override_properties_joined', convertToProjectTimezone: false },
+ 'default',
+ { personsOnEventsMode: 'person_id_override_properties_joined' },
+ ],
+ ['clears the modifiers once no key is left', { convertToProjectTimezone: false }, 'default', null],
+ [
+ 'keeps other modifiers when it sets the key',
+ { personsOnEventsMode: 'person_id_override_properties_joined' },
+ 'project_timezone',
+ { personsOnEventsMode: 'person_id_override_properties_joined', convertToProjectTimezone: true },
+ ],
+ ['adds the key when there are no modifiers', null, 'utc', { convertToProjectTimezone: false }],
+ ])('setQueryTimezone %s', async (_, exportModifiers, choice, expectedModifiers) => {
+ await initLogic(undefined, exportModifiers)
+
+ logic.actions.setQueryTimezone(choice)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(formLogic.values.configuration.hogql_modifiers).toEqual(expectedModifiers)
+ expect(editorLogic().values.queryModifiers).toEqual(expectedModifiers)
+ })
+
// The form saves `hogql_query`, so it must match what the editor shows. A form reset, such as "Clear changes",
// must also reach the editor, or the editor keeps text that the form no longer holds.
it('copies editor changes into the form', async () => {
- await initLogic()
+ await initLogic(undefined, null)
editorLogic().actions.setQueryInput('SELECT 2')
await expectLogic(logic).toFinishAllListeners()
@@ -87,18 +182,18 @@ describe('batchExportHogQLQueryLogic', () => {
})
it('restores the editor when the form resets', async () => {
- await initLogic()
+ await initLogic(undefined, null)
editorLogic().actions.setQueryInput('SELECT 2')
await expectLogic(logic).toFinishAllListeners()
formLogic.actions.resetConfiguration(formLogic.values.savedConfiguration)
await expectLogic(logic).toFinishAllListeners()
- expect(editorLogic().values.queryInput).toEqual(hogqlExport().hogql_query)
+ expect(editorLogic().values.queryInput).toEqual(hogqlExport(null).hogql_query)
})
it('gives the editor preview values that follow the schedule', async () => {
- await initLogic()
+ await initLogic(undefined, null)
const hourlyPlaceholders = editorLogic().values.placeholders
expect(hourlyPlaceholders).toEqual(logic.values.placeholders)
@@ -111,7 +206,7 @@ describe('batchExportHogQLQueryLogic', () => {
it('starts a new export with the default query in both the editor and the form', async () => {
const newExportProps: BatchExportConfigFormLogicProps = { id: null, service: 'AwsS3' }
- await initLogic(newExportProps)
+ await initLogic(undefined, null, newExportProps)
const queryInput = editorLogic(newExportProps).values.queryInput
expect(queryInput).toContain('{data_interval_start}')
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.ts b/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.ts
index fbb5616f4032..07bd77bd59b7 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.ts
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportHogQLQueryLogic.ts
@@ -1,6 +1,7 @@
import {
LogicWrapper,
MakeLogicType,
+ actions,
afterMount,
connect,
kea,
@@ -21,8 +22,8 @@ import { SQLEditorMode } from 'scenes/data-warehouse/editor/sqlEditorModes'
import { SQLEditorPlaceholder } from 'scenes/data-warehouse/editor/sqlEditorPlaceholders'
import { teamLogic } from 'scenes/teamLogic'
-import { NodeKind } from '~/queries/schema/schema-general'
-import { BatchExportInterval, ChartDisplayType } from '~/types'
+import { HogQLQueryModifiers, NodeKind } from '~/queries/schema/schema-general'
+import { BatchExportInterval, ChartDisplayType, TeamPublicType, TeamType } from '~/types'
import { BatchExportConfigFormLogicProps, batchExportConfigFormLogic } from './batchExportConfigFormLogic'
import { BatchExportDataInterval, lastCompleteDataInterval } from './utils'
@@ -44,6 +45,9 @@ WHERE timestamp >= {${DATA_INTERVAL_START_PLACEHOLDER}}
// ClickHouse cannot parse a datetime string with a UTC offset.
const PLACEHOLDER_VALUE_FORMAT = 'YYYY-MM-DD HH:mm:ss'
+/** 'default' leaves `convertToProjectTimezone` unset, so the export follows the project's default. */
+export type QueryTimezoneChoice = 'default' | 'project_timezone' | 'utc'
+
export function batchExportHogQLEditorTabId({ id, service }: BatchExportConfigFormLogicProps): string {
return `batch-export-hogql-${id ?? `new-${service}`}`
}
@@ -52,15 +56,21 @@ export function batchExportHogQLEditorTabId({ id, service }: BatchExportConfigFo
export interface batchExportHogQLQueryLogicValues {
configuration: Record<string, any> // batchExportConfigFormLogic
queryInput: string | null // sqlEditorLogic
+ currentTeam: TeamPublicType | TeamType | null // teamLogic
projectTimezone: string // teamLogic
+ defaultTimezone: string
+ hogqlModifiers: HogQLQueryModifiers | null
placeholders: SQLEditorPlaceholder[]
previewEnd: string
previewInterval: BatchExportDataInterval
previewStart: string
+ queryTimezone: string
+ queryTimezoneChoice: QueryTimezoneChoice
scheduleInterval: BatchExportInterval
scheduleOffsetDay: number | null
scheduleOffsetHour: number | null
scheduleTimezone: string | null
+ teamConvertToProjectTimezone: boolean | null
usesIntervalPlaceholders: boolean
}
@@ -95,9 +105,15 @@ export interface batchExportHogQLQueryLogicActions {
setQueryInput: (queryInput: string | null) => {
queryInput: string | null
} // sqlEditorLogic
+ setQueryModifiers: (queryModifiers: HogQLQueryModifiers | null) => {
+ queryModifiers: HogQLQueryModifiers | null
+ } // sqlEditorLogic
setSourceQuery: (sourceQuery: import('~/queries/schema/schema-general').DataVisualizationNode) => {
sourceQuery: import('~/queries/schema/schema-general').DataVisualizationNode
} // sqlEditorLogic
+ setQueryTimezone: (choice: QueryTimezoneChoice) => {
+ choice: QueryTimezoneChoice
+ }
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -115,6 +131,19 @@ export interface batchExportHogQLQueryLogicMeta {
) => void | Promise<void>
}
__keaTypeGenInternalSelectorTypes: {
+ hogqlModifiers: (configuration: Record<string, any>) => HogQLQueryModifiers | null
+ queryTimezoneChoice: (hogqlModifiers: HogQLQueryModifiers | null) => QueryTimezoneChoice
+ teamConvertToProjectTimezone: (currentTeam: TeamPublicType | TeamType | null) => boolean | null
+ defaultTimezone: (
+ teamConvertToProjectTimezone: boolean | null,
+ currentTeam: TeamPublicType | TeamType | null,
+ projectTimezone: string
+ ) => string
+ queryTimezone: (
+ queryTimezoneChoice: QueryTimezoneChoice,
+ defaultTimezone: string,
+ projectTimezone: string
+ ) => string
scheduleInterval: (configuration: Record<string, any>) => BatchExportInterval
scheduleTimezone: (configuration: Record<string, any>) => string | null
scheduleOffsetDay: (configuration: Record<string, any>) => number | null
@@ -126,8 +155,8 @@ export interface batchExportHogQLQueryLogicMeta {
scheduleOffsetHour: number | null,
projectTimezone: string
) => BatchExportDataInterval
- previewStart: (previewInterval: BatchExportDataInterval, projectTimezone: string) => string
- previewEnd: (previewInterval: BatchExportDataInterval, projectTimezone: string) => string
+ previewStart: (previewInterval: BatchExportDataInterval, queryTimezone: string) => string
+ previewEnd: (previewInterval: BatchExportDataInterval, queryTimezone: string) => string
placeholders: (previewStart: string, previewEnd: string) => SQLEditorPlaceholder[]
usesIntervalPlaceholders: (queryInput: string | null) => boolean
}
@@ -152,7 +181,7 @@ export const batchExportHogQLQueryLogic: LogicWrapper<batchExportHogQLQueryLogic
batchExportConfigFormLogic(props),
['configuration'],
teamLogic,
- ['timezone as projectTimezone'],
+ ['timezone as projectTimezone', 'currentTeam'],
sqlEditorLogic({ tabId: batchExportHogQLEditorTabId(props), mode: SQLEditorMode.Embedded }),
['queryInput'],
],
@@ -166,10 +195,51 @@ export const batchExportHogQLQueryLogic: LogicWrapper<batchExportHogQLQueryLogic
'updateBatchExportConfigSuccess',
],
sqlEditorLogic({ tabId: batchExportHogQLEditorTabId(props), mode: SQLEditorMode.Embedded }),
- ['setQueryInput', 'setSourceQuery', 'setPlaceholders'],
+ ['setQueryInput', 'setSourceQuery', 'setPlaceholders', 'setQueryModifiers'],
],
})),
+ actions({
+ setQueryTimezone: (choice: QueryTimezoneChoice) => ({ choice }),
+ }),
selectors({
+ hogqlModifiers: [
+ (s) => [s.configuration],
+ (configuration: Record<string, any>): HogQLQueryModifiers | null =>
+ configuration.hogql_modifiers ?? null,
+ ],
+ queryTimezoneChoice: [
+ (s) => [s.hogqlModifiers],
+ (hogqlModifiers: HogQLQueryModifiers | null): QueryTimezoneChoice => {
+ const convertToProjectTimezone = hogqlModifiers?.convertToProjectTimezone
+ if (convertToProjectTimezone === undefined || convertToProjectTimezone === null) {
+ return 'default'
+ }
+ return convertToProjectTimezone ? 'project_timezone' : 'utc'
+ },
+ ],
+ // Only the API sets the team's modifier, so a value here means someone chose it on purpose
+ teamConvertToProjectTimezone: [
+ (s) => [s.currentTeam],
+ (currentTeam: TeamType | TeamPublicType | null): boolean | null =>
+ currentTeam?.modifiers?.convertToProjectTimezone ?? null,
+ ],
+ // The backend fills in `true` when neither the project nor its defaults set a value
+ defaultTimezone: [
+ (s) => [s.teamConvertToProjectTimezone, s.currentTeam, s.projectTimezone],
+ (
+ teamConvertToProjectTimezone: boolean | null,
+ currentTeam: TeamType | TeamPublicType | null,
+ projectTimezone: string
+ ): string =>
+ (teamConvertToProjectTimezone ?? currentTeam?.default_modifiers?.convertToProjectTimezone ?? true)
+ ? projectTimezone
+ : 'UTC',
+ ],
+ queryTimezone: [
+ (s) => [s.queryTimezoneChoice, s.defaultTimezone, s.projectTimezone],
+ (choice: QueryTimezoneChoice, defaultTimezone: string, projectTimezone: string): string =>
+ choice === 'default' ? defaultTimezone : choice === 'project_timezone' ? projectTimezone : 'UTC',
+ ],
scheduleInterval: [
(s) => [s.configuration],
(configuration: Record<string, any>): BatchExportInterval => configuration.interval ?? 'hour',
@@ -211,16 +281,16 @@ export const batchExportHogQLQueryLogic: LogicWrapper<batchExportHogQLQueryLogic
})
},
],
- // HogQL reads these strings as times in the project timezone, so convert the bounds to it first.
+ // HogQL reads these strings as times in the query's timezone, so convert the bounds to it first.
previewStart: [
- (s) => [s.previewInterval, s.projectTimezone],
- (previewInterval: BatchExportDataInterval, projectTimezone: string): string =>
- previewInterval.start.tz(projectTimezone).format(PLACEHOLDER_VALUE_FORMAT),
+ (s) => [s.previewInterval, s.queryTimezone],
+ (previewInterval: BatchExportDataInterval, queryTimezone: string): string =>
+ previewInterval.start.tz(queryTimezone).format(PLACEHOLDER_VALUE_FORMAT),
],
previewEnd: [
- (s) => [s.previewInterval, s.projectTimezone],
- (previewInterval: BatchExportDataInterval, projectTimezone: string): string =>
- previewInterval.end.tz(projectTimezone).format(PLACEHOLDER_VALUE_FORMAT),
+ (s) => [s.previewInterval, s.queryTimezone],
+ (previewInterval: BatchExportDataInterval, queryTimezone: string): string =>
+ previewInterval.end.tz(queryTimezone).format(PLACEHOLDER_VALUE_FORMAT),
],
placeholders: [
(s) => [s.previewStart, s.previewEnd],
@@ -255,6 +325,16 @@ export const batchExportHogQLQueryLogic: LogicWrapper<batchExportHogQLQueryLogic
},
})),
listeners(({ actions, values, sharedListeners }) => ({
+ setQueryTimezone: ({ choice }) => {
+ // Only this key changes, so modifiers set through the API survive a save from the form
+ const next: HogQLQueryModifiers = { ...values.hogqlModifiers }
+ if (choice === 'default') {
+ delete next.convertToProjectTimezone
+ } else {
+ next.convertToProjectTimezone = choice === 'project_timezone'
+ }
+ actions.setConfigurationValue('hogql_modifiers', Object.keys(next).length > 0 ? next : null)
+ },
setQueryInput: ({ queryInput }) => {
if (queryInput !== null && queryInput !== values.configuration.hogql_query) {
actions.setConfigurationValue('hogql_query', queryInput)
@@ -268,6 +348,7 @@ export const batchExportHogQLQueryLogic: LogicWrapper<batchExportHogQLQueryLogic
})),
subscriptions(({ actions }) => ({
placeholders: (placeholders: SQLEditorPlaceholder[]) => actions.setPlaceholders(placeholders),
+ hogqlModifiers: (hogqlModifiers: HogQLQueryModifiers | null) => actions.setQueryModifiers(hogqlModifiers),
})),
afterMount(({ actions, values }) => {
if (values.queryInput !== null) {
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 269144aca17e..cc5547038b92 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -7018,6 +7018,7 @@ export type BatchExportConfiguration = {
paused: boolean
model: string
hogql_query?: BatchExportApi['hogql_query']
+ hogql_modifiers?: BatchExportApi['hogql_modifiers']
filters: AnyPropertyFilter[]
latest_runs?: BatchExportRun[]
}