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

chore(editor-3000): move over materialization #26619

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Changes from all commits
Commits
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
167 changes: 164 additions & 3 deletions frontend/src/scenes/data-warehouse/editor/editorSidebarLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Fuse from 'fuse.js'
import { connect, kea, path, selectors } from 'kea'
import { router } from 'kea-router'
import { subscriptions } from 'kea-subscriptions'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { sceneLogic } from 'scenes/sceneLogic'
import { Scene } from 'scenes/sceneTypes'
Expand All @@ -14,6 +16,7 @@ import { DatabaseSchemaDataWarehouseTable, DatabaseSchemaTable } from '~/queries
import { DataWarehouseSavedQuery, PipelineTab } from '~/types'

import { dataWarehouseViewsLogic } from '../saved_queries/dataWarehouseViewsLogic'
import { viewLinkLogic } from '../viewLinkLogic'
import { editorSceneLogic } from './editorSceneLogic'
import type { editorSidebarLogicType } from './editorSidebarLogicType'
import { multitabEditorLogic } from './multitabEditorLogic'
Expand All @@ -39,6 +42,20 @@ const savedQueriesfuse = new Fuse<DataWarehouseSavedQuery>([], {
includeMatches: true,
})

const nonMaterializedViewsfuse = new Fuse<DataWarehouseSavedQuery>([], {
keys: [{ name: 'name', weight: 2 }],
threshold: 0.3,
ignoreLocation: true,
includeMatches: true,
})

const materializedViewsfuse = new Fuse<DataWarehouseSavedQuery>([], {
keys: [{ name: 'name', weight: 2 }],
threshold: 0.3,
ignoreLocation: true,
includeMatches: true,
})

export const editorSidebarLogic = kea<editorSidebarLogicType>([
path(['data-warehouse', 'editor', 'editorSidebarLogic']),
connect({
Expand All @@ -49,8 +66,17 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
['dataWarehouseSavedQueries', 'dataWarehouseSavedQueryMapById', 'dataWarehouseSavedQueriesLoading'],
databaseTableListLogic,
['posthogTables', 'dataWarehouseTables', 'databaseLoading', 'views', 'viewsMapById'],
featureFlagLogic,
['featureFlags'],
],
actions: [
editorSceneLogic,
['selectSchema'],
dataWarehouseViewsLogic,
['deleteDataWarehouseSavedQuery', 'runDataWarehouseSavedQuery'],
viewLinkLogic,
['selectSourceTable', 'toggleJoinTableModal'],
],
actions: [editorSceneLogic, ['selectSchema'], dataWarehouseViewsLogic, ['deleteDataWarehouseSavedQuery']],
}),
selectors(({ actions }) => ({
contents: [
Expand All @@ -60,13 +86,19 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
s.relevantPosthogTables,
s.relevantDataWarehouseTables,
s.databaseLoading,
s.relevantNonMaterializedViews,
s.relevantMaterializedViews,
s.featureFlags,
],
(
relevantSavedQueries,
dataWarehouseSavedQueriesLoading,
relevantPosthogTables,
relevantDataWarehouseTables,
databaseLoading
databaseLoading,
relevantNonMaterializedViews,
relevantMaterializedViews,
featureFlags
) => [
{
key: 'data-warehouse-sources',
Expand All @@ -85,6 +117,15 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
onClick: () => {
actions.selectSchema(table)
},
menuItems: [
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(table.name)
actions.toggleJoinTableModal()
},
},
],
})),
onAdd: () => {
router.actions.push(urls.pipeline(PipelineTab.Sources))
Expand All @@ -107,13 +148,25 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
onClick: () => {
actions.selectSchema(table)
},
menuItems: [
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(table.name)
actions.toggleJoinTableModal()
},
},
],
})),
} as SidebarCategory,
{
key: 'data-warehouse-views',
noun: ['view', 'views'],
loading: dataWarehouseSavedQueriesLoading,
items: relevantSavedQueries.map(([savedQuery, matches]) => ({
items: (featureFlags[FEATURE_FLAGS.DATA_MODELING]
? relevantNonMaterializedViews
: relevantSavedQueries
).map(([savedQuery, matches]) => ({
key: savedQuery.id,
name: savedQuery.name,
url: '',
Expand All @@ -135,6 +188,23 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
}).actions.createTab(savedQuery.query.query, savedQuery)
},
},
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(savedQuery.name)
actions.toggleJoinTableModal()
},
},
...(featureFlags[FEATURE_FLAGS.DATA_MODELING] && !savedQuery.status
? [
{
label: 'Materialize',
onClick: () => {
actions.runDataWarehouseSavedQuery(savedQuery.id)
},
},
]
: []),
{
label: 'Delete',
status: 'danger',
Expand All @@ -145,8 +215,77 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
],
})),
} as SidebarCategory,
...(featureFlags[FEATURE_FLAGS.DATA_MODELING]
? [
{
key: 'data-warehouse-materialized-views',
noun: ['materialized view', 'materialized views'],
loading: dataWarehouseSavedQueriesLoading,
items: relevantMaterializedViews.map(([materializedView, matches]) => ({
key: materializedView.id,
name: materializedView.name,
url: '',
searchMatch: matches
? {
matchingFields: matches.map((match) => match.key),
nameHighlightRanges: matches.find((match) => match.key === 'name')?.indices,
}
: null,
onClick: () => {
actions.selectSchema(materializedView)
},
menuItems: [
{
label: 'Edit view definition',
onClick: () => {
multitabEditorLogic({
key: `hogQLQueryEditor/${router.values.location.pathname}`,
}).actions.createTab(materializedView.query.query, materializedView)
},
},
{
label: 'Add join',
onClick: () => {
actions.selectSourceTable(materializedView.name)
actions.toggleJoinTableModal()
},
},
...(featureFlags[FEATURE_FLAGS.DATA_MODELING] && materializedView.status
? [
{
label: 'Run',
onClick: () => {
actions.runDataWarehouseSavedQuery(materializedView.id)
},
},
]
: []),
{
label: 'Delete',
status: 'danger',
onClick: () => {
actions.deleteDataWarehouseSavedQuery(materializedView.id)
},
},
],
})),
},
]
: []),
],
],
nonMaterializedViews: [
(s) => [s.dataWarehouseSavedQueries],
(views): DataWarehouseSavedQuery[] => {
return views.filter((view) => !view.status && !view.last_run_at)
},
],
materializedViews: [
(s) => [s.dataWarehouseSavedQueries],
(views): DataWarehouseSavedQuery[] => {
return views.filter((view) => view.status || view.last_run_at)
},
],
activeListItemKey: [
(s) => [s.activeScene, s.sceneParams],
(activeScene, sceneParams): [string, number] | null => {
Expand Down Expand Up @@ -188,6 +327,28 @@ export const editorSidebarLogic = kea<editorSidebarLogicType>([
return dataWarehouseSavedQueries.map((savedQuery) => [savedQuery, null])
},
],
relevantNonMaterializedViews: [
(s) => [s.nonMaterializedViews, navigation3000Logic.selectors.searchTerm],
(nonMaterializedViews, searchTerm): [DataWarehouseSavedQuery, FuseSearchMatch[] | null][] => {
if (searchTerm) {
return nonMaterializedViewsfuse
.search(searchTerm)
.map((result) => [result.item, result.matches as FuseSearchMatch[]])
}
return nonMaterializedViews.map((view) => [view, null])
},
],
relevantMaterializedViews: [
(s) => [s.materializedViews, navigation3000Logic.selectors.searchTerm],
(materializedViews, searchTerm): [DataWarehouseSavedQuery, FuseSearchMatch[] | null][] => {
if (searchTerm) {
return materializedViewsfuse
.search(searchTerm)
.map((result) => [result.item, result.matches as FuseSearchMatch[]])
}
return materializedViews.map((view) => [view, null])
},
],
})),
subscriptions({
dataWarehouseTables: (dataWarehouseTables) => {
Expand Down
Loading