: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(sql-editor): default send raw query to on for the managed warehouse connection (#74679)
Eric Duongb67ec17337ae
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.tsindex e4da3e0c8ca1..2a05ebca80b7 100644--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts@@ -24,7 +24,12 @@ import { ChartDisplayType, InsightShortId, QueryBasedInsightModel } from '~/typeimport { editorSceneLogic } from './editorSceneLogic'import { OutputTab } from './outputPaneLogic'-import { activeTabMatchesUrlTarget, getDisplayTypeToSaveInsight, sqlEditorLogic } from './sqlEditorLogic'+import {+ activeTabMatchesUrlTarget,+ getDisplayTypeToSaveInsight,+ sqlEditorLogic,+ MANAGED_WAREHOUSE_SOURCE_PREFIX,+} from './sqlEditorLogic'import { SQLEditorMode } from './sqlEditorModes'// endpointLogic uses permanentlyMount() with a keyed logic, which crashes in@@ -1546,6 +1551,105 @@ describe('sqlEditorLogic', () => {expect(String(router.values.hashParams.raw)).toEqual('1')})+ it('defaults to raw SQL mode for the managed warehouse connection', async () => {+ useMocks({+ get: {+ '/api/projects/:team_id/external_data_sources/connections/': [+ 200,+ [+ {+ id: 'managed-conn-1',+ prefix: MANAGED_WAREHOUSE_SOURCE_PREFIX,+ engine: 'duckdb',+ source_type: 'Postgres',+ access_method: 'direct',+ supports_hogql: true,+ },+ ],+ ],+ '/api/environments/:team_id/external_data_sources/': [+ 200,+ {+ results: [+ {+ id: 'managed-conn-1',+ source_id: 'src-managed-1',+ prefix: MANAGED_WAREHOUSE_SOURCE_PREFIX,+ source_type: 'Postgres',+ access_method: 'direct',+ engine: 'duckdb',+ } as any,+ ],+ },+ ],+ },+ })+ logic = sqlEditorLogic({+ tabId: TAB_ID,+ monaco: createMockMonaco(),+ editor: createMockEditor(),+ })+ logic.mount()++ router.actions.push(urls.sqlEditor(), undefined, { q: 'SELECT 1', c: 'managed-conn-1' })++ await expectLogic(logic).toDispatchActions(['setSourceQuery', 'createTab', 'updateTab'])+ await expectLogic(logic).toDispatchActions(['setSendRawQuery'])++ expect(logic.values.selectedConnectionSupportsHogQL).toEqual(true)+ expect(logic.values.sourceQuery.source.sendRawQuery).toEqual(true)+ expect(logic.values.sendRawQueryEnabled).toEqual(true)+ })++ it('does not force raw SQL mode for a user-managed Postgres direct connection', async () => {+ useMocks({+ get: {+ '/api/projects/:team_id/external_data_sources/connections/': [+ 200,+ [+ {+ id: 'user-conn-1',+ prefix: 'my_postgres',+ engine: 'postgres',+ source_type: 'Postgres',+ access_method: 'direct',+ supports_hogql: true,+ },+ ],+ ],+ '/api/environments/:team_id/external_data_sources/': [+ 200,+ {+ results: [+ {+ id: 'user-conn-1',+ source_id: 'src-user-1',+ prefix: 'my_postgres',+ source_type: 'Postgres',+ access_method: 'direct',+ engine: 'postgres',+ } as any,+ ],+ },+ ],+ },+ })+ logic = sqlEditorLogic({+ tabId: TAB_ID,+ monaco: createMockMonaco(),+ editor: createMockEditor(),+ })+ logic.mount()++ router.actions.push(urls.sqlEditor(), undefined, { q: 'SELECT 1', c: 'user-conn-1' })++ await expectLogic(logic).toDispatchActions(['setSourceQuery', 'createTab', 'updateTab'])++ expect(logic.values.selectedConnectionSupportsHogQL).toEqual(true)+ expect(logic.values.sourceQuery.source.sendRawQuery).toBeUndefined()+ expect(logic.values.sendRawQueryEnabled).toEqual(false)+ })+it('forces raw SQL mode when the selected connection does not support HogQL', async () => {useMocks({get: {diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsxindex c72a078f7c71..07ff74f7c7cd 100644--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx@@ -92,6 +92,9 @@ import { validateEndpointName } from 'products/endpoints/frontend/common'import type { ExternalDataSourceConnectionOptionApi } from '../../../../../products/warehouse_sources/frontend/generated/api.schemas'import type { PaginatedResponse } from '../../../lib/api'++// Mirrors MANAGED_WAREHOUSE_SOURCE_PREFIX in products/warehouse_sources/backend/models/external_data_source.py.+export const MANAGED_WAREHOUSE_SOURCE_PREFIX = 'managed_warehouse'import type { FeatureFlagsSet } from '../../../lib/logic/featureFlagLogic'import type { DatabaseSchemaQueryResponse, Node } from '../../../queries/schema/schema-general'import type { DataModelingDAG, DataWarehouseSavedQueryFolder, UserType } from '../../../types'@@ -1820,12 +1823,19 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([},enforceConnectionRawQueryMode: () => {// Raw-only connections cannot compile HogQL — force raw SQL mode.- if (- values.selectedConnectionId &&- !values.selectedConnectionSupportsHogQL &&- !values.sourceQuery.source.sendRawQuery- ) {- actions.setSendRawQuery(true)+ // The managed warehouse (auto-provisioned Duckgres) speaks DuckDB+ // natively end-to-end, so raw mode is the better default for it too:+ // it skips the HogQL reprint and reaches the engine verbatim.+ if (values.selectedConnectionId && !values.sourceQuery.source.sendRawQuery) {+ const option = (values.connectionOptions ?? []).find(+ (option) => option.id === values.selectedConnectionId+ )+ const isManagedWarehouseSource =+ option?.prefix === MANAGED_WAREHOUSE_SOURCE_PREFIX && option?.source_type === 'Postgres'++ if (!values.selectedConnectionSupportsHogQL || isManagedWarehouseSource) {+ actions.setSendRawQuery(true)+ }}},// Options can load after a connection was restored from the URL.