Skip to content

Commit

Permalink
Rename to experiments_timestamp_key
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Nov 30, 2024
1 parent d190a12 commit 413a63f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
12 changes: 6 additions & 6 deletions frontend/src/scenes/data-warehouse/ViewLinkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function ViewLinkForm(): JSX.Element {
joiningIsUsingHogQLExpression,
isViewLinkSubmitting,
experimentsOptimized,
experimentsTimestampField,
experimentsTimestampKey,
} = useValues(viewLinkLogic)
const {
selectJoiningTable,
Expand All @@ -70,7 +70,7 @@ export function ViewLinkForm(): JSX.Element {
selectSourceKey,
selectJoiningKey,
setExperimentsOptimized,
selectExperimentsTimestampField,
selectExperimentsTimestampKey,
} = useActions(viewLinkLogic)
const [advancedSettingsExpanded, setAdvancedSettingsExpanded] = useState(false)

Expand Down Expand Up @@ -173,12 +173,12 @@ export function ViewLinkForm(): JSX.Element {
</Field>
</div>
<div className="w-60 shrink-0">
<span className="l4">Timestamp Field</span>
<Field name="experiments_timestamp_field">
<span className="l4">Source Timestamp Key</span>
<Field name="experiments_timestamp_key">
<LemonSelect
fullWidth
onSelect={selectExperimentsTimestampField}
value={experimentsTimestampField ?? undefined}
onSelect={selectExperimentsTimestampKey}
value={experimentsTimestampKey ?? undefined}
options={sourceTableKeys}
placeholder="Select a key"
/>
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/scenes/data-warehouse/viewLinkLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
setError: (error: string) => ({ error }),
setFieldName: (fieldName: string) => ({ fieldName }),
setExperimentsOptimized: (experimentsOptimized: boolean) => ({ experimentsOptimized }),
selectExperimentsTimestampField: (experimentsTimestampField: string | null) => ({ experimentsTimestampField }),
selectExperimentsTimestampKey: (experimentsTimestampKey: string | null) => ({ experimentsTimestampKey }),
clearModalFields: true,
})),
reducers({
Expand Down Expand Up @@ -111,11 +111,11 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
clearModalFields: () => false,
},
],
experimentsTimestampField: [
experimentsTimestampKey: [
null as string | null,
{
selectExperimentsTimestampField: (_, { experimentsTimestampField }) => experimentsTimestampField,
toggleEditJoinModal: (_, { join }) => join.configuration?.experiments_timestamp_field ?? null,
selectExperimentsTimestampKey: (_, { experimentsTimestampKey }) => experimentsTimestampKey,
toggleEditJoinModal: (_, { join }) => join.configuration?.experiments_timestamp_key ?? null,
clearModalFields: () => null,
},
],
Expand Down Expand Up @@ -156,7 +156,7 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
field_name: values.fieldName,
configuration: {
experiments_optimized: values.experimentsOptimized,
experiments_timestamp_field: values.experimentsTimestampField ?? undefined,
experiments_timestamp_key: values.experimentsTimestampKey ?? undefined,
},
})

Expand All @@ -180,7 +180,7 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
field_name: values.fieldName,
configuration: {
experiments_optimized: values.experimentsOptimized,
experiments_timestamp_field: values.experimentsTimestampField ?? undefined,
experiments_timestamp_key: values.experimentsTimestampKey ?? undefined,
},
})

Expand All @@ -203,11 +203,11 @@ export const viewLinkLogic = kea<viewLinkLogicType>([
},
setExperimentsOptimized: ({ experimentsOptimized }) => {
if (!experimentsOptimized) {
actions.selectExperimentsTimestampField(null)
actions.selectExperimentsTimestampKey(null)
}
},
selectExperimentsTimestampField: ({ experimentsTimestampField }) => {
if (experimentsTimestampField) {
selectExperimentsTimestampKey: ({ experimentsTimestampKey }) => {
if (experimentsTimestampKey) {
actions.setExperimentsOptimized(true)
}
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4055,7 +4055,7 @@ export interface DataWarehouseViewLink {
created_at?: string | null
configuration?: {
experiments_optimized?: boolean
experiments_timestamp_field?: string | null
experiments_timestamp_key?: string | null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def create_data_warehouse_table_with_payments(self):
joining_table_name="events",
joining_table_key="distinct_id",
field_name="events",
configuration={"experiments_optimized": True, "experiments_timestamp_field": "dw_timestamp"},
configuration={"experiments_optimized": True, "experiments_timestamp_key": "dw_timestamp"},
)
return table_name

Expand Down
12 changes: 5 additions & 7 deletions posthog/warehouse/api/test/test_view_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_create_with_configuration(self):
"source_table_key": "uuid",
"joining_table_key": "id",
"field_name": "some_field",
"configuration": {"experiments_optimized": True, "experiments_timestamp_field": "timestamp"},
"configuration": {"experiments_optimized": True, "experiments_timestamp_key": "timestamp"},
},
)
self.assertEqual(response.status_code, 201, response.content)
Expand All @@ -59,7 +59,7 @@ def test_create_with_configuration(self):
"joining_table_name": "persons",
"joining_table_key": "id",
"field_name": "some_field",
"configuration": {"experiments_optimized": True, "experiments_timestamp_field": "timestamp"},
"configuration": {"experiments_optimized": True, "experiments_timestamp_key": "timestamp"},
},
)

Expand Down Expand Up @@ -116,7 +116,7 @@ def test_update_with_configuration(self):

response = self.client.patch(
f"/api/projects/{self.team.id}/warehouse_view_links/{join.id}/",
{"configuration": {"experiments_optimized": True, "experiments_timestamp_field": "timestamp"}},
{"configuration": {"experiments_optimized": True, "experiments_timestamp_key": "timestamp"}},
)
self.assertEqual(response.status_code, 200, response.content)
view_link = response.json()
Expand All @@ -132,13 +132,11 @@ def test_update_with_configuration(self):
"joining_table_name": "persons",
"joining_table_key": "id",
"field_name": "some_field",
"configuration": {"experiments_optimized": True, "experiments_timestamp_field": "timestamp"},
"configuration": {"experiments_optimized": True, "experiments_timestamp_key": "timestamp"},
},
)
join.refresh_from_db()
self.assertEqual(
join.configuration, {"experiments_optimized": True, "experiments_timestamp_field": "timestamp"}
)
self.assertEqual(join.configuration, {"experiments_optimized": True, "experiments_timestamp_key": "timestamp"})

def test_delete(self):
response = self.client.post(
Expand Down
8 changes: 4 additions & 4 deletions posthog/warehouse/models/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def _join_function_for_experiments(
if not self.configuration.get("experiments_optimized"):
raise ResolutionError("experiments_optimized is not enabled for this join")

timestamp_field = self.configuration.get("experiments_timestamp_field")
if not timestamp_field:
raise ResolutionError("experiments_timestamp_field is not set for this join")
timestamp_key = self.configuration.get("experiments_timestamp_key")
if not timestamp_key:
raise ResolutionError("experiments_timestamp_key is not set for this join")

return ast.JoinExpr(
table=ast.SelectQuery(
Expand Down Expand Up @@ -165,7 +165,7 @@ def _join_function_for_experiments(
left=ast.Field(
chain=[
join_to_add.from_table,
timestamp_field,
timestamp_key,
]
),
op=ast.CompareOperationOp.GtEq,
Expand Down

0 comments on commit 413a63f

Please sign in to comment.