: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): pick a materialized view as a destination or workflow trigger (#84417)
Tom Owers210d3a3046c1
diff --git a/frontend/src/lib/components/TaxonomicFilter/InfiniteSelectResults.tsx b/frontend/src/lib/components/TaxonomicFilter/InfiniteSelectResults.tsxindex 0e86512b7b91..565770a26053 100644--- a/frontend/src/lib/components/TaxonomicFilter/InfiniteSelectResults.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/InfiniteSelectResults.tsx@@ -201,6 +201,7 @@ export function InfiniteSelectResults({const showDataWarehouseLoadingState =(openTab === TaxonomicFilterGroupType.DataWarehouse ||openTab === TaxonomicFilterGroupType.DataWarehouseSourceTables ||+ openTab === TaxonomicFilterGroupType.DataWarehouseMaterializedViews ||openTab === TaxonomicFilterGroupType.DataWarehouseProperties) &&totalListCount === 0 &&isLocalDataLoadingdiff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterEmptyState.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterEmptyState.tsxindex a51254d5c182..1bcde6fc330c 100644--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterEmptyState.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterEmptyState.tsx@@ -260,6 +260,7 @@ const DefaultEmptyState = (): JSX.Element | null => {const EMPTY_STATES: Partial<Record<TaxonomicFilterGroupType, React.ComponentType<TaxonomicFilterEmptyStateProps>>> = {[TaxonomicFilterGroupType.DataWarehouse]: DataWarehouseEmptyState,[TaxonomicFilterGroupType.DataWarehouseSourceTables]: DataWarehouseEmptyState,+ [TaxonomicFilterGroupType.DataWarehouseMaterializedViews]: DataWarehouseEmptyState,[TaxonomicFilterGroupType.DataWarehouseProperties]: DataWarehouseEmptyState,[TaxonomicFilterGroupType.DataWarehousePersonProperties]: DataWarehouseEmptyState,[TaxonomicFilterGroupType.RecentFilters]: RecentFiltersEmptyState,diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.tsindex ed128b33d184..4dfe42d22d63 100644--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts@@ -142,6 +142,7 @@ export const NO_ITEM_SELECTED = -1const DATA_WAREHOUSE_GROUP_TYPES: TaxonomicFilterGroupType[] = [TaxonomicFilterGroupType.DataWarehouse,TaxonomicFilterGroupType.DataWarehouseSourceTables,+ TaxonomicFilterGroupType.DataWarehouseMaterializedViews,]export function getInitialPinnedRowIndex({diff --git a/frontend/src/lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic.ts b/frontend/src/lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic.tsindex d6edb43f97aa..f12a924d20d5 100644--- a/frontend/src/lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic.ts+++ b/frontend/src/lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic.ts@@ -21,6 +21,7 @@ const EXCLUDED_RECENT_FILTER_GROUP_TYPES = new Set<TaxonomicFilterGroupType>([...META_GROUP_TYPES,TaxonomicFilterGroupType.DataWarehouse,TaxonomicFilterGroupType.DataWarehouseSourceTables,+ TaxonomicFilterGroupType.DataWarehouseMaterializedViews,TaxonomicFilterGroupType.DataWarehouseProperties,TaxonomicFilterGroupType.DataWarehousePersonProperties,])diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsxindex 4727fd651759..7576dfe9b21f 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx@@ -1086,6 +1086,18 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([getPopoverHeader: () => 'Data Warehouse Table',getIcon: () => <IconServer />,},+ {+ name: 'Materialized views',+ searchPlaceholder: 'materialized views',+ type: TaxonomicFilterGroupType.DataWarehouseMaterializedViews,+ logic: dataWarehouseSettingsSceneLogic,+ value: 'materializedViews',+ valueLoading: 'materializedViewsLoading',+ getName: (table: DatabaseSchemaTable) => table.name,+ getValue: (table: DatabaseSchemaTable) => table.name,+ getPopoverHeader: () => 'Materialized view',+ getIcon: () => <IconServer />,+ },...(schemaColumns.length > 0 || schemaColumnsLoading? [{diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.tsindex 4ef78f19486b..5233aeeb90a7 100644--- a/frontend/src/lib/components/TaxonomicFilter/types.ts+++ b/frontend/src/lib/components/TaxonomicFilter/types.ts@@ -296,6 +296,9 @@ export enum TaxonomicFilterGroupType {// Like DataWarehouse but restricted to external-source tables (no views/saved queries or self-managed// tables) — used by CDP destination/workflow warehouse-row triggers.DataWarehouseSourceTables = 'data_warehouse_source_tables',+ // Materialized views (saved queries with a backing table) — used by CDP destination/workflow+ // materialized-view triggers, which fire on the rows a view's run writes.+ DataWarehouseMaterializedViews = 'data_warehouse_materialized_views',DataWarehouseProperties = 'data_warehouse_properties',DataWarehousePersonProperties = 'data_warehouse_person_properties',Elements = 'elements',@@ -375,6 +378,7 @@ export const OPEN_AS_SELF_ON_REOPEN = new Set<TaxonomicFilterGroupType>([TaxonomicFilterGroupType.HogQLExpression,TaxonomicFilterGroupType.DataWarehouse,TaxonomicFilterGroupType.DataWarehouseSourceTables,+ TaxonomicFilterGroupType.DataWarehouseMaterializedViews,TaxonomicFilterGroupType.DataWarehouseProperties,])diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex fa7de45fae45..a546bdc5d677 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -269,6 +269,7 @@ export const FEATURE_FLAGS = {BILLING_ALERTS: 'billing-alerts', // owner: #team-billing, gates the Billing > Alerts tabCDP_ACTIVITY_LOG_NOTIFICATIONS: 'cdp-activity-log-notifications', // owner: #team-workflows-cdpCDP_DWH_TABLE_SOURCE: 'cdp-dwh-table-source', // owner: #team-workflows-cdp+ CDP_DWH_VIEW_SOURCE: 'cdp-dwh-view-source', // owner: #team-workflows-cdpCDP_HOG_SOURCES: 'cdp-hog-sources', // owner #team-workflows-cdpCDP_NEW_PRICING: 'cdp-new-pricing', // owner: #team-workflowsCDP_PERSON_UPDATES: 'cdp-person-updates', // owner: #team-workflows-cdpdiff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 980d354551c3..9d8eef151673 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -51285,6 +51285,7 @@"cohorts_with_all","data_warehouse","data_warehouse_source_tables",+ "data_warehouse_materialized_views","data_warehouse_properties","data_warehouse_person_properties","elements",diff --git a/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsSceneLogic.ts b/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsSceneLogic.tsindex 25e287eec0d6..7bccc89ff23f 100644--- a/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsSceneLogic.ts+++ b/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsSceneLogic.ts@@ -51,6 +51,7 @@ export interface dataWarehouseSettingsSceneLogicValues {inEditSchemaMode: booleanisEditingSavedQuery: booleanmaterializedViews: DatabaseSchemaMaterializedViewTable[]+ materializedViewsLoading: booleannonMaterializedViews: DatabaseSchemaTable[]schemaModalIsOpen: booleanschemaUpdates: Record<string, DatabaseSerializedFieldType>@@ -204,6 +205,7 @@ export interface dataWarehouseSettingsSceneLogicMeta {views: DatabaseSchemaViewTable[],dataWarehouseSavedQueryMapById: Record<string, DataWarehouseSavedQuery>) => DatabaseSchemaTable[]+ materializedViewsLoading: (databaseLoading: boolean, dataWarehouseSavedQueriesLoading: boolean) => booleanmaterializedViews: (views: DatabaseSchemaViewTable[],dataWarehouseSavedQueryMapById: Record<string, DataWarehouseSavedQuery>@@ -401,6 +403,14 @@ export const dataWarehouseSettingsSceneLogic = kea<dataWarehouseSettingsSceneLog}))},],+ // `materializedViews` needs both loaders: names come from the database schema, the+ // materialized flag from the saved queries. Consumers that watch only one report an empty+ // list while the other is still in flight.+ materializedViewsLoading: [+ (s) => [s.databaseLoading, s.dataWarehouseSavedQueriesLoading],+ (databaseLoading: boolean, dataWarehouseSavedQueriesLoading: boolean): boolean =>+ databaseLoading || dataWarehouseSavedQueriesLoading,+ ],materializedViews: [(s) => [s.views, s.dataWarehouseSavedQueryMapById],(diff --git a/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsx b/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsxindex 3486a8fb3915..32b3379d07dd 100644--- a/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsx+++ b/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsx@@ -11,10 +11,13 @@ import { ExcludedProperties, TaxonomicFilterGroupType } from 'lib/components/Taximport { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { LemonField } from 'lib/lemon-ui/LemonField'+import { Link } from 'lib/lemon-ui/Link'import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'+import { dataWarehouseViewsLogic } from 'scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic'import { ActionFilter } from 'scenes/insights/filters/ActionFilter/ActionFilter'import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow'import MaxTool from 'scenes/max/MaxTool'+import { urls } from 'scenes/urls'import { groupsModel } from '~/models/groupsModel'import { AnyPropertyFilter, CyclotronJobFiltersType, EntityTypes, FilterType } from '~/types'@@ -112,14 +115,20 @@ export function HogFunctionFilters({])const isTransformation = type === 'transformation'- const isDataWarehouse = configuration?.filters?.source === 'data-warehouse-table'+ const filterSource = configuration?.filters?.source+ const isDataWarehouseView = filterSource === 'data-warehouse-view'+ // Both warehouse sources deliver a row rather than an event, so everything downstream of here+ // that hides person/event affordances applies to either.+ const isDataWarehouse = filterSource === 'data-warehouse-table' || isDataWarehouseViewconst cdpPersonUpdatesEnabled = useFeatureFlag('CDP_PERSON_UPDATES')const cdpDwhTableSourceEnabled = useFeatureFlag('CDP_DWH_TABLE_SOURCE')+ const cdpDwhViewSourceEnabled = useFeatureFlag('CDP_DWH_VIEW_SOURCE')// The table matcher's column suggestions read from databaseTableListLogic, which isn't loaded// automatically in this scene — kick it off when a warehouse table is the source.const { dataWarehouseTables, dataWarehouseTablesMap } = useValues(databaseTableListLogic)const { loadDatabase, ensureAllTableFields } = useActions(databaseTableListLogic)+ const { dataWarehouseSavedQueries } = useValues(dataWarehouseViewsLogic)useEffect(() => {if (isDataWarehouse) {if (!dataWarehouseTables.length) {@@ -182,9 +191,10 @@ export function HogFunctionFilters({// NOTE: Mappings won't work for person updates currently as they are totally event based...const showSourcePicker =- (cdpPersonUpdatesEnabled || cdpDwhTableSourceEnabled) && type === 'destination' && !useMapping- const showEventMatchers =- !useMapping && ['events', 'data-warehouse-table'].includes(configuration?.filters?.source ?? 'events')+ (cdpPersonUpdatesEnabled || cdpDwhTableSourceEnabled || cdpDwhViewSourceEnabled) &&+ type === 'destination' &&+ !useMapping+ const showEventMatchers = !useMapping && (isDataWarehouse || (filterSource ?? 'events') === 'events')const mainContent = (<div@@ -222,6 +232,9 @@ export function HogFunctionFilters({...(cdpDwhTableSourceEnabled? [{ value: 'data-warehouse-table', label: 'Warehouse table' }]: []),+ ...(cdpDwhViewSourceEnabled+ ? [{ value: 'data-warehouse-view', label: 'Materialized view' }]+ : []),]}value={value?.source ?? 'events'}onChange={(val) => {@@ -251,6 +264,14 @@ export function HogFunctionFilters({const dataWarehouseColumns = dataWarehouseTableName? Object.values(dataWarehouseTablesMap[dataWarehouseTableName]?.fields ?? {}): []+ // A full-refresh view re-emits every row on every run, which is worth saying out+ // loud before someone points a destination at one.+ const selectedFullRefreshView =+ isDataWarehouseView && dataWarehouseTableName+ ? dataWarehouseSavedQueries.find(+ (view) => view.name === dataWarehouseTableName && !view.is_incremental+ )+ : undefinedconst onChange = (newValue: CyclotronJobFiltersType): void => {if (oldFilters && newFilters) {@@ -299,11 +320,13 @@ export function HogFunctionFilters({<><div className="flex gap-2 justify-between w-full"><LemonLabel>- {isDataWarehouse- ? 'Match tables'- : isTransformation- ? 'Match events'- : 'Match events and actions'}+ {isDataWarehouseView+ ? 'Match materialized views'+ : isDataWarehouse+ ? 'Match tables'+ : isTransformation+ ? 'Match events'+ : 'Match events and actions'}</LemonLabel></div><p className="mb-0 text-xs text-secondary">@@ -318,7 +341,7 @@ export function HogFunctionFilters({...sanitizeActionFilters(payload),})}}- typeKey="plugin-filters"+ typeKey={isDataWarehouseView ? 'plugin-filters-view' : 'plugin-filters'}mathAvailability={MathAvailability.None}hideRenamehideDuplicate@@ -326,16 +349,23 @@ export function HogFunctionFilters({actionsTaxonomicGroupTypes={isTransformation? [TaxonomicFilterGroupType.Events]- : isDataWarehouse- ? [TaxonomicFilterGroupType.DataWarehouseSourceTables]- : [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions]+ : isDataWarehouseView+ ? [TaxonomicFilterGroupType.DataWarehouseMaterializedViews]+ : isDataWarehouse+ ? [TaxonomicFilterGroupType.DataWarehouseSourceTables]+ : [+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.Actions,+ ]}propertiesTaxonomicGroupTypes={taxonomicGroupTypes}propertyFiltersPopoveraddFilterDefaultOptions={isDataWarehouse? {- name: 'Select a table',+ name: isDataWarehouseView+ ? 'Select a materialized view'+ : 'Select a table',type: EntityTypes.DATA_WAREHOUSE,}: {@@ -344,10 +374,32 @@ export function HogFunctionFilters({type: EntityTypes.EVENTS,}}- buttonCopy={isDataWarehouse ? 'Add table matcher' : 'Add event matcher'}+ buttonCopy={+ isDataWarehouseView+ ? 'Add view matcher'+ : isDataWarehouse+ ? 'Add table matcher'+ : 'Add event matcher'+ }excludedProperties={excludedProperties}allowNonCapturedEvents/>+ {selectedFullRefreshView ? (+ <LemonBanner type="warning" className="w-full">+ <p className="mb-0">+ This view rebuilds its whole table on every run, so every row runs this+ destination again each time. Set the view to update incrementally to run+ only on the rows that changed.{' '}+ <Link+ to={urls.sqlEditor({ view_id: selectedFullRefreshView.id })}+ target="_blank"+ className="font-semibold"+ >+ Open the view+ </Link>+ </p>+ </LemonBanner>+ ) : null}{dataWarehouseTableName ? (<DataWarehouseColumnsHintschemaColumns={dataWarehouseColumns}diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsxindex 9864baa6ddd1..c42ed05122ad 100644--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx@@ -74,6 +74,13 @@ const DragHandle = ({ listeners }: DragHandleProps): JSX.Element => (// so numeric-only pickers must not be fed non-numeric columns in the first place.const NUMERIC_SCHEMA_FIELD_TYPES: DatabaseSerializedFieldType[] = ['integer', 'float', 'decimal']+// Which warehouse tables a row's picker may offer, by the caller's typeKey. Anything not listed+// gets the unrestricted data warehouse group.+const DATA_WAREHOUSE_GROUP_TYPE_BY_TYPE_KEY: Record<string, TaxonomicFilterGroupType> = {+ 'plugin-filters': TaxonomicFilterGroupType.DataWarehouseSourceTables,+ 'plugin-filters-view': TaxonomicFilterGroupType.DataWarehouseMaterializedViews,+}+export function ActionFilterRow({logic,filter,@@ -348,11 +355,10 @@ export function ActionFilterRow({)const isDataWarehouseFilter = filter.type === EntityTypes.DATA_WAREHOUSE- // CDP destination/workflow filters (plugin-filters) restrict the picker to external-source tables.+ // CDP destination/workflow filters restrict the picker to the one warehouse table family their+ // trigger fires on, so each family gets its own typeKey.const dataWarehouseGroupType =- typeKey === 'plugin-filters'- ? TaxonomicFilterGroupType.DataWarehouseSourceTables- : TaxonomicFilterGroupType.DataWarehouse+ DATA_WAREHOUSE_GROUP_TYPE_BY_TYPE_KEY[typeKey] ?? TaxonomicFilterGroupType.DataWarehouse// The committed value's real group — it drives the picker's committed-selection// affordance (selected row floats to the top, with the series' rename applied).// The picker still opens on the suggested-filters surface either way. All-eventsdiff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/actionFilterRowUtils.ts b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/actionFilterRowUtils.tsindex e3d6ccc69e8e..53eb54dce8ef 100644--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/actionFilterRowUtils.ts+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/actionFilterRowUtils.ts@@ -20,6 +20,7 @@ const taxonomicFilterGroupTypeToEntityTypeMapping: Partial<Record<TaxonomicFilte[TaxonomicFilterGroupType.Actions]: EntityTypes.ACTIONS,[TaxonomicFilterGroupType.DataWarehouse]: EntityTypes.DATA_WAREHOUSE,[TaxonomicFilterGroupType.DataWarehouseSourceTables]: EntityTypes.DATA_WAREHOUSE,+ [TaxonomicFilterGroupType.DataWarehouseMaterializedViews]: EntityTypes.DATA_WAREHOUSE,}export function taxonomicFilterGroupTypeToEntityType(diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.tsindex f4e809d30c00..996449b49f50 100644--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts@@ -78,6 +78,7 @@ export interface taxonomicBreakdownFilterLogicValues {| TaxonomicFilterGroupType.CohortsWithAllUsers| TaxonomicFilterGroupType.DataWarehouse| TaxonomicFilterGroupType.DataWarehouseSourceTables+ | TaxonomicFilterGroupType.DataWarehouseMaterializedViews| TaxonomicFilterGroupType.DataWarehouseProperties| TaxonomicFilterGroupType.DataWarehousePersonProperties| TaxonomicFilterGroupType.Elements@@ -243,6 +244,7 @@ export interface taxonomicBreakdownFilterLogicMeta {| TaxonomicFilterGroupType.CohortsWithAllUsers| TaxonomicFilterGroupType.DataWarehouse| TaxonomicFilterGroupType.DataWarehouseSourceTables+ | TaxonomicFilterGroupType.DataWarehouseMaterializedViews| TaxonomicFilterGroupType.DataWarehouseProperties| TaxonomicFilterGroupType.DataWarehousePersonProperties| TaxonomicFilterGroupType.Elementsdiff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 8e009c333f52..f776eca8e273 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -6252,6 +6252,9 @@ export interface DataWarehouseSavedQuery {latest_error: string | nulllatest_history_id?: stringis_materialized?: boolean+ /** Whether the view is set up to update incrementally. A run can still rebuild the whole table,+ * for example on its first run or after the query changes. */+ is_incremental?: boolean/** Engine → suspension details. Only included when fetching a single saved query, not in list responses */suspended?: DataWarehouseSavedQueryApiSuspendedupstream_dependency_count?: number@@ -7313,7 +7316,7 @@ export type CyclotronJobFilterPropertyFilter =| FlagPropertyFilterexport interface CyclotronJobFiltersType {- source?: 'events' | 'person-updates' | 'data-warehouse-table'+ source?: 'events' | 'person-updates' | 'data-warehouse-table' | 'data-warehouse-view'events?: CyclotronJobFilterEvents[]data_warehouse?: CyclotronJobFilterDataWarehouse[]actions?: CyclotronJobFilterActions[]diff --git a/posthog/schema_enums.py b/posthog/schema_enums.pyindex c70e271c2728..f216f02bf3a5 100644--- a/posthog/schema_enums.py+++ b/posthog/schema_enums.py@@ -4014,6 +4014,7 @@ class TaxonomicFilterGroupType(StrEnum):COHORTS_WITH_ALL = "cohorts_with_all"DATA_WAREHOUSE = "data_warehouse"DATA_WAREHOUSE_SOURCE_TABLES = "data_warehouse_source_tables"+ DATA_WAREHOUSE_MATERIALIZED_VIEWS = "data_warehouse_materialized_views"DATA_WAREHOUSE_PROPERTIES = "data_warehouse_properties"DATA_WAREHOUSE_PERSON_PROPERTIES = "data_warehouse_person_properties"ELEMENTS = "elements"diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex c1551ce712a3..fdafc0f3fd99 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -5326,6 +5326,7 @@ export const TaxonomicFilterGroupTypeApi = {CohortsWithAll: 'cohorts_with_all',DataWarehouse: 'data_warehouse',DataWarehouseSourceTables: 'data_warehouse_source_tables',+ DataWarehouseMaterializedViews: 'data_warehouse_materialized_views',DataWarehouseProperties: 'data_warehouse_properties',DataWarehousePersonProperties: 'data_warehouse_person_properties',Elements: 'elements',diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex c97e3ffc721a..27592e4a9ed8 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -4488,6 +4488,7 @@ export const TaxonomicFilterGroupTypeApi = {CohortsWithAll: 'cohorts_with_all',DataWarehouse: 'data_warehouse',DataWarehouseSourceTables: 'data_warehouse_source_tables',+ DataWarehouseMaterializedViews: 'data_warehouse_materialized_views',DataWarehouseProperties: 'data_warehouse_properties',DataWarehousePersonProperties: 'data_warehouse_person_properties',Elements: 'elements',diff --git a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsxindex 58bcbb192a7a..2406ccfbc3c4 100644--- a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx+++ b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx@@ -751,6 +751,14 @@ export interface hogFlowEditorLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -899,6 +907,14 @@ export interface hogFlowEditorLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -1563,6 +1579,14 @@ export interface hogFlowEditorLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -1711,6 +1735,14 @@ export interface hogFlowEditorLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,diff --git a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.tsindex 3caf6c2ec630..0a94f471bb61 100644--- a/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/panel/testing/hogFlowEditorTestLogic.ts@@ -389,6 +389,14 @@ export interface hogFlowEditorTestLogicMeta {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -511,6 +519,14 @@ export interface hogFlowEditorTestLogicMeta {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,diff --git a/products/workflows/frontend/Workflows/hogflows/registry/triggers/data_warehouse_view.test.ts b/products/workflows/frontend/Workflows/hogflows/registry/triggers/data_warehouse_view.test.tsnew file mode 100644index 000000000000..8ba18f0e60ea--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/registry/triggers/data_warehouse_view.test.ts@@ -0,0 +1,63 @@+import { isDataWarehouseViewTriggerConfig } from './data_warehouse_view'+import { getRegisteredTriggerTypes } from './triggerTypeRegistry'++describe('materialized view trigger', () => {+ const getTriggerType = (): ReturnType<typeof getRegisteredTriggerTypes>[number] => {+ const triggerType = getRegisteredTriggerTypes().find((t) => t.value === 'data-warehouse-view')+ if (!triggerType) {+ throw new Error('Materialized view trigger type not registered')+ }+ return triggerType+ }++ describe('isDataWarehouseViewTriggerConfig', () => {+ it.each([+ {+ name: 'data-warehouse-view config',+ config: { type: 'data-warehouse-view', table_name: 'daily_revenue' } as any,+ expected: true,+ },+ {+ name: 'data-warehouse-table config',+ config: { type: 'data-warehouse-table', table_name: 'daily_revenue' } as any,+ expected: false,+ },+ { name: 'event config', config: { type: 'event', filters: {} } as any, expected: false },+ ])('returns $expected for $name', ({ config, expected }) => {+ expect(isDataWarehouseViewTriggerConfig(config)).toBe(expected)+ })+ })++ describe('validate', () => {+ it.each([+ {+ name: 'missing view name',+ config: { type: 'data-warehouse-view', table_name: '', filters: { properties: [] } },+ expected: { valid: false, errors: { table_name: 'Please select a materialized view' } },+ },+ {+ name: 'view name set',+ config: { type: 'data-warehouse-view', table_name: 'daily_revenue', filters: { properties: [] } },+ expected: { valid: true, errors: {} },+ },+ {+ name: 'non data-warehouse-view config returns null',+ config: { type: 'data-warehouse-table', table_name: 'postgres.table_1' },+ expected: null,+ },+ ])('returns $expected for $name', ({ config, expected }) => {+ expect(getTriggerType().validate!(config as any)).toEqual(expected)+ })+ })++ it('is gated behind its own feature flag, separately from the source table trigger', () => {+ expect(getTriggerType().featureFlag).toBe('cdp-dwh-view-source')+ })++ it('buildConfig produces a config recognized by matchConfig', () => {+ const triggerType = getTriggerType()+ const config = triggerType.buildConfig()+ expect(config.type).toBe('data-warehouse-view')+ expect(triggerType.matchConfig!(config)).toBe(true)+ })+})diff --git a/products/workflows/frontend/Workflows/hogflows/registry/triggers/data_warehouse_view.tsx b/products/workflows/frontend/Workflows/hogflows/registry/triggers/data_warehouse_view.tsxnew file mode 100644index 000000000000..97b781c8c2cc--- /dev/null+++ b/products/workflows/frontend/Workflows/hogflows/registry/triggers/data_warehouse_view.tsx@@ -0,0 +1,186 @@+import { useActions, useValues } from 'kea'+import { useEffect } from 'react'++import { IconServer } from '@posthog/icons'+import { LemonBanner, LemonSelect, LemonTag } from '@posthog/lemon-ui'++import { DataWarehouseColumnsHint } from 'lib/components/CyclotronJob/DataWarehouseColumnsHint'+import { LemonField } from 'lib/lemon-ui/LemonField'+import { Link } from 'lib/lemon-ui/Link'+import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'+import { dataWarehouseViewsLogic } from 'scenes/data-warehouse/saved_queries/dataWarehouseViewsLogic'+import { urls } from 'scenes/urls'++import { HogFlowPropertyFilters } from 'products/workflows/frontend/Workflows/hogflows/filters/HogFlowFilters'+import { registerTriggerType } from 'products/workflows/frontend/Workflows/hogflows/registry/triggers/triggerTypeRegistry'+import { workflowLogic } from 'products/workflows/frontend/Workflows/workflowLogic'++import { HogFlowAction } from '../../types'++export type DataWarehouseViewTriggerConfig = {+ type: 'data-warehouse-view'+ table_name: string+ filters: {+ properties?: any[]+ }+ key_property?: string+}++export function isDataWarehouseViewTriggerConfig(+ config: Extract<HogFlowAction, { type: 'trigger' }>['config']+): config is DataWarehouseViewTriggerConfig {+ return config.type === 'data-warehouse-view'+}++function StepTriggerConfigurationDataWarehouseView({ node }: { node: any }): JSX.Element {+ const { setWorkflowActionConfig } = useActions(workflowLogic)+ const { actionValidationErrorsById } = useValues(workflowLogic)+ const { dataWarehouseTables, dataWarehouseTablesMap, views, databaseLoading } = useValues(databaseTableListLogic)+ const { loadDatabase, ensureAllTableFields } = useActions(databaseTableListLogic)+ const { dataWarehouseSavedQueryMapById, dataWarehouseSavedQueriesLoading } = useValues(dataWarehouseViewsLogic)++ useEffect(() => {+ // The list isn't loaded automatically on mount, so kick it off when the panel opens.+ if (!dataWarehouseTables.length && !views.length) {+ loadDatabase()+ } else {+ // The store may hold a shallow (fields-less) schema left by the SQL editor.+ ensureAllTableFields()+ }+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [])++ const config = node.data.config as DataWarehouseViewTriggerConfig+ const selectedTableName = config.table_name || null+ const properties = config.filters?.properties ?? []+ const validationResult = actionValidationErrorsById[node.data.id]++ // Only a materialized view writes rows on a schedule, so a plain view has nothing to trigger on.+ const materializedViews = views.filter((view) => dataWarehouseSavedQueryMapById[view.id]?.is_materialized)+ // The list needs both logics: the names come from the database schema and the materialized flag+ // from the saved queries. Waiting on only one of them claims the project has no views while the+ // other is still in flight.+ const loading = databaseLoading || dataWarehouseSavedQueriesLoading+ const hasNoViews = !loading && materializedViews.length === 0++ const viewOptions = materializedViews.map((view) => {+ const incremental = dataWarehouseSavedQueryMapById[view.id]?.is_incremental+ return {+ label: view.name,+ value: view.name,+ labelInMenu: (+ <span className="flex items-center gap-2">+ {view.name}+ <LemonTag type={incremental ? 'success' : 'warning'}>+ {incremental ? 'Incremental' : 'Full refresh'}+ </LemonTag>+ </span>+ ),+ }+ })++ const selectedView = materializedViews.find((view) => view.name === selectedTableName)+ const selectedSavedQuery = selectedView ? dataWarehouseSavedQueryMapById[selectedView.id] : undefined+ const selectedIsFullRefresh = !!selectedView && !selectedSavedQuery?.is_incremental++ const schemaColumns = selectedTableName+ ? Object.values(dataWarehouseTablesMap[selectedTableName]?.fields ?? {})+ : []++ const updateTriggerConfig = (tableName: string | null, newProperties: any[]): void => {+ setWorkflowActionConfig(node.data.id, {+ type: 'data-warehouse-view',+ table_name: tableName ?? '',+ filters: { properties: newProperties },+ // Preserve any existing masking/dedup key set via the API or a future UI+ ...(config.key_property ? { key_property: config.key_property } : {}),+ })+ }++ return (+ <div className="flex flex-col gap-2 w-full">+ <p className="mb-0 text-sm text-muted-alt">+ This workflow runs once for each row a materialized view adds or updates. Runs are row-scoped, so there+ is no associated person and person-dependent steps are unavailable.+ </p>+ <LemonField.Pure label="Materialized view" error={validationResult?.errors?.table_name}>+ <LemonSelect+ options={viewOptions}+ value={selectedTableName}+ loading={loading}+ disabledReason={hasNoViews ? 'Materialize a view first' : undefined}+ onChange={(tableName) => updateTriggerConfig(tableName, properties)}+ placeholder="Select a materialized view"+ />+ {hasNoViews && (+ <LemonBanner type="warning" className="w-full mt-1">+ <p className="mb-0">+ You don't have any materialized views yet, so this trigger has nothing to listen to.+ Materialize a view first, then come back and pick the one this workflow should run on.{' '}+ <Link to={urls.sqlEditor({})} target="_blank" className="font-semibold">+ Open the SQL editor+ </Link>+ </p>+ </LemonBanner>+ )}+ </LemonField.Pure>++ {selectedIsFullRefresh && (+ <LemonBanner type="warning" className="w-full">+ <p className="mb-0">+ This view rebuilds its whole table on every run, so every row runs this workflow again each+ time. Set the view to update incrementally to run only on the rows that changed.{' '}+ {selectedView && (+ <Link+ to={urls.sqlEditor({ view_id: selectedView.id })}+ target="_blank"+ className="font-semibold"+ >+ Open the view+ </Link>+ )}+ </p>+ </LemonBanner>+ )}++ {selectedTableName ? (+ <DataWarehouseColumnsHint schemaColumns={schemaColumns} tableName={selectedTableName} />+ ) : null}++ <LemonField.Pure label="Only trigger for specific rows">+ <HogFlowPropertyFilters+ filtersKey={`data-warehouse-view-trigger-${node.data.id}`}+ filters={{ properties }}+ setFilters={(filters) => updateTriggerConfig(selectedTableName, filters?.properties ?? [])}+ schemaColumns={schemaColumns}+ dataWarehouseTableName={selectedTableName ?? undefined}+ />+ </LemonField.Pure>+ </div>+ )+}++registerTriggerType({+ value: 'data-warehouse-view',+ label: 'Materialized view row updated',+ icon: <IconServer />,+ description: 'Trigger when a materialized view adds or updates a row',+ group: 'Data warehouse',+ featureFlag: 'cdp-dwh-view-source',+ matchConfig: (config) => isDataWarehouseViewTriggerConfig(config),+ buildConfig: () => ({+ type: 'data-warehouse-view',+ table_name: '',+ filters: { properties: [] },+ }),+ validate: (config): { valid: boolean; errors: Record<string, string> } | null => {+ if (config.type !== 'data-warehouse-view') {+ return null+ }+ if (!config.table_name) {+ return { valid: false, errors: { table_name: 'Please select a materialized view' } }+ }+ return { valid: true, errors: {} }+ },+ ConfigComponent: StepTriggerConfigurationDataWarehouseView,+})diff --git a/products/workflows/frontend/Workflows/hogflows/registry/triggers/index.ts b/products/workflows/frontend/Workflows/hogflows/registry/triggers/index.tsindex 80be7034364f..876a674c8a99 100644--- a/products/workflows/frontend/Workflows/hogflows/registry/triggers/index.ts+++ b/products/workflows/frontend/Workflows/hogflows/registry/triggers/index.ts@@ -1,5 +1,6 @@import './conversations'import './customer_analytics'import './data_warehouse_table'+import './data_warehouse_view'import './slack'import './surveys'diff --git a/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.ts b/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.tsindex cbec9c77c12a..2208cbd2b3c1 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.ts@@ -222,6 +222,14 @@ export interface stepDelayLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -416,6 +424,14 @@ export interface stepDelayLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,diff --git a/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.ts b/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.tsindex cdd59e79822e..89054803e393 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.ts@@ -263,6 +263,14 @@ export interface stepWaitUntilTimeWindowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -458,6 +466,14 @@ export interface stepWaitUntilTimeWindowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,diff --git a/products/workflows/frontend/Workflows/hogflows/steps/types.ts b/products/workflows/frontend/Workflows/hogflows/steps/types.tsindex 06cd4cb1ce28..e3d34f9582dc 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/types.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/types.ts@@ -189,6 +189,15 @@ export const HogFlowTriggerSchema = z.discriminatedUnion('type', [properties: z.array(z.any()).optional(),}),}),+ z.object({+ type: z.literal('data-warehouse-view'),+ // The materialized view's own name, which is also its HogQL name+ table_name: z.string(),+ filters: z.object({+ properties: z.array(z.any()).optional(),+ }),+ key_property: z.string().optional(),+ }),])/** Trigger types that use HogFlowSchedule for recurring execution */diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.tsindex 43a02c403010..4906fba83f77 100644--- a/products/workflows/frontend/Workflows/workflowLogic.ts+++ b/products/workflows/frontend/Workflows/workflowLogic.ts@@ -112,9 +112,10 @@ export const NEW_WORKFLOW: HogFlow = {// data-warehouse-table triggers. Module-scoped to avoid reallocating on every selector recompute.export const PERSON_DEPENDENT_ACTION_TYPES = new Set(['wait_until_condition', 'random_cohort_branch'])-// Trigger types whose runs have no person attached. Keep in sync with the backend's-// ROW_SCOPED_TRIGGER_TYPES, which is the authoritative check.-export const ROW_SCOPED_TRIGGER_TYPES = new Set(['data-warehouse-table', 'slack-message'])+// Trigger types whose runs have no person attached: a synced warehouse row, a materialized view+// row, and a Slack poster are all things no PostHog person is attached to. Keep in sync with the+// backend's ROW_SCOPED_TRIGGER_TYPES, which is the authoritative check.+export const ROW_SCOPED_TRIGGER_TYPES = new Set(['data-warehouse-table', 'data-warehouse-view', 'slack-message'])function getTemplatingError(value: string, templating?: 'liquid' | 'hog'): string | undefined {if (templating === 'liquid' && typeof value === 'string') {@@ -761,6 +762,14 @@ export interface workflowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -1019,6 +1028,14 @@ export interface workflowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -1573,6 +1590,14 @@ export interface workflowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -1831,6 +1856,14 @@ export interface workflowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -2112,6 +2145,14 @@ export interface workflowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -2467,6 +2508,14 @@ export interface workflowLogicActions {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -2730,6 +2779,14 @@ export interface workflowLogicMeta {table_name: stringtype: 'data-warehouse-table'}+ | {+ filters: {+ properties?: any[] | undefined+ }+ key_property?: string | undefined+ table_name: string+ type: 'data-warehouse-view'+ }| {inputs: Record<string,@@ -3514,7 +3571,7 @@ export const workflowLogic = kea<workflowLogicType>([isRowScopedTrigger: [(s) => [s.triggerAction],(triggerAction: TriggerAction | null): boolean =>- ROW_SCOPED_TRIGGER_TYPES.has(triggerAction?.config?.type as string),+ ROW_SCOPED_TRIGGER_TYPES.has(triggerAction?.config?.type ?? ''),],workflowSanitized: [diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex ddc7b0640de2..c7a9ffa701c0 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -6688,6 +6688,7 @@ export namespace Schemas {CohortsWithAll: 'cohorts_with_all',DataWarehouse: 'data_warehouse',DataWarehouseSourceTables: 'data_warehouse_source_tables',+ DataWarehouseMaterializedViews: 'data_warehouse_materialized_views',DataWarehouseProperties: 'data_warehouse_properties',DataWarehousePersonProperties: 'data_warehouse_person_properties',Elements: 'elements',