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.

refactor(batch-exports): refactor frontend destination config (#61103)

Rossb41291f8d991
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx
index 9fc0f1e0bc59..25304ac63118 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx
+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx
@@ -1,19 +1,9 @@
-import React from 'react'
-
import { IconInfo } from '@posthog/icons'
-import {
- LemonCalendarSelectInput,
- LemonCheckbox,
- LemonInput,
- LemonSelect,
- LemonTextArea,
- Link,
- Tooltip,
-} from '@posthog/lemon-ui'
+import { LemonCalendarSelectInput, LemonCheckbox, LemonInput, Tooltip } from '@posthog/lemon-ui'
-import { IntegrationChoice } from 'lib/components/CyclotronJob/integrations/IntegrationChoice'
import { LemonField } from 'lib/lemon-ui/LemonField'
+import { DESTINATIONS } from './destinations'
import { BatchExportConfigurationForm } from './types'
export function BatchExportGeneralEditFields({
@@ -84,6 +74,8 @@ export function BatchExportGeneralEditFields({
)
}
+// Per-destination field rendering is owned by the registry under ./destinations/.
+// To add a new destination, create a new file there and register it in destinations/index.ts.
export function BatchExportsEditFields({
isNew,
batchExportConfigForm,
@@ -93,811 +85,18 @@ export function BatchExportsEditFields({
batchExportConfigForm: BatchExportConfigurationForm
configurationChanged: boolean
}): JSX.Element {
+ const destination = batchExportConfigForm.destination
+ const definition = destination ? DESTINATIONS[destination] : undefined
+
return (
<div className="flex flex-col gap-y-4 max-w-200">
- {batchExportConfigForm.destination === 'S3' ? (
- <>
- <div className="flex gap-4">
- <LemonField name="bucket_name" label="Bucket" className="flex-1">
- <LemonInput placeholder="e.g. my-bucket" />
- </LemonField>
- <LemonField name="region" label="Region" className="flex-1">
- <LemonSelect
- options={[
- { value: 'us-east-1', label: 'US East (N. Virginia)' },
- { value: 'us-east-2', label: 'US East (Ohio)' },
- { value: 'us-west-1', label: 'US West (N. California)' },
- { value: 'us-west-2', label: 'US West (Oregon)' },
- { value: 'af-south-1', label: 'Africa (Cape Town)' },
- { value: 'ap-east-1', label: 'Asia Pacific (Hong Kong)' },
- { value: 'ap-south-1', label: 'Asia Pacific (Mumbai)' },
- {
- value: 'ap-northeast-3',
- label: 'Asia Pacific (Osaka-Local)',
- },
- { value: 'ap-northeast-2', label: 'Asia Pacific (Seoul)' },
- { value: 'ap-southeast-1', label: 'Asia Pacific (Singapore)' },
- { value: 'ap-southeast-2', label: 'Asia Pacific (Sydney)' },
- { value: 'ap-northeast-1', label: 'Asia Pacific (Tokyo)' },
- { value: 'ca-central-1', label: 'Canada (Central)' },
- { value: 'cn-north-1', label: 'China (Beijing)' },
- { value: 'cn-northwest-1', label: 'China (Ningxia)' },
- { value: 'eu-central-1', label: 'Europe (Frankfurt)' },
- { value: 'eu-west-1', label: 'Europe (Ireland)' },
- { value: 'eu-west-2', label: 'Europe (London)' },
- { value: 'eu-south-1', label: 'Europe (Milan)' },
- { value: 'eu-west-3', label: 'Europe (Paris)' },
- { value: 'eu-north-1', label: 'Europe (Stockholm)' },
- { value: 'me-east-1', label: 'Middle East (Dubai)' },
- { value: 'me-south-1', label: 'Middle East (Bahrain)' },
- { value: 'me-central-1', label: 'Middle East (Riyadh)' },
- { value: 'sa-east-1', label: 'South America (São Paulo)' },
- // GCP
- { value: 'us-central1', label: 'GCP — US Central (Iowa)' },
- { value: 'europe-west4', label: 'GCP — Europe (Netherlands)' },
- // Cloudflare R2
- { value: 'auto', label: 'Automatic (AUTO)' },
- { value: 'apac', label: 'Asia Pacific (APAC)' },
- { value: 'eeur', label: 'Eastern Europe (EEUR)' },
- { value: 'enam', label: 'Eastern North America (ENAM)' },
- { value: 'weur', label: 'Western Europe (WEUR)' },
- { value: 'wnam', label: 'Western North America (WNAM)' },
- // OVH Cloud
- { value: 'gra', label: 'Gravelines (GRA)' },
- { value: 'rbx', label: 'Roubaix (RBX)' },
- { value: 'sbg', label: 'Strasbourg (SBG)' },
- { value: 'eu-west-par', label: 'Paris (PAR)' },
- { value: 'eu-south-mil', label: 'Milan (MIL)' },
- { value: 'de', label: 'Frankfurt (DE)' },
- { value: 'uk', label: 'London (UK)' },
- { value: 'waw', label: 'Warsaw (WAW)' },
- { value: 'bhs', label: 'Beauharnois (BHS)' },
- { value: 'ca-east-tor', label: 'Toronto (TOR)' },
- { value: 'sgp', label: 'Singapore (SGP)' },
- { value: 'ap-southeast-syd', label: 'Sydney (SYD)' },
- { value: 'ap-south-mum', label: 'Mumbai (MUM)' },
- ]}
- />
- </LemonField>
- </div>
- <LemonField
- name="prefix"
- label="Key prefix"
- info={
- <>
- Template variables are supported. Please check out the{' '}
- <Link
- to="https://posthog.com/docs/cdp/batch-exports/s3#s3-key-prefix-template-variables"
- target="_blank"
- >
- docs
- </Link>{' '}
- for more information.
- </>
- }
- >
- <LemonInput placeholder="e.g. posthog-events/" />
- </LemonField>
-
- <div className="flex gap-4">
- <LemonField
- name="file_format"
- label="Format"
- className="flex-1"
- info="We recommend Parquet with zstd compression for the best performance"
- >
- <LemonSelect
- options={[
- { value: 'Parquet', label: 'Apache Parquet' },
- { value: 'JSONLines', label: 'JSON lines' },
- ]}
- />
- </LemonField>
-
- <LemonField
- name="max_file_size_mb"
- label="Max file size (MiB)"
- showOptional
- className="flex-1"
- info={
- <>
- Files over this max file size will be split into multiple files. Leave empty or set
- to 0 for no splitting regardless of file size
- </>
- }
- >
- <LemonInput type="number" min={0} />
- </LemonField>
- </div>
-
- <div className="flex gap-4">
- <LemonField name="compression" label="Compression" className="flex-1">
- {({ value, onChange }) => {
- const parquetCompressionOptions = [
- { value: 'zstd', label: 'zstd' },
- { value: 'lz4', label: 'lz4' },
- { value: 'snappy', label: 'snappy' },
- { value: 'gzip', label: 'gzip' },
- { value: 'brotli', label: 'brotli' },
- { value: null, label: 'No compression' },
- ]
- const jsonLinesCompressionOptions = [
- { value: 'gzip', label: 'gzip' },
- { value: 'brotli', label: 'brotli' },
- { value: null, label: 'No compression' },
- ]
- const compressionOptions =
- batchExportConfigForm.file_format === 'Parquet'
- ? parquetCompressionOptions
- : batchExportConfigForm.file_format === 'JSONLines'
- ? jsonLinesCompressionOptions
- : []
-
- const isSelectedCompressionOptionValid = (value: string | null): boolean => {
- if (batchExportConfigForm.file_format === 'Parquet') {
- return parquetCompressionOptions.some((option) => option.value === value)
- } else if (batchExportConfigForm.file_format === 'JSONLines') {
- return jsonLinesCompressionOptions.some((option) => option.value === value)
- }
- return false
- }
-
- // Set defaults when file format changes for new destinations
- React.useEffect(() => {
- // Only run when configuration changes
- if (!configurationChanged) {
- return
- }
- if (isNew && batchExportConfigForm.file_format === 'JSONLines') {
- onChange(null)
- } else if (isNew && batchExportConfigForm.file_format === 'Parquet') {
- onChange('zstd')
- } else if (!isSelectedCompressionOptionValid(value)) {
- // if file format is changed but existing compression is not valid, set to null
- onChange(null)
- }
- }, [configurationChanged, batchExportConfigForm.file_format, isNew]) // oxlint-disable-line react-hooks/exhaustive-deps
-
- return (
- <LemonSelect
- options={compressionOptions}
- value={value}
- onChange={onChange}
- placeholder={
- !batchExportConfigForm.file_format ? 'Select file format first' : undefined
- }
- />
- )
- }}
- </LemonField>
-
- <LemonField name="encryption" label="Encryption" className="flex-1">
- <LemonSelect
- options={[
- { value: 'AES256', label: 'AES256' },
- { value: 'aws:kms', label: 'aws:kms' },
- { value: null, label: 'No encryption' },
- ]}
- />
- </LemonField>
- </div>
-
- <div className="flex gap-4">
- <LemonField name="aws_access_key_id" label="AWS Access Key ID" className="flex-1">
- <LemonInput
- placeholder={isNew ? 'e.g. AKIAIOSFODNN7EXAMPLE' : 'Leave unchanged'}
- autoComplete="off"
- />
- </LemonField>
-
- <LemonField name="aws_secret_access_key" label="AWS Secret Access Key" className="flex-1">
- <LemonInput
- placeholder={isNew ? 'e.g. secret-key' : 'Leave unchanged'}
- type="password"
- autoComplete="new-password"
- />
- </LemonField>
-
- {batchExportConfigForm.encryption == 'aws:kms' && (
- <LemonField name="kms_key_id" label="AWS KMS Key ID" className="flex-1">
- <LemonInput
- placeholder={
- isNew ? 'e.g. 1234abcd-12ab-34cd-56ef-1234567890ab' : 'leave unchanged'
- }
- />
- </LemonField>
- )}
- </div>
-
- <LemonField
- name="endpoint_url"
- label="Endpoint URL"
- showOptional
- info={<>Only required if exporting to an S3-compatible blob storage (like MinIO)</>}
- >
- <LemonInput placeholder={isNew ? 'e.g. https://your-minio-host:9000' : 'Leave unchanged'} />
- </LemonField>
-
- <LemonField
- name="use_virtual_style_addressing"
- label="Virtual style addressing"
- showOptional
- info={
- <>
- Some non-AWS S3-compatible destinations may require this setting enabled. Check your
- destination's documentation if "virtual hosted style" is required, otherwise leave
- unchecked
- </>
- }
- >
- <LemonCheckbox
- bordered
- label={<span className="flex gap-2 items-center">Use virtual style addressing</span>}
- />
- </LemonField>
- </>
- ) : batchExportConfigForm.destination === 'Snowflake' ? (
- <>
- <LemonField name="account" label="Account">
- <LemonInput placeholder="my-account" />
- </LemonField>
-
- <LemonField name="user" label="User">
- <LemonInput placeholder={isNew ? 'my-user' : 'Leave unchanged'} />
- </LemonField>
-
- <LemonField name="authentication_type" label="Authentication type" className="flex-1">
- <LemonSelect
- options={[
- { value: 'password', label: 'Password' },
- { value: 'keypair', label: 'Key pair' },
- ]}
- />
- </LemonField>
-
- {batchExportConfigForm.authentication_type != 'keypair' && (
- <LemonField name="password" label="Password">
- <LemonInput placeholder={isNew ? 'my-password' : 'Leave unchanged'} type="password" />
- </LemonField>
- )}
-
- {batchExportConfigForm.authentication_type == 'keypair' && (
- <>
- <LemonField name="private_key" label="Private key">
- <LemonTextArea
- className="ph-ignore-input"
- placeholder={isNew ? 'my-private-key' : 'Leave unchanged'}
- minRows={4}
- />
- </LemonField>
-
- <LemonField name="private_key_passphrase" label="Private key passphrase">
- <LemonInput placeholder={isNew ? 'my-passphrase' : 'Leave unchanged'} />
- </LemonField>
- </>
- )}
-
- <LemonField name="database" label="Database">
- <LemonInput placeholder="my-database" />
- </LemonField>
-
- <LemonField name="warehouse" label="Warehouse">
- <LemonInput placeholder="my-warehouse" />
- </LemonField>
-
- <LemonField name="schema" label="Schema">
- <LemonInput placeholder="my-schema" />
- </LemonField>
-
- <LemonField name="table_name" label="Table name">
- <LemonInput placeholder="events" />
- </LemonField>
-
- <LemonField name="role" label="Role" showOptional>
- <LemonInput placeholder="my-role" />
- </LemonField>
- </>
- ) : batchExportConfigForm.destination === 'Postgres' ? (
- <>
- <LemonField name="user" label="User">
- <LemonInput placeholder={isNew ? 'my-user' : 'Leave unchanged'} />
- </LemonField>
-
- <LemonField name="password" label="Password">
- <LemonInput placeholder={isNew ? 'my-password' : 'Leave unchanged'} type="password" />
- </LemonField>
-
- <LemonField name="host" label="Host">
- <LemonInput placeholder="my-host" />
- </LemonField>
-
- <LemonField name="port" label="Port">
- <LemonInput placeholder="5432" type="number" min="0" max="65535" />
- </LemonField>
-
- <LemonField name="database" label="Database">
- <LemonInput placeholder="my-database" />
- </LemonField>
-
- <LemonField name="schema" label="Schema">
- <LemonInput placeholder="public" />
- </LemonField>
-
- <LemonField name="table_name" label="Table name">
- <LemonInput placeholder="events" />
- </LemonField>
-
- <LemonField name="has_self_signed_cert">
- {({ value, onChange }) => (
- <LemonCheckbox
- bordered
- label={
- <span className="flex gap-2 items-center">
- Does your Postgres instance have a self-signed SSL certificate?
- <Tooltip title="In most cases, Heroku and RDS users should check this.">
- <IconInfo className="text-lg text-secondary" />
- </Tooltip>
- </span>
- }
- checked={!!value}
- onChange={onChange}
- />
- )}
- </LemonField>
- </>
- ) : batchExportConfigForm.destination === 'Redshift' ? (
- <>
- <LemonField name="user" label="User">
- <LemonInput placeholder={isNew ? 'my-user' : 'Leave unchanged'} />
- </LemonField>
-
- <LemonField name="password" label="Password">
- <LemonInput placeholder={isNew ? 'my-password' : 'Leave unchanged'} type="password" />
- </LemonField>
-
- <LemonField name="host" label="Host">
- <LemonInput placeholder="my-host" />
- </LemonField>
-
- <LemonField name="port" label="Port">
- <LemonInput placeholder="5439" type="number" min="0" max="65535" />
- </LemonField>
-
- <LemonField name="database" label="Database">
- <LemonInput placeholder="my-database" />
- </LemonField>
-
- <LemonField name="schema" label="Schema">
- <LemonInput placeholder="public" />
- </LemonField>
-
- <LemonField name="table_name" label="Table name">
- <LemonInput placeholder="events" />
- </LemonField>
-
- <LemonField
- name="properties_data_type"
- label="Semi-structured data type"
- info={
- <>
- Different PostHog models have semi-structured data fields in them, like
- "events.properties". We can export these fields to Redshift as a "SUPER" type column, or
- a "VARCHAR" column. We recommend "SUPER" over "VARCHAR" as "VARCHAR" has a strict length
- limit that applies on the entire document, whereas with "SUPER" the limit applies on
- each value in the document.
- </>
- }
- >
- <LemonSelect
- options={[
- { value: 'varchar', label: 'VARCHAR(65535)' },
- { value: 'super', label: 'SUPER' },
- ]}
- />
- </LemonField>
-
- <LemonField
- name="mode"
- label="Command"
- className="flex-1"
- info={
- <>
- Choose the SQL command used by the batch export. "COPY" has the best performance but
- requires an S3 bucket we can connect to. "INSERT" performs worse but without any
- additional requirements.
- </>
- }
- >
- <LemonSelect
- options={[
- { value: 'COPY', label: 'COPY' },
- { value: 'INSERT', label: 'INSERT' },
- ]}
- />
- </LemonField>
-
- {batchExportConfigForm.mode === 'COPY' && (
- <>
- <p className="text-xs text-muted mt-1">
- In order to execute a COPY SQL command, the batch export will first export files to an
- S3 bucket, which requires credentials to access it. After the files are available in the
- bucket, we will instruct Redshift to copy them into the configured table. As part of
- this, the batch export needs to specify to Redshift how to access your bucket. For this
- reason, additionally to the first set of credentials used by the batch export, either an
- IAM role (recommended), or the same or a different set of credentials is required.
- </p>
-
- <div className="flex gap-4">
- <LemonField name="redshift_s3_bucket" label="S3 bucket name" className="flex-1">
- <LemonInput placeholder="e.g. my-bucket" />
- </LemonField>
- <LemonField
- name="redshift_s3_bucket_region_name"
- label="S3 bucket region"
- className="flex-1"
- >
- <LemonSelect
- options={[
- { value: 'us-east-1', label: 'US East (N. Virginia)' },
- { value: 'us-east-2', label: 'US East (Ohio)' },
- { value: 'us-west-1', label: 'US West (N. California)' },
- { value: 'us-west-2', label: 'US West (Oregon)' },
- { value: 'af-south-1', label: 'Africa (Cape Town)' },
- { value: 'ap-east-1', label: 'Asia Pacific (Hong Kong)' },
- { value: 'ap-south-1', label: 'Asia Pacific (Mumbai)' },
- {
- value: 'ap-northeast-3',
- label: 'Asia Pacific (Osaka-Local)',
- },
- { value: 'ap-northeast-2', label: 'Asia Pacific (Seoul)' },
- { value: 'ap-southeast-1', label: 'Asia Pacific (Singapore)' },
- { value: 'ap-southeast-2', label: 'Asia Pacific (Sydney)' },
- { value: 'ap-northeast-1', label: 'Asia Pacific (Tokyo)' },
- { value: 'ca-central-1', label: 'Canada (Central)' },
- { value: 'cn-north-1', label: 'China (Beijing)' },
- { value: 'cn-northwest-1', label: 'China (Ningxia)' },
- { value: 'eu-central-1', label: 'Europe (Frankfurt)' },
- { value: 'eu-west-1', label: 'Europe (Ireland)' },
- { value: 'eu-west-2', label: 'Europe (London)' },
- { value: 'eu-south-1', label: 'Europe (Milan)' },
- { value: 'eu-west-3', label: 'Europe (Paris)' },
- { value: 'eu-north-1', label: 'Europe (Stockholm)' },
- { value: 'me-south-1', label: 'Middle East (Bahrain)' },
- { value: 'me-central-1', label: 'Middle East (Riyadh)' },
- { value: 'sa-east-1', label: 'South America (São Paulo)' },
- ]}
- />
- </LemonField>
- </div>
-
- <LemonField name="redshift_s3_key_prefix" label="S3 key prefix" className="flex-1">
- <LemonInput placeholder="e.g. /posthog-copy-files" />
- </LemonField>
-
- <div className="flex gap-4">
- <LemonField
- name="redshift_s3_bucket_aws_access_key_id"
- label="AWS Access Key ID"
- className="flex-1"
- >
- <LemonInput
- placeholder={isNew ? 'e.g. AKIAIOSFODNN7EXAMPLE' : 'Leave unchanged'}
- autoComplete="off"
- />
- </LemonField>
-
- <LemonField
- name="redshift_s3_bucket_aws_secret_access_key"
- label="AWS Secret Access Key"
- className="flex-1"
- >
- <LemonInput
- placeholder={isNew ? 'e.g. secret-key' : 'Leave unchanged'}
- type="password"
- autoComplete="new-password"
- />
- </LemonField>
- </div>
-
- <LemonField
- name="authorization_mode"
- label="Authorization"
- className="flex-1"
- info={
- <>
- Redshift needs to authenticate to COPY data from your S3 bucket. Choose whether
- to assume an IAM role or to provide it with credentials to access the S3 bucket.
- </>
- }
- >
- <LemonSelect
- options={[
- { value: 'IAMRole', label: 'IAM Role' },
- { value: 'Credentials', label: 'Credentials' },
- ]}
- />
- </LemonField>
-
- {batchExportConfigForm.authorization_mode === 'IAMRole' && (
- <>
- <LemonField name="redshift_iam_role" label="IAM Role ARN" className="flex-1">
- <LemonInput placeholder="e.g. arn:aws:iam::<aws-account-id>:role/<role-name>" />
- </LemonField>
- </>
- )}
-
- {batchExportConfigForm.authorization_mode === 'Credentials' && (
- <div className="flex gap-4">
- <LemonField
- name="redshift_aws_access_key_id"
- label="AWS Access Key ID"
- className="flex-1"
- >
- <LemonInput
- placeholder={isNew ? 'e.g. AKIAIOSFODNN7EXAMPLE' : 'Leave unchanged'}
- autoComplete="off"
- />
- </LemonField>
-
- <LemonField
- name="redshift_aws_secret_access_key"
- label="AWS Secret Access Key"
- className="flex-1"
- >
- <LemonInput
- placeholder={isNew ? 'e.g. secret-key' : 'Leave unchanged'}
- type="password"
- autoComplete="new-password"
- />
- </LemonField>
- </div>
- )}
- </>
- )}
- </>
- ) : batchExportConfigForm.destination === 'BigQuery' ? (
- <>
- <LemonField name="integration_id" label="Integration">
- {({ value, onChange }) => (
- <IntegrationChoice
- integration="google-cloud-service-account"
- value={value}
- onChange={onChange}
- />
- )}
- </LemonField>
-
- <LemonField name="table_id" label="Table ID">
- <LemonInput placeholder="events" />
- </LemonField>
-
- <LemonField name="dataset_id" label="Dataset ID">
- <LemonInput placeholder="dataset" />
- </LemonField>
-
- {isNew ? (
- <LemonField name="use_json_type" label="Structured fields data type">
- <LemonCheckbox
- bordered
- label={
- <span className="flex gap-2 items-center">
- Export 'properties', 'set', and 'set_once' fields as BigQuery JSON type
- <Tooltip title="If left unchecked, these fields will be sent as STRING type. This setting cannot be changed after batch export is created.">
- <IconInfo className="text-lg text-secondary" />
- </Tooltip>
- </span>
- }
- />
- </LemonField>
- ) : null}
- </>
- ) : batchExportConfigForm.destination === 'Databricks' ? (
- <>
- <LemonField name="integration_id" label="Integration">
- {({ value, onChange }) => (
- <IntegrationChoice integration="databricks" value={value} onChange={onChange} />
- )}
- </LemonField>
-
- <LemonField
- name="http_path"
- label="HTTP Path"
- info={<>HTTP Path value for your all-purpose compute or SQL warehouse.</>}
- >
- <LemonInput placeholder="/sql/1.0/warehouses/my-warehouse" />
- </LemonField>
-
- <LemonField name="catalog" label="Catalog">
- <LemonInput placeholder="workspace" />
- </LemonField>
-
- <LemonField name="schema" label="Schema">
- <LemonInput placeholder="default" />
- </LemonField>
-
- <LemonField name="table_name" label="Table name">
- <LemonInput placeholder="my-table" />
- </LemonField>
-
- {isNew ? (
- <LemonField name="use_variant_type">
- {({ value, onChange }) => (
- <LemonCheckbox
- checked={!!value}
- onChange={onChange}
- bordered
- label={
- <span className="flex gap-2 items-center">
- Use VARIANT type for storing JSON data
- <Tooltip
- interactive
- title={
- <>
- Using VARIANT for storing JSON data is{' '}
- <Link
- to="https://docs.databricks.com/aws/en/semi-structured/variant"
- target="_blank"
- >
- recommended by Databricks
- </Link>{' '}
- , however, the VARIANT data type is only available in Databricks
- Runtime 15.3 and above. If left unchecked, JSON data will be
- stored using the STRING type.
- <br />
- <strong>
- This setting cannot be changed after the batch export is
- created.
- </strong>
- </>
- }
- >
- <IconInfo className="text-lg text-secondary" />
- </Tooltip>
- </span>
- }
- />
- )}
- </LemonField>
- ) : null}
- </>
- ) : batchExportConfigForm.destination === 'AzureBlob' ? (
- <>
- <LemonField name="integration_id" label="Azure connection">
- {({ value, onChange }) => (
- <IntegrationChoice integration="azure-blob" value={value} onChange={onChange} />
- )}
- </LemonField>
-
- <LemonField
- name="container_name"
- label="Container name"
- info={
- <>
- The name of the Azure Blob Storage container where data will be exported. The container
- must already exist.
- </>
- }
- >
- <LemonInput placeholder="my-export-container" />
- </LemonField>
-
- <LemonField
- name="prefix"
- label="Blob prefix"
- showOptional
- info={
- <>
- Optional prefix for blob names. Supports template variables: {'{year}'}, {'{month}'},{' '}
- {'{day}'}, {'{hour}'}, {'{minute}'}, {'{data_interval_start}'}, {'{data_interval_end}'}.
- </>
- }
- >
- <LemonInput placeholder="posthog/events/" />
- </LemonField>
-
- <div className="flex gap-4">
- <LemonField
- name="file_format"
- label="Format"
- className="flex-1"
- info="We recommend Parquet with zstd compression for the best performance"
- >
- <LemonSelect
- options={[
- { value: 'Parquet', label: 'Apache Parquet' },
- { value: 'JSONLines', label: 'JSON lines' },
- ]}
- />
- </LemonField>
-
- <LemonField
- name="max_file_size_mb"
- label="Max file size (MiB)"
- showOptional
- className="flex-1"
- info={
- <>
- Files over this max file size will be split into multiple files. Leave empty or set
- to 0 for no splitting regardless of file size.
- </>
- }
- >
- <LemonInput type="number" min={0} />
- </LemonField>
- </div>
-
- <LemonField name="compression" label="Compression">
- {({ value, onChange }) => {
- const parquetCompressionOptions = [
- { value: 'zstd', label: 'zstd' },
- { value: 'lz4', label: 'lz4' },
- { value: 'snappy', label: 'snappy' },
- { value: 'gzip', label: 'gzip' },
- { value: 'brotli', label: 'brotli' },
- { value: null, label: 'No compression' },
- ]
- const jsonLinesCompressionOptions = [
- { value: 'gzip', label: 'gzip' },
- { value: 'brotli', label: 'brotli' },
- { value: null, label: 'No compression' },
- ]
- const compressionOptions =
- batchExportConfigForm.file_format === 'Parquet'
- ? parquetCompressionOptions
- : batchExportConfigForm.file_format === 'JSONLines'
- ? jsonLinesCompressionOptions
- : []
-
- const isSelectedCompressionOptionValid = (val: string | null): boolean => {
- if (batchExportConfigForm.file_format === 'Parquet') {
- return parquetCompressionOptions.some((option) => option.value === val)
- } else if (batchExportConfigForm.file_format === 'JSONLines') {
- return jsonLinesCompressionOptions.some((option) => option.value === val)
- }
- return false
- }
-
- React.useEffect(() => {
- if (!configurationChanged) {
- return
- }
- if (isNew && batchExportConfigForm.file_format === 'JSONLines') {
- onChange(null)
- } else if (isNew && batchExportConfigForm.file_format === 'Parquet') {
- onChange('zstd')
- } else if (!isSelectedCompressionOptionValid(value)) {
- onChange(null)
- }
- }, [configurationChanged, batchExportConfigForm.file_format, isNew]) // oxlint-disable-line react-hooks/exhaustive-deps
-
- return (
- <LemonSelect
- options={compressionOptions}
- value={value}
- onChange={onChange}
- placeholder={
- !batchExportConfigForm.file_format ? 'Select file format first' : undefined
- }
- />
- )
- }}
- </LemonField>
- </>
- ) : batchExportConfigForm.destination === 'HTTP' ? (
- <>
- <LemonField name="url" label="PostHog region">
- <LemonSelect
- options={[
- { value: 'https://us.i.posthog.com/batch/', label: 'US' },
- { value: 'https://eu.i.posthog.com/batch/', label: 'EU' },
- ]}
- />
- </LemonField>
- <LemonField name="token" label="Destination project token">
- <LemonInput placeholder="e.g. phc_12345..." />
- </LemonField>
- </>
- ) : null}
+ {definition && (
+ <definition.Fields
+ isNew={isNew}
+ formValues={batchExportConfigForm}
+ configurationChanged={configurationChanged}
+ />
+ )}
</div>
)
}
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 aeadd075318b..24e5f4f6c477 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.test.ts
@@ -501,6 +501,45 @@ describe('batchExportConfigFormLogic', () => {
})
})
+ describe('Redshift COPY → INSERT drops the staging copy_inputs', () => {
+ // Loading a COPY export flattens copy_inputs into redshift_* form fields. Switching the
+ // mode to INSERT must null out copy_inputs (matching a native INSERT export) rather than
+ // leaking the original nested staging object back into the payload.
+ it('nulls copy_inputs in the saved config when switching to INSERT', async () => {
+ await initLogic({ service: null, id: REDSHIFT_COPY_IAM_BATCH_EXPORT.id })
+
+ logic.actions.setConfigurationValues({
+ ...logic.values.configuration,
+ mode: 'INSERT',
+ })
+
+ await expectLogic(logic, () => {
+ logic.actions.submitConfiguration()
+ })
+ .toDispatchActions(['submitConfiguration', 'updateBatchExportConfigSuccess'])
+ .toFinishAllListeners()
+
+ const body = patchBodiesById[REDSHIFT_COPY_IAM_BATCH_EXPORT.id]
+ expect(body.destination).toEqual({
+ type: 'Redshift',
+ config: {
+ user: 'rs-user',
+ password: 'rs-pass',
+ host: 'rs-host',
+ port: 5439,
+ database: 'rs-db',
+ schema: 'public',
+ table_name: 'events',
+ properties_data_type: 'SUPER',
+ mode: 'INSERT',
+ copy_inputs: null,
+ exclude_events: [],
+ include_events: [],
+ },
+ })
+ })
+ })
+
describe('successful update', () => {
it('sends changed field plus untouched fixture defaults', async () => {
await initLogic({ service: null, id: S3_BATCH_EXPORT.id })
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
index 8509085e17d4..7d127c84c196 100644
--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportConfigFormLogic.tsx
@@ -20,59 +20,68 @@ import {
import type { batchExportConfigFormLogicType } from './batchExportConfigFormLogicType'
import { batchExportDataLogic } from './batchExportDataLogic'
+import { DESTINATIONS } from './destinations'
+import { genericPersonEventFields } from './destinations/common'
import { humanizeBatchExportName } from './utils'
-// Bucket naming rules (supports both S3 and GCS):
-// S3: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
-// GCS: https://cloud.google.com/storage/docs/buckets#naming
-const BUCKET_NAME_REGEX = /^[a-z0-9][a-z0-9._-]*[a-z0-9]$|^[a-z0-9]$/
-const IP_ADDRESS_REGEX = /^(\d{1,3}\.){3}\d{1,3}$/
-
-function validateBucketName(bucketName: string): string | undefined {
- if (!bucketName) {
- return undefined // Let required field validation handle empty values
- }
-
- if (/\s/.test(bucketName)) {
- return 'Bucket name cannot contain whitespace'
- }
-
- if (bucketName !== bucketName.toLowerCase()) {
- return 'Bucket name must be lowercase'
- }
-
- if (bucketName.includes('..')) {
- return 'Bucket name cannot contain consecutive periods'
- }
+export interface BatchExportConfigFormLogicProps {
+ service: BatchExportService['type'] | null
+ id: string | null
+}
- if (IP_ADDRESS_REGEX.test(bucketName)) {
- return 'Bucket name cannot be formatted as an IP address'
- }
+// Fields that exist on the form but are not part of destination.config
+const TOP_LEVEL_FORM_FIELDS = new Set([
+ 'name',
+ 'destination',
+ 'interval',
+ 'timezone',
+ 'offset_day',
+ 'offset_hour',
+ 'paused',
+ 'created_at',
+ 'start_at',
+ 'end_at',
+ 'model',
+ 'filters',
+ 'integration_id',
+])
- if (!BUCKET_NAME_REGEX.test(bucketName)) {
- return 'Bucket name can only contain lowercase letters, numbers, hyphens, and periods, and must start and end with a letter or number'
+function buildDestinationPayload(formValues: Record<string, any>): {
+ type: string
+ config: Record<string, any>
+ integration?: any
+} {
+ const destinationType = formValues.destination as BatchExportService['type']
+ const definition = DESTINATIONS[destinationType]
+ // Apply destination-specific transform first (e.g. Redshift's COPY copy_inputs assembly).
+ // Destinations without a custom serialize get the raw form values passed through.
+ const intermediate = definition?.serialize ? definition.serialize(formValues) : formValues
+ // Strip top-level form fields that don't belong in destination.config (always — destinations
+ // shouldn't have to re-implement this).
+ const config: Record<string, any> = {}
+ for (const [key, value] of Object.entries(intermediate)) {
+ if (TOP_LEVEL_FORM_FIELDS.has(key)) {
+ continue
+ }
+ config[key] = value
}
-
- return undefined
-}
-
-function validateAzureContainerName(name: string): string | undefined {
- if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(name) && name.length > 1) {
- return 'Must be lowercase letters, numbers, and hyphens; start and end with letter or number'
+ const result: { type: string; config: Record<string, any>; integration?: any } = {
+ type: destinationType,
+ config,
}
- if (/--/.test(name)) {
- return 'Cannot contain consecutive hyphens'
+ if (definition?.usesIntegration) {
+ result.integration = formValues.integration_id
}
- return undefined
-}
-
-export interface BatchExportConfigFormLogicProps {
- service: BatchExportService['type'] | null
- id: string | null
+ return result
}
function getConfigurationFromBatchExportConfig(batchExportConfig: BatchExportConfiguration): Record<string, any> {
const destinationType = batchExportConfig.destination.type
+ const definition = DESTINATIONS[destinationType]
+
+ const flatConfig = definition?.deserialize
+ ? definition.deserialize(batchExportConfig.destination.config)
+ : { ...batchExportConfig.destination.config }
const config: Record<string, any> = {
name: batchExportConfig.name,
@@ -84,206 +93,82 @@ function getConfigurationFromBatchExportConfig(batchExportConfig: BatchExportCon
offset_hour: (batchExportConfig as any).offset_hour ?? null,
model: batchExportConfig.model,
filters: batchExportConfig.filters,
- ...batchExportConfig.destination.config,
- }
-
- if (destinationType === 'Databricks' || destinationType === 'AzureBlob' || destinationType === 'BigQuery') {
- config.integration_id = batchExportConfig.destination.integration
+ ...flatConfig,
}
- let authorizationMode: 'IAMRole' | 'Credentials' = 'IAMRole'
- let copyInputsFields: Record<string, any> = {}
-
- if (batchExportConfig.destination.type === 'Redshift' && batchExportConfig.destination.config.copy_inputs) {
- const copyInputs = batchExportConfig.destination.config.copy_inputs
-
- copyInputsFields = {
- redshift_s3_bucket: copyInputs.s3_bucket,
- redshift_s3_key_prefix: copyInputs.s3_key_prefix,
- redshift_s3_bucket_region_name: copyInputs.region_name,
- redshift_s3_bucket_aws_access_key_id: copyInputs.bucket_credentials?.aws_access_key_id,
- redshift_s3_bucket_aws_secret_access_key: copyInputs.bucket_credentials?.aws_secret_access_key,
- redshift_iam_role: undefined,
- redshift_aws_access_key_id: undefined,
- redshift_aws_secret_access_key: undefined,
- }
-
- if (typeof copyInputs.authorization === 'string') {
- authorizationMode = 'IAMRole'
- copyInputsFields.redshift_iam_role = copyInputs.authorization
- } else {
- authorizationMode = 'Credentials'
- copyInputsFields.redshift_aws_access_key_id = copyInputs.authorization?.aws_access_key_id
- copyInputsFields.redshift_aws_secret_access_key = copyInputs.authorization?.aws_secret_access_key
- }
+ if (definition?.usesIntegration) {
+ // Only the integration-backed destinations (Databricks, AzureBlob, BigQuery) carry this field.
+ config.integration_id = (batchExportConfig.destination as { integration?: number }).integration
}
- return {
- ...config,
- ...copyInputsFields,
- authorization_mode: authorizationMode,
- }
+ return config
}
export function getDefaultConfiguration(service: string): Record<string, any> {
+ const definition = DESTINATIONS[service as BatchExportService['type']]
return {
name: humanizeBatchExportName(service as BatchExportService['type']),
destination: service,
model: 'events',
paused: true,
- ...(service === 'Snowflake' && {
- authentication_type: 'password',
- }),
- ...(service === 'S3' && {
- file_format: 'Parquet',
- compression: 'zstd',
- }),
- ...(service === 'Redshift' && {
- mode: 'COPY',
- authorization_mode: 'IAMRole',
- properties_data_type: 'SUPER',
- }),
- ...(service === 'Databricks' && {
- use_variant_type: true,
- // prefill prefix for http path
- http_path: '/sql/1.0/warehouses/',
- }),
- ...(service === 'AzureBlob' && {
- file_format: 'Parquet',
- compression: 'zstd',
- }),
+ ...(definition ? definition.defaults() : {}),
}
}
+const BASE_EVENT_FIELDS = {
+ uuid: {
+ name: 'uuid',
+ hogql_value: 'toString(uuid)',
+ type: 'string',
+ schema_valid: true,
+ },
+ timestamp: {
+ name: 'timestamp',
+ hogql_value: 'timestamp',
+ type: 'datetime',
+ schema_valid: true,
+ },
+ event: {
+ name: 'event',
+ hogql_value: 'event',
+ type: 'string',
+ schema_valid: true,
+ },
+ distinct_id: {
+ name: 'distinct_id',
+ hogql_value: 'toString(distinct_id)',
+ type: 'string',
+ schema_valid: true,
+ },
+ properties: {
+ name: 'properties',
+ hogql_value: 'properties',
+ type: 'json',
+ schema_valid: true,
+ },
+} as const
+
function getEventTable(service: BatchExportService['type']): DatabaseSchemaBatchExportTable {
- const eventsTable: DatabaseSchemaBatchExportTable = {
+ const definition = DESTINATIONS[service]
+ const overrides = definition?.eventTableOverrides ?? {}
+ const includeGeneric = overrides.includeGenericPersonFields !== false
+
+ return {
type: 'batch_export',
id: 'Events',
name: 'events',
fields: {
- uuid: {
- name: 'uuid',
- hogql_value: 'toString(uuid)',
- type: 'string',
- schema_valid: true,
- },
- timestamp: {
- name: 'timestamp',
- hogql_value: 'timestamp',
- type: 'datetime',
- schema_valid: true,
- },
- event: {
- name: 'event',
- hogql_value: 'event',
- type: 'string',
- schema_valid: true,
- },
- distinct_id: {
- name: 'distinct_id',
- hogql_value: 'toString(distinct_id)',
- type: 'string',
- schema_valid: true,
- },
- properties: {
- name: 'properties',
- hogql_value: 'properties',
- type: 'json',
- schema_valid: true,
- },
- ...(service == 'S3' && {
- person_id: {
- name: 'person_id',
- hogql_value: 'toString(person_id)',
- type: 'string',
- schema_valid: true,
- },
- person_properties: {
- name: 'person_properties',
- hogql_value: "nullIf(person_properties, '')",
- type: 'string',
- schema_valid: true,
- },
- created_at: {
- name: 'created_at',
- hogql_value: 'created_at',
- type: 'datetime',
- schema_valid: true,
- },
- }),
- ...(service == 'Databricks' && {
- team_id: {
- name: 'team_id',
- hogql_value: 'team_id',
- type: 'integer',
- schema_valid: true,
- },
- databricks_ingested_timestamp: {
- name: 'databricks_ingested_timestamp',
- hogql_value: 'NOW64()',
- type: 'datetime',
- schema_valid: true,
- },
- }),
- ...(service != 'S3' &&
- service != 'Databricks' && {
- team_id: {
- name: 'team_id',
- hogql_value: service == 'Postgres' || service == 'Redshift' ? 'toInt32(team_id)' : 'team_id',
- type: 'integer',
- schema_valid: true,
- },
- set: {
- name: service == 'Snowflake' ? 'people_set' : 'set',
- hogql_value: "nullIf(JSONExtractString(properties, '$set'), '')",
- type: 'string',
- schema_valid: true,
- },
- set_once: {
- name: service == 'Snowflake' ? 'people_set_once' : 'set_once',
- hogql_value: "nullIf(JSONExtractString(properties, '$set_once'), '')",
- type: 'string',
- schema_valid: true,
- },
- site_url: {
- name: 'site_url',
- hogql_value: "''",
- type: 'string',
- schema_valid: true,
- },
- ip: {
- name: 'ip',
- hogql_value: "nullIf(JSONExtractString(properties, '$ip'), '')",
- type: 'string',
- schema_valid: true,
- },
- elements_chain: {
- name: 'elements',
- hogql_value: 'toJSONString(elements_chain)',
- type: 'string',
- schema_valid: true,
- },
- }),
- ...(service == 'BigQuery' && {
- bq_ingested_timestamp: {
- name: 'bq_ingested_timestamp',
- hogql_value: 'NOW64()',
- type: 'datetime',
- schema_valid: true,
- },
- }),
- ...(service == 'Snowflake' && {
- snowflake_ingested_timestamp: {
- name: 'snowflake_ingested_timestamp',
- hogql_value: 'NOW64()',
- type: 'datetime',
- schema_valid: true,
- },
- }),
+ ...BASE_EVENT_FIELDS,
+ ...(includeGeneric
+ ? genericPersonEventFields({
+ teamIdHogql: overrides.teamIdHogql ?? 'team_id',
+ setName: overrides.setName ?? 'set',
+ setOnceName: overrides.setOnceName ?? 'set_once',
+ })
+ : {}),
+ ...definition?.eventTableExtraFields,
},
}
-
- return eventsTable
}
const personsTable: DatabaseSchemaBatchExportTable = {
@@ -635,6 +520,8 @@ const sessionsTable: DatabaseSchemaBatchExportTable = {
// Form logic for creating and editing batch export configurations.
// Owns form state, validation, dirty-checking, test steps, and save/delete actions.
// Reads the underlying config data from batchExportDataLogic.
+// Per-destination behaviour (defaults, required fields, payload assembly, validation, JSX) lives
+// in the registry under ./destinations/. This file is destination-agnostic.
export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([
props({ id: null, service: null } as BatchExportConfigFormLogicProps),
key(({ service, id }: BatchExportConfigFormLogicProps) => {
@@ -705,79 +592,19 @@ export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([
step.result = null
})
}
- const {
- name,
- destination,
- interval,
- timezone,
- offset_day,
- offset_hour,
- paused,
- created_at,
- start_at,
- end_at,
- model,
- filters,
- integration_id,
- // Redshift COPY configuration
- mode,
- authorization_mode,
- redshift_s3_bucket,
- redshift_s3_key_prefix,
- redshift_s3_bucket_region_name,
- redshift_s3_bucket_aws_access_key_id,
- redshift_s3_bucket_aws_secret_access_key,
- redshift_iam_role,
- redshift_aws_access_key_id,
- redshift_aws_secret_access_key,
- ...config
- } = values.configuration
-
- if (destination === 'Redshift') {
- if (mode === 'COPY') {
- const copyInputs: Record<string, any> = {
- s3_bucket: redshift_s3_bucket,
- s3_key_prefix: redshift_s3_key_prefix,
- region_name: redshift_s3_bucket_region_name,
- }
-
- if (redshift_iam_role) {
- copyInputs.authorization = redshift_iam_role
- } else if (redshift_aws_access_key_id && redshift_aws_secret_access_key) {
- copyInputs.authorization = {
- aws_access_key_id: redshift_aws_access_key_id,
- aws_secret_access_key: redshift_aws_secret_access_key,
- }
- }
-
- if (redshift_s3_bucket_aws_access_key_id && redshift_s3_bucket_aws_secret_access_key) {
- copyInputs.bucket_credentials = {
- aws_access_key_id: redshift_s3_bucket_aws_access_key_id,
- aws_secret_access_key: redshift_s3_bucket_aws_secret_access_key,
- }
- }
-
- config.copy_inputs = copyInputs
- }
- config.mode = mode
- }
- const destinationObj = {
- type: destination,
- config: config,
- integration: integration_id,
- }
+ const formValues = values.configuration
+ const interval = formValues.interval
const data = {
- paused,
- name,
+ paused: formValues.paused,
+ name: formValues.name,
interval,
- // timezone and offset are only used for day and week intervals
- timezone: interval === 'day' || interval === 'week' ? timezone : null,
- offset_day: interval === 'week' ? offset_day : null,
- offset_hour: interval === 'day' || interval === 'week' ? offset_hour : null,
- model,
- filters,
- destination: destinationObj,
+ timezone: interval === 'day' || interval === 'week' ? formValues.timezone : null,
+ offset_day: interval === 'week' ? formValues.offset_day : null,
+ offset_hour: interval === 'day' || interval === 'week' ? formValues.offset_hour : null,
+ model: formValues.model,
+ filters: formValues.filters,
+ destination: buildDestinationPayload(formValues),
} as any
if (props.id) {
@@ -892,144 +719,32 @@ export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([
(s) => [s.service, s.isNew, s.configuration],
(service, isNew, config): string[] => {
const generalRequiredFields = ['interval', 'name', 'model']
- if (service === 'Postgres') {
- return [
- ...generalRequiredFields,
- ...(isNew ? ['user'] : []),
- ...(isNew ? ['password'] : []),
- 'host',
- 'port',
- 'database',
- 'schema',
- 'table_name',
- ]
- } else if (service === 'Redshift') {
- return [
- ...generalRequiredFields,
- ...(isNew ? ['user'] : []),
- ...(isNew ? ['password'] : []),
- 'host',
- 'port',
- 'database',
- 'schema',
- 'table_name',
- ]
- } else if (service === 'S3') {
- return [
- ...generalRequiredFields,
- 'bucket_name',
- 'region',
- 'prefix',
- ...(isNew ? ['aws_access_key_id'] : []),
- ...(isNew ? ['aws_secret_access_key'] : []),
- ...(isNew ? ['file_format'] : []),
- ]
- } else if (service === 'BigQuery') {
- return [...generalRequiredFields, ...(isNew ? ['integration_id'] : []), 'dataset_id', 'table_id']
- } else if (service === 'HTTP') {
- return [...generalRequiredFields, 'url', 'token']
- } else if (service === 'Snowflake') {
- return [
- ...generalRequiredFields,
- 'account',
- 'database',
- 'warehouse',
- ...(isNew ? ['user'] : []),
- ...(isNew && config.authentication_type == 'password' ? ['password'] : []),
- ...(isNew && config.authentication_type == 'keypair' ? ['private_key'] : []),
- 'schema',
- 'table_name',
- ]
- } else if (service === 'Databricks') {
- return [...generalRequiredFields, 'integration_id', 'http_path', 'catalog', 'schema', 'table_name']
- } else if (service === 'AzureBlob') {
- return [
- ...generalRequiredFields,
- 'integration_id',
- 'container_name',
- ...(isNew ? ['file_format'] : []),
- ]
+ if (!service) {
+ return generalRequiredFields
+ }
+ const definition = DESTINATIONS[service as BatchExportService['type']]
+ if (!definition) {
+ return generalRequiredFields
}
- return generalRequiredFields
+ return [...generalRequiredFields, ...definition.requiredFields({ isNew, formValues: config })]
},
],
})),
listeners(({ props, values, actions }) => ({
updateBatchExportConfig: async ({ formdata }) => {
- const {
- name,
- destination,
- interval,
- timezone,
- offset_day,
- offset_hour,
- paused,
- created_at,
- start_at,
- end_at,
- model,
- filters,
- integration_id,
- // Redshift COPY configuration
- mode,
- authorization_mode,
- redshift_s3_bucket,
- redshift_s3_key_prefix,
- redshift_s3_bucket_region_name,
- redshift_s3_bucket_aws_access_key_id,
- redshift_s3_bucket_aws_secret_access_key,
- redshift_iam_role,
- redshift_aws_access_key_id,
- redshift_aws_secret_access_key,
- ...config
- } = formdata
-
- if (destination === 'Redshift') {
- if (mode === 'COPY') {
- const copyInputs: Record<string, any> = {
- s3_bucket: redshift_s3_bucket,
- s3_key_prefix: redshift_s3_key_prefix,
- region_name: redshift_s3_bucket_region_name,
- }
-
- if (redshift_iam_role) {
- copyInputs.authorization = redshift_iam_role
- } else if (redshift_aws_access_key_id && redshift_aws_secret_access_key) {
- copyInputs.authorization = {
- aws_access_key_id: redshift_aws_access_key_id,
- aws_secret_access_key: redshift_aws_secret_access_key,
- }
- }
-
- if (redshift_s3_bucket_aws_access_key_id && redshift_s3_bucket_aws_secret_access_key) {
- copyInputs.bucket_credentials = {
- aws_access_key_id: redshift_s3_bucket_aws_access_key_id,
- aws_secret_access_key: redshift_s3_bucket_aws_secret_access_key,
- }
- }
-
- config.copy_inputs = copyInputs
- }
- config.mode = mode
- }
-
- const destinationObj = {
- type: destination,
- integration: integration_id,
- config: config,
- }
+ const interval = formdata.interval
const data: Omit<BatchExportConfiguration, 'id' | 'team_id' | 'created_at' | 'start_at' | 'end_at'> = {
- paused,
- name,
+ paused: formdata.paused,
+ name: formdata.name,
interval,
- // timezone and offset are only used for day and week intervals
- timezone: interval === 'day' || interval === 'week' ? timezone : null,
- offset_day: interval === 'week' ? offset_day : null,
- offset_hour: interval === 'day' || interval === 'week' ? offset_hour : null,
- model,
- filters,
- destination: destinationObj,
+ timezone: interval === 'day' || interval === 'week' ? formdata.timezone : null,
+ offset_day: interval === 'week' ? formdata.offset_day : null,
+ offset_hour: interval === 'day' || interval === 'week' ? formdata.offset_hour : null,
+ model: formdata.model,
+ filters: formdata.filters,
+ destination: buildDestinationPayload(formdata) as any,
} as any
+
if (props.id) {
const res = await api.batchExports.update(props.id, data)
lemonToast.success('Batch export configuration updated successfully')
@@ -1117,6 +832,7 @@ export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([
},
setConfigurationValue: ({ name, value }) => {
const fieldName = Array.isArray(name) ? name[0] : name
+
if (fieldName === 'interval') {
// if changing to day or week, set the timezone to the team's timezone if not already set
if (value === 'day' || value === 'week') {
@@ -1166,27 +882,19 @@ export const batchExportConfigFormLogic = kea<batchExportConfigFormLogicType>([
])
)
- // Bucket name validation (S3/GCS compatible)
- const bucketNameError =
- values.service === 'S3'
- ? validateBucketName(formdata.bucket_name)
- : values.service === 'Redshift' && formdata.mode === 'COPY'
- ? validateBucketName(formdata.redshift_s3_bucket)
- : undefined
+ const destination = formdata.destination as BatchExportService['type'] | undefined
+ const definition = destination ? DESTINATIONS[destination] : undefined
+ const fieldValidations = definition?.validate?.(formdata) ?? {}
- const containerNameError =
- values.service === 'AzureBlob' && formdata.container_name
- ? validateAzureContainerName(formdata.container_name as string)
- : undefined
-
- return {
- ...requiredFieldErrors,
- ...(values.service === 'S3' && bucketNameError ? { bucket_name: bucketNameError } : {}),
- ...(values.service === 'Redshift' && formdata.mode === 'COPY' && bucketNameError
- ? { redshift_s3_bucket: bucketNameError }
- : {}),
- ...(containerNameError && { container_name: containerNameError }),
+ // Only apply a field validation when it produced a message — a valid (undefined)
+ // result must not clobber a "required" error from the same empty field.
+ const errors: Record<string, string | undefined> = { ...requiredFieldErrors }
+ for (const [field, message] of Object.entries(fieldValidations)) {
+ if (message) {
+ errors[field] = message
+ }
}
+ return errors
},
submit: async (formdata) => {
// Check if schedule fields have changed and show confirmation modal
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsx
new file mode 100644
index 000000000000..513727eca980
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/azureblob.tsx
@@ -0,0 +1,70 @@
+import { LemonInput } from '@posthog/lemon-ui'
+
+import { IntegrationChoice } from 'lib/components/CyclotronJob/integrations/IntegrationChoice'
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import { CompressionField, FileFormatField, MaxFileSizeField, validateAzureContainerName } from './common'
+import type { DestinationDefinition } from './types'
+
+export const azureBlobDefinition: DestinationDefinition = {
+ type: 'AzureBlob',
+ usesIntegration: true,
+ defaults: () => ({
+ file_format: 'Parquet',
+ compression: 'zstd',
+ }),
+ requiredFields: ({ isNew }) => ['integration_id', 'container_name', ...(isNew ? ['file_format'] : [])],
+ validate: (formValues) => ({
+ container_name: validateAzureContainerName(formValues.container_name),
+ }),
+ eventTableOverrides: { teamIdHogql: 'team_id' },
+ Fields: function AzureBlobFields({ isNew, formValues, configurationChanged }) {
+ return (
+ <>
+ <LemonField name="integration_id" label="Azure connection">
+ {({ value, onChange }) => (
+ <IntegrationChoice integration="azure-blob" value={value} onChange={onChange} />
+ )}
+ </LemonField>
+
+ <LemonField
+ name="container_name"
+ label="Container name"
+ info={
+ <>
+ The name of the Azure Blob Storage container where data will be exported. The container must
+ already exist.
+ </>
+ }
+ >
+ <LemonInput placeholder="my-export-container" />
+ </LemonField>
+
+ <LemonField
+ name="prefix"
+ label="Blob prefix"
+ showOptional
+ info={
+ <>
+ Optional prefix for blob names. Supports template variables: {'{year}'}, {'{month}'},{' '}
+ {'{day}'}, {'{hour}'}, {'{minute}'}, {'{data_interval_start}'}, {'{data_interval_end}'}.
+ </>
+ }
+ >
+ <LemonInput placeholder="posthog/events/" />
+ </LemonField>
+
+ <div className="flex gap-4">
+ <FileFormatField />
+ <MaxFileSizeField />
+ </div>
+
+ <CompressionField
+ fileFormat={formValues.file_format}
+ isNew={isNew}
+ configurationChanged={configurationChanged}
+ />
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/bigquery.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/bigquery.tsx
new file mode 100644
index 000000000000..95ec63264d08
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/bigquery.tsx
@@ -0,0 +1,62 @@
+import { IconInfo } from '@posthog/icons'
+import { LemonCheckbox, LemonInput, Tooltip } from '@posthog/lemon-ui'
+
+import { IntegrationChoice } from 'lib/components/CyclotronJob/integrations/IntegrationChoice'
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import type { DestinationDefinition } from './types'
+
+export const bigqueryDefinition: DestinationDefinition = {
+ type: 'BigQuery',
+ usesIntegration: true,
+ defaults: () => ({}),
+ requiredFields: ({ isNew }) => [...(isNew ? ['integration_id'] : []), 'dataset_id', 'table_id'],
+ eventTableOverrides: { teamIdHogql: 'team_id' },
+ eventTableExtraFields: {
+ bq_ingested_timestamp: {
+ name: 'bq_ingested_timestamp',
+ hogql_value: 'NOW64()',
+ type: 'datetime',
+ schema_valid: true,
+ },
+ },
+ Fields: function BigQueryFields({ isNew }) {
+ return (
+ <>
+ <LemonField name="integration_id" label="Integration">
+ {({ value, onChange }) => (
+ <IntegrationChoice
+ integration="google-cloud-service-account"
+ value={value}
+ onChange={onChange}
+ />
+ )}
+ </LemonField>
+
+ <LemonField name="table_id" label="Table ID">
+ <LemonInput placeholder="events" />
+ </LemonField>
+
+ <LemonField name="dataset_id" label="Dataset ID">
+ <LemonInput placeholder="dataset" />
+ </LemonField>
+
+ {isNew ? (
+ <LemonField name="use_json_type" label="Structured fields data type">
+ <LemonCheckbox
+ bordered
+ label={
+ <span className="flex gap-2 items-center">
+ Export 'properties', 'set', and 'set_once' fields as BigQuery JSON type
+ <Tooltip title="If left unchecked, these fields will be sent as STRING type. This setting cannot be changed after batch export is created.">
+ <IconInfo className="text-lg text-secondary" />
+ </Tooltip>
+ </span>
+ }
+ />
+ </LemonField>
+ ) : null}
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsx
new file mode 100644
index 000000000000..d942c004afb8
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/common.tsx
@@ -0,0 +1,283 @@
+import React from 'react'
+
+import { LemonInput, LemonSelect } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import type { DatabaseSchemaField } from '~/queries/schema/schema-general'
+
+// Bucket naming rules (supports both S3 and GCS):
+// S3: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
+// GCS: https://cloud.google.com/storage/docs/buckets#naming
+const BUCKET_NAME_REGEX = /^[a-z0-9][a-z0-9._-]*[a-z0-9]$|^[a-z0-9]$/
+const IP_ADDRESS_REGEX = /^(\d{1,3}\.){3}\d{1,3}$/
+
+export function validateBucketName(bucketName: string | undefined): string | undefined {
+ if (!bucketName) {
+ return undefined
+ }
+
+ if (/\s/.test(bucketName)) {
+ return 'Bucket name cannot contain whitespace'
+ }
+
+ if (bucketName !== bucketName.toLowerCase()) {
+ return 'Bucket name must be lowercase'
+ }
+
+ if (bucketName.includes('..')) {
+ return 'Bucket name cannot contain consecutive periods'
+ }
+
+ if (IP_ADDRESS_REGEX.test(bucketName)) {
+ return 'Bucket name cannot be formatted as an IP address'
+ }
+
+ if (!BUCKET_NAME_REGEX.test(bucketName)) {
+ return 'Bucket name can only contain lowercase letters, numbers, hyphens, and periods, and must start and end with a letter or number'
+ }
+
+ return undefined
+}
+
+export function validateAzureContainerName(name: string | undefined): string | undefined {
+ if (!name) {
+ return undefined
+ }
+ if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(name) && name.length > 1) {
+ return 'Must be lowercase letters, numbers, and hyphens; start and end with letter or number'
+ }
+ if (/--/.test(name)) {
+ return 'Cannot contain consecutive hyphens'
+ }
+ return undefined
+}
+
+// Full S3 region list, including GCP Cloud Storage and a handful of S3-compatible providers.
+export const S3_REGION_OPTIONS: { value: string; label: string }[] = [
+ { value: 'us-east-1', label: 'US East (N. Virginia)' },
+ { value: 'us-east-2', label: 'US East (Ohio)' },
+ { value: 'us-west-1', label: 'US West (N. California)' },
+ { value: 'us-west-2', label: 'US West (Oregon)' },
+ { value: 'af-south-1', label: 'Africa (Cape Town)' },
+ { value: 'ap-east-1', label: 'Asia Pacific (Hong Kong)' },
+ { value: 'ap-south-1', label: 'Asia Pacific (Mumbai)' },
+ { value: 'ap-northeast-3', label: 'Asia Pacific (Osaka-Local)' },
+ { value: 'ap-northeast-2', label: 'Asia Pacific (Seoul)' },
+ { value: 'ap-southeast-1', label: 'Asia Pacific (Singapore)' },
+ { value: 'ap-southeast-2', label: 'Asia Pacific (Sydney)' },
+ { value: 'ap-northeast-1', label: 'Asia Pacific (Tokyo)' },
+ { value: 'ca-central-1', label: 'Canada (Central)' },
+ { value: 'cn-north-1', label: 'China (Beijing)' },
+ { value: 'cn-northwest-1', label: 'China (Ningxia)' },
+ { value: 'eu-central-1', label: 'Europe (Frankfurt)' },
+ { value: 'eu-west-1', label: 'Europe (Ireland)' },
+ { value: 'eu-west-2', label: 'Europe (London)' },
+ { value: 'eu-south-1', label: 'Europe (Milan)' },
+ { value: 'eu-west-3', label: 'Europe (Paris)' },
+ { value: 'eu-north-1', label: 'Europe (Stockholm)' },
+ { value: 'me-east-1', label: 'Middle East (Dubai)' },
+ { value: 'me-south-1', label: 'Middle East (Bahrain)' },
+ { value: 'me-central-1', label: 'Middle East (Riyadh)' },
+ { value: 'sa-east-1', label: 'South America (São Paulo)' },
+ { value: 'us-central1', label: 'GCP — US Central (Iowa)' },
+ { value: 'europe-west4', label: 'GCP — Europe (Netherlands)' },
+ { value: 'auto', label: 'Automatic (AUTO)' },
+ { value: 'apac', label: 'Asia Pacific (APAC)' },
+ { value: 'eeur', label: 'Eastern Europe (EEUR)' },
+ { value: 'enam', label: 'Eastern North America (ENAM)' },
+ { value: 'weur', label: 'Western Europe (WEUR)' },
+ { value: 'wnam', label: 'Western North America (WNAM)' },
+ { value: 'gra', label: 'Gravelines (GRA)' },
+ { value: 'rbx', label: 'Roubaix (RBX)' },
+ { value: 'sbg', label: 'Strasbourg (SBG)' },
+ { value: 'eu-west-par', label: 'Paris (PAR)' },
+ { value: 'eu-south-mil', label: 'Milan (MIL)' },
+ { value: 'de', label: 'Frankfurt (DE)' },
+ { value: 'uk', label: 'London (UK)' },
+ { value: 'waw', label: 'Warsaw (WAW)' },
+ { value: 'bhs', label: 'Beauharnois (BHS)' },
+ { value: 'ca-east-tor', label: 'Toronto (TOR)' },
+ { value: 'sgp', label: 'Singapore (SGP)' },
+ { value: 'ap-southeast-syd', label: 'Sydney (SYD)' },
+ { value: 'ap-south-mum', label: 'Mumbai (MUM)' },
+]
+
+// AWS-only region subset used for the Redshift COPY S3 staging bucket.
+export const AWS_ONLY_REGION_OPTIONS: { value: string; label: string }[] = [
+ { value: 'us-east-1', label: 'US East (N. Virginia)' },
+ { value: 'us-east-2', label: 'US East (Ohio)' },
+ { value: 'us-west-1', label: 'US West (N. California)' },
+ { value: 'us-west-2', label: 'US West (Oregon)' },
+ { value: 'af-south-1', label: 'Africa (Cape Town)' },
+ { value: 'ap-east-1', label: 'Asia Pacific (Hong Kong)' },
+ { value: 'ap-south-1', label: 'Asia Pacific (Mumbai)' },
+ { value: 'ap-northeast-3', label: 'Asia Pacific (Osaka-Local)' },
+ { value: 'ap-northeast-2', label: 'Asia Pacific (Seoul)' },
+ { value: 'ap-southeast-1', label: 'Asia Pacific (Singapore)' },
+ { value: 'ap-southeast-2', label: 'Asia Pacific (Sydney)' },
+ { value: 'ap-northeast-1', label: 'Asia Pacific (Tokyo)' },
+ { value: 'ca-central-1', label: 'Canada (Central)' },
+ { value: 'cn-north-1', label: 'China (Beijing)' },
+ { value: 'cn-northwest-1', label: 'China (Ningxia)' },
+ { value: 'eu-central-1', label: 'Europe (Frankfurt)' },
+ { value: 'eu-west-1', label: 'Europe (Ireland)' },
+ { value: 'eu-west-2', label: 'Europe (London)' },
+ { value: 'eu-south-1', label: 'Europe (Milan)' },
+ { value: 'eu-west-3', label: 'Europe (Paris)' },
+ { value: 'eu-north-1', label: 'Europe (Stockholm)' },
+ { value: 'me-south-1', label: 'Middle East (Bahrain)' },
+ { value: 'me-central-1', label: 'Middle East (Riyadh)' },
+ { value: 'sa-east-1', label: 'South America (São Paulo)' },
+]
+
+export const FILE_FORMAT_OPTIONS: { value: string; label: string }[] = [
+ { value: 'Parquet', label: 'Apache Parquet' },
+ { value: 'JSONLines', label: 'JSON lines' },
+]
+
+const PARQUET_COMPRESSION_OPTIONS = [
+ { value: 'zstd', label: 'zstd' },
+ { value: 'lz4', label: 'lz4' },
+ { value: 'snappy', label: 'snappy' },
+ { value: 'gzip', label: 'gzip' },
+ { value: 'brotli', label: 'brotli' },
+ { value: null, label: 'No compression' },
+]
+
+const JSONLINES_COMPRESSION_OPTIONS = [
+ { value: 'gzip', label: 'gzip' },
+ { value: 'brotli', label: 'brotli' },
+ { value: null, label: 'No compression' },
+]
+
+// Compression select that adapts its options to the currently-selected file format and self-corrects
+// invalid combinations. Used by S3 and AzureBlob, which share file_format/compression semantics.
+export function CompressionField({
+ fileFormat,
+ isNew,
+ configurationChanged,
+}: {
+ fileFormat: string | undefined
+ isNew: boolean
+ configurationChanged: boolean
+}): JSX.Element {
+ return (
+ <LemonField name="compression" label="Compression" className="flex-1">
+ {({ value, onChange }) => {
+ const compressionOptions =
+ fileFormat === 'Parquet'
+ ? PARQUET_COMPRESSION_OPTIONS
+ : fileFormat === 'JSONLines'
+ ? JSONLINES_COMPRESSION_OPTIONS
+ : []
+
+ const isSelectedCompressionOptionValid = (val: string | null): boolean => {
+ if (fileFormat === 'Parquet') {
+ return PARQUET_COMPRESSION_OPTIONS.some((option) => option.value === val)
+ } else if (fileFormat === 'JSONLines') {
+ return JSONLINES_COMPRESSION_OPTIONS.some((option) => option.value === val)
+ }
+ return false
+ }
+
+ React.useEffect(() => {
+ if (!configurationChanged) {
+ return
+ }
+ if (isNew && fileFormat === 'JSONLines') {
+ onChange(null)
+ } else if (isNew && fileFormat === 'Parquet') {
+ onChange('zstd')
+ } else if (!isSelectedCompressionOptionValid(value)) {
+ onChange(null)
+ }
+ }, [configurationChanged, fileFormat, isNew]) // oxlint-disable-line react-hooks/exhaustive-deps
+
+ return (
+ <LemonSelect
+ options={compressionOptions}
+ value={value}
+ onChange={onChange}
+ placeholder={!fileFormat ? 'Select file format first' : undefined}
+ />
+ )
+ }}
+ </LemonField>
+ )
+}
+
+export function FileFormatField(): JSX.Element {
+ return (
+ <LemonField
+ name="file_format"
+ label="Format"
+ className="flex-1"
+ info="We recommend Parquet with zstd compression for the best performance"
+ >
+ <LemonSelect options={FILE_FORMAT_OPTIONS} />
+ </LemonField>
+ )
+}
+
+export function MaxFileSizeField(): JSX.Element {
+ return (
+ <LemonField
+ name="max_file_size_mb"
+ label="Max file size (MiB)"
+ showOptional
+ className="flex-1"
+ info="Files over this max file size will be split into multiple files. Leave empty or set to 0 for no splitting regardless of file size."
+ >
+ <LemonInput type="number" min={0} />
+ </LemonField>
+ )
+}
+
+// Generic person-related event columns shared by Postgres, Redshift, Snowflake, BigQuery, HTTP.
+// S3 and Databricks override these (S3 uses person_id/person_properties/created_at; Databricks
+// emits a different team_id+ingestion-timestamp pair).
+export function genericPersonEventFields(opts: {
+ teamIdHogql: string
+ setName: string
+ setOnceName: string
+}): Record<string, DatabaseSchemaField> {
+ return {
+ team_id: {
+ name: 'team_id',
+ hogql_value: opts.teamIdHogql,
+ type: 'integer',
+ schema_valid: true,
+ },
+ set: {
+ name: opts.setName,
+ hogql_value: "nullIf(JSONExtractString(properties, '$set'), '')",
+ type: 'string',
+ schema_valid: true,
+ },
+ set_once: {
+ name: opts.setOnceName,
+ hogql_value: "nullIf(JSONExtractString(properties, '$set_once'), '')",
+ type: 'string',
+ schema_valid: true,
+ },
+ site_url: {
+ name: 'site_url',
+ hogql_value: "''",
+ type: 'string',
+ schema_valid: true,
+ },
+ ip: {
+ name: 'ip',
+ hogql_value: "nullIf(JSONExtractString(properties, '$ip'), '')",
+ type: 'string',
+ schema_valid: true,
+ },
+ elements_chain: {
+ name: 'elements',
+ hogql_value: 'toJSONString(elements_chain)',
+ type: 'string',
+ schema_valid: true,
+ },
+ }
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/databricks.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/databricks.tsx
new file mode 100644
index 000000000000..38a2e1f68137
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/databricks.tsx
@@ -0,0 +1,105 @@
+import { IconInfo } from '@posthog/icons'
+import { LemonCheckbox, LemonInput, Link, Tooltip } from '@posthog/lemon-ui'
+
+import { IntegrationChoice } from 'lib/components/CyclotronJob/integrations/IntegrationChoice'
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import type { DestinationDefinition } from './types'
+
+export const databricksDefinition: DestinationDefinition = {
+ type: 'Databricks',
+ usesIntegration: true,
+ defaults: () => ({
+ use_variant_type: true,
+ // prefill prefix for http path
+ http_path: '/sql/1.0/warehouses/',
+ }),
+ requiredFields: () => ['integration_id', 'http_path', 'catalog', 'schema', 'table_name'],
+ eventTableExtraFields: {
+ team_id: {
+ name: 'team_id',
+ hogql_value: 'team_id',
+ type: 'integer',
+ schema_valid: true,
+ },
+ databricks_ingested_timestamp: {
+ name: 'databricks_ingested_timestamp',
+ hogql_value: 'NOW64()',
+ type: 'datetime',
+ schema_valid: true,
+ },
+ },
+ eventTableOverrides: { includeGenericPersonFields: false },
+ Fields: function DatabricksFields({ isNew }) {
+ return (
+ <>
+ <LemonField name="integration_id" label="Integration">
+ {({ value, onChange }) => (
+ <IntegrationChoice integration="databricks" value={value} onChange={onChange} />
+ )}
+ </LemonField>
+
+ <LemonField
+ name="http_path"
+ label="HTTP Path"
+ info={<>HTTP Path value for your all-purpose compute or SQL warehouse.</>}
+ >
+ <LemonInput placeholder="/sql/1.0/warehouses/my-warehouse" />
+ </LemonField>
+
+ <LemonField name="catalog" label="Catalog">
+ <LemonInput placeholder="workspace" />
+ </LemonField>
+
+ <LemonField name="schema" label="Schema">
+ <LemonInput placeholder="default" />
+ </LemonField>
+
+ <LemonField name="table_name" label="Table name">
+ <LemonInput placeholder="my-table" />
+ </LemonField>
+
+ {isNew ? (
+ <LemonField name="use_variant_type">
+ {({ value, onChange }) => (
+ <LemonCheckbox
+ checked={!!value}
+ onChange={onChange}
+ bordered
+ label={
+ <span className="flex gap-2 items-center">
+ Use VARIANT type for storing JSON data
+ <Tooltip
+ interactive
+ title={
+ <>
+ Using VARIANT for storing JSON data is{' '}
+ <Link
+ to="https://docs.databricks.com/aws/en/semi-structured/variant"
+ target="_blank"
+ >
+ recommended by Databricks
+ </Link>{' '}
+ , however, the VARIANT data type is only available in Databricks
+ Runtime 15.3 and above. If left unchecked, JSON data will be stored
+ using the STRING type.
+ <br />
+ <strong>
+ This setting cannot be changed after the batch export is
+ created.
+ </strong>
+ </>
+ }
+ >
+ <IconInfo className="text-lg text-secondary" />
+ </Tooltip>
+ </span>
+ }
+ />
+ )}
+ </LemonField>
+ ) : null}
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/http.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/http.tsx
new file mode 100644
index 000000000000..493f3513d879
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/http.tsx
@@ -0,0 +1,29 @@
+import { LemonInput, LemonSelect } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import type { DestinationDefinition } from './types'
+
+export const httpDefinition: DestinationDefinition = {
+ type: 'HTTP',
+ defaults: () => ({}),
+ requiredFields: () => ['url', 'token'],
+ eventTableOverrides: { teamIdHogql: 'team_id' },
+ Fields: function HttpFields() {
+ return (
+ <>
+ <LemonField name="url" label="PostHog region">
+ <LemonSelect
+ options={[
+ { value: 'https://us.i.posthog.com/batch/', label: 'US' },
+ { value: 'https://eu.i.posthog.com/batch/', label: 'EU' },
+ ]}
+ />
+ </LemonField>
+ <LemonField name="token" label="Destination project token">
+ <LemonInput placeholder="e.g. phc_12345..." />
+ </LemonField>
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/index.ts b/frontend/src/scenes/data-pipelines/batch-exports/destinations/index.ts
new file mode 100644
index 000000000000..abc0924a0122
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/index.ts
@@ -0,0 +1,22 @@
+import { azureBlobDefinition } from './azureblob'
+import { bigqueryDefinition } from './bigquery'
+import { databricksDefinition } from './databricks'
+import { httpDefinition } from './http'
+import { postgresDefinition } from './postgres'
+import { redshiftDefinition } from './redshift'
+import { s3Definition } from './s3'
+import { snowflakeDefinition } from './snowflake'
+import type { BatchExportServiceType, DestinationDefinition } from './types'
+
+export const DESTINATIONS: Record<BatchExportServiceType, DestinationDefinition> = {
+ S3: s3Definition,
+ Postgres: postgresDefinition,
+ Redshift: redshiftDefinition,
+ Snowflake: snowflakeDefinition,
+ BigQuery: bigqueryDefinition,
+ HTTP: httpDefinition,
+ Databricks: databricksDefinition,
+ AzureBlob: azureBlobDefinition,
+}
+
+export type { DestinationDefinition, BatchExportServiceType } from './types'
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/postgres.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/postgres.tsx
new file mode 100644
index 000000000000..8a9c32fa36d6
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/postgres.tsx
@@ -0,0 +1,72 @@
+import { IconInfo } from '@posthog/icons'
+import { LemonCheckbox, LemonInput, Tooltip } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import type { DestinationDefinition } from './types'
+
+export const postgresDefinition: DestinationDefinition = {
+ type: 'Postgres',
+ defaults: () => ({}),
+ requiredFields: ({ isNew }) => [
+ ...(isNew ? ['user'] : []),
+ ...(isNew ? ['password'] : []),
+ 'host',
+ 'port',
+ 'database',
+ 'schema',
+ 'table_name',
+ ],
+ eventTableOverrides: { teamIdHogql: 'toInt32(team_id)' },
+ Fields: function PostgresFields({ isNew }) {
+ return (
+ <>
+ <LemonField name="user" label="User">
+ <LemonInput placeholder={isNew ? 'my-user' : 'Leave unchanged'} />
+ </LemonField>
+
+ <LemonField name="password" label="Password">
+ <LemonInput placeholder={isNew ? 'my-password' : 'Leave unchanged'} type="password" />
+ </LemonField>
+
+ <LemonField name="host" label="Host">
+ <LemonInput placeholder="my-host" />
+ </LemonField>
+
+ <LemonField name="port" label="Port">
+ <LemonInput placeholder="5432" type="number" min="0" max="65535" />
+ </LemonField>
+
+ <LemonField name="database" label="Database">
+ <LemonInput placeholder="my-database" />
+ </LemonField>
+
+ <LemonField name="schema" label="Schema">
+ <LemonInput placeholder="public" />
+ </LemonField>
+
+ <LemonField name="table_name" label="Table name">
+ <LemonInput placeholder="events" />
+ </LemonField>
+
+ <LemonField name="has_self_signed_cert">
+ {({ value, onChange }) => (
+ <LemonCheckbox
+ bordered
+ label={
+ <span className="flex gap-2 items-center">
+ Does your Postgres instance have a self-signed SSL certificate?
+ <Tooltip title="In most cases, Heroku and RDS users should check this.">
+ <IconInfo className="text-lg text-secondary" />
+ </Tooltip>
+ </span>
+ }
+ checked={!!value}
+ onChange={onChange}
+ />
+ )}
+ </LemonField>
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/redshift.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/redshift.tsx
new file mode 100644
index 000000000000..b0094e850bc9
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/redshift.tsx
@@ -0,0 +1,295 @@
+import { LemonInput, LemonSelect } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import { AWS_ONLY_REGION_OPTIONS, validateBucketName } from './common'
+import type { DestinationDefinition } from './types'
+
+// Redshift is the only destination with a non-trivial form ↔ payload mapping.
+// The COPY mode requires nested copy_inputs (s3_bucket, s3_key_prefix, region_name,
+// authorization, bucket_credentials), which we flatten to top-level redshift_* fields
+// in the form for editing and re-assemble on save.
+function buildCopyInputs(formValues: Record<string, any>): Record<string, any> {
+ const copyInputs: Record<string, any> = {
+ s3_bucket: formValues.redshift_s3_bucket,
+ s3_key_prefix: formValues.redshift_s3_key_prefix,
+ region_name: formValues.redshift_s3_bucket_region_name,
+ }
+
+ if (formValues.redshift_iam_role) {
+ copyInputs.authorization = formValues.redshift_iam_role
+ } else if (formValues.redshift_aws_access_key_id && formValues.redshift_aws_secret_access_key) {
+ copyInputs.authorization = {
+ aws_access_key_id: formValues.redshift_aws_access_key_id,
+ aws_secret_access_key: formValues.redshift_aws_secret_access_key,
+ }
+ }
+
+ if (formValues.redshift_s3_bucket_aws_access_key_id && formValues.redshift_s3_bucket_aws_secret_access_key) {
+ copyInputs.bucket_credentials = {
+ aws_access_key_id: formValues.redshift_s3_bucket_aws_access_key_id,
+ aws_secret_access_key: formValues.redshift_s3_bucket_aws_secret_access_key,
+ }
+ }
+
+ return copyInputs
+}
+
+const REDSHIFT_FORM_ONLY_FIELDS = [
+ 'mode',
+ 'authorization_mode',
+ // copy_inputs is re-assembled from the flat redshift_* fields in COPY mode and must not be
+ // carried over verbatim — otherwise switching a COPY export to INSERT leaks the stale object.
+ 'copy_inputs',
+ 'redshift_s3_bucket',
+ 'redshift_s3_key_prefix',
+ 'redshift_s3_bucket_region_name',
+ 'redshift_s3_bucket_aws_access_key_id',
+ 'redshift_s3_bucket_aws_secret_access_key',
+ 'redshift_iam_role',
+ 'redshift_aws_access_key_id',
+ 'redshift_aws_secret_access_key',
+] as const
+
+export const redshiftDefinition: DestinationDefinition = {
+ type: 'Redshift',
+ defaults: () => ({
+ mode: 'COPY',
+ authorization_mode: 'IAMRole',
+ properties_data_type: 'SUPER',
+ }),
+ requiredFields: ({ isNew }) => [
+ ...(isNew ? ['user'] : []),
+ ...(isNew ? ['password'] : []),
+ 'host',
+ 'port',
+ 'database',
+ 'schema',
+ 'table_name',
+ ],
+ validate: (formValues) => {
+ if (formValues.mode === 'COPY') {
+ return { redshift_s3_bucket: validateBucketName(formValues.redshift_s3_bucket) }
+ }
+ return {}
+ },
+ serialize: (formValues) => {
+ const config: Record<string, any> = {}
+ for (const [key, value] of Object.entries(formValues)) {
+ if ((REDSHIFT_FORM_ONLY_FIELDS as readonly string[]).includes(key)) {
+ continue
+ }
+ config[key] = value
+ }
+ config.mode = formValues.mode
+ // copy_inputs is rebuilt from the flat redshift_* fields in COPY mode and explicitly nulled
+ // in INSERT mode — never carried over from the deserialized form state.
+ config.copy_inputs = formValues.mode === 'COPY' ? buildCopyInputs(formValues) : null
+ return config
+ },
+ deserialize: (config) => {
+ const result: Record<string, any> = { ...config, authorization_mode: 'IAMRole' }
+ if (config.copy_inputs) {
+ const copyInputs = config.copy_inputs
+ result.redshift_s3_bucket = copyInputs.s3_bucket
+ result.redshift_s3_key_prefix = copyInputs.s3_key_prefix
+ result.redshift_s3_bucket_region_name = copyInputs.region_name
+ result.redshift_s3_bucket_aws_access_key_id = copyInputs.bucket_credentials?.aws_access_key_id
+ result.redshift_s3_bucket_aws_secret_access_key = copyInputs.bucket_credentials?.aws_secret_access_key
+ result.redshift_iam_role = undefined
+ result.redshift_aws_access_key_id = undefined
+ result.redshift_aws_secret_access_key = undefined
+
+ if (typeof copyInputs.authorization === 'string') {
+ result.authorization_mode = 'IAMRole'
+ result.redshift_iam_role = copyInputs.authorization
+ } else if (copyInputs.authorization) {
+ result.authorization_mode = 'Credentials'
+ result.redshift_aws_access_key_id = copyInputs.authorization.aws_access_key_id
+ result.redshift_aws_secret_access_key = copyInputs.authorization.aws_secret_access_key
+ }
+ }
+ return result
+ },
+ eventTableOverrides: { teamIdHogql: 'toInt32(team_id)' },
+ Fields: function RedshiftFields({ isNew, formValues }) {
+ return (
+ <>
+ <LemonField name="user" label="User">
+ <LemonInput placeholder={isNew ? 'my-user' : 'Leave unchanged'} />
+ </LemonField>
+
+ <LemonField name="password" label="Password">
+ <LemonInput placeholder={isNew ? 'my-password' : 'Leave unchanged'} type="password" />
+ </LemonField>
+
+ <LemonField name="host" label="Host">
+ <LemonInput placeholder="my-host" />
+ </LemonField>
+
+ <LemonField name="port" label="Port">
+ <LemonInput placeholder="5439" type="number" min="0" max="65535" />
+ </LemonField>
+
+ <LemonField name="database" label="Database">
+ <LemonInput placeholder="my-database" />
+ </LemonField>
+
+ <LemonField name="schema" label="Schema">
+ <LemonInput placeholder="public" />
+ </LemonField>
+
+ <LemonField name="table_name" label="Table name">
+ <LemonInput placeholder="events" />
+ </LemonField>
+
+ <LemonField
+ name="properties_data_type"
+ label="Semi-structured data type"
+ info={
+ <>
+ Different PostHog models have semi-structured data fields in them, like "events.properties".
+ We can export these fields to Redshift as a "SUPER" type column, or a "VARCHAR" column. We
+ recommend "SUPER" over "VARCHAR" as "VARCHAR" has a strict length limit that applies on the
+ entire document, whereas with "SUPER" the limit applies on each value in the document.
+ </>
+ }
+ >
+ <LemonSelect
+ options={[
+ { value: 'varchar', label: 'VARCHAR(65535)' },
+ { value: 'super', label: 'SUPER' },
+ ]}
+ />
+ </LemonField>
+
+ <LemonField
+ name="mode"
+ label="Command"
+ className="flex-1"
+ info={
+ <>
+ Choose the SQL command used by the batch export. "COPY" has the best performance but
+ requires an S3 bucket we can connect to. "INSERT" performs worse but without any additional
+ requirements.
+ </>
+ }
+ >
+ <LemonSelect
+ options={[
+ { value: 'COPY', label: 'COPY' },
+ { value: 'INSERT', label: 'INSERT' },
+ ]}
+ />
+ </LemonField>
+
+ {formValues.mode === 'COPY' && (
+ <>
+ <p className="text-xs text-muted mt-1">
+ In order to execute a COPY SQL command, the batch export will first export files to an S3
+ bucket, which requires credentials to access it. After the files are available in the
+ bucket, we will instruct Redshift to copy them into the configured table. As part of this,
+ the batch export needs to specify to Redshift how to access your bucket. For this reason,
+ additionally to the first set of credentials used by the batch export, either an IAM role
+ (recommended), or the same or a different set of credentials is required.
+ </p>
+
+ <div className="flex gap-4">
+ <LemonField name="redshift_s3_bucket" label="S3 bucket name" className="flex-1">
+ <LemonInput placeholder="e.g. my-bucket" />
+ </LemonField>
+ <LemonField
+ name="redshift_s3_bucket_region_name"
+ label="S3 bucket region"
+ className="flex-1"
+ >
+ <LemonSelect options={AWS_ONLY_REGION_OPTIONS} />
+ </LemonField>
+ </div>
+
+ <LemonField name="redshift_s3_key_prefix" label="S3 key prefix" className="flex-1">
+ <LemonInput placeholder="e.g. /posthog-copy-files" />
+ </LemonField>
+
+ <div className="flex gap-4">
+ <LemonField
+ name="redshift_s3_bucket_aws_access_key_id"
+ label="AWS Access Key ID"
+ className="flex-1"
+ >
+ <LemonInput
+ placeholder={isNew ? 'e.g. AKIAIOSFODNN7EXAMPLE' : 'Leave unchanged'}
+ autoComplete="off"
+ />
+ </LemonField>
+
+ <LemonField
+ name="redshift_s3_bucket_aws_secret_access_key"
+ label="AWS Secret Access Key"
+ className="flex-1"
+ >
+ <LemonInput
+ placeholder={isNew ? 'e.g. secret-key' : 'Leave unchanged'}
+ type="password"
+ autoComplete="new-password"
+ />
+ </LemonField>
+ </div>
+
+ <LemonField
+ name="authorization_mode"
+ label="Authorization"
+ className="flex-1"
+ info={
+ <>
+ Redshift needs to authenticate to COPY data from your S3 bucket. Choose whether to
+ assume an IAM role or to provide it with credentials to access the S3 bucket.
+ </>
+ }
+ >
+ <LemonSelect
+ options={[
+ { value: 'IAMRole', label: 'IAM Role' },
+ { value: 'Credentials', label: 'Credentials' },
+ ]}
+ />
+ </LemonField>
+
+ {formValues.authorization_mode === 'IAMRole' && (
+ <LemonField name="redshift_iam_role" label="IAM Role ARN" className="flex-1">
+ <LemonInput placeholder="e.g. arn:aws:iam::<aws-account-id>:role/<role-name>" />
+ </LemonField>
+ )}
+
+ {formValues.authorization_mode === 'Credentials' && (
+ <div className="flex gap-4">
+ <LemonField
+ name="redshift_aws_access_key_id"
+ label="AWS Access Key ID"
+ className="flex-1"
+ >
+ <LemonInput
+ placeholder={isNew ? 'e.g. AKIAIOSFODNN7EXAMPLE' : 'Leave unchanged'}
+ autoComplete="off"
+ />
+ </LemonField>
+
+ <LemonField
+ name="redshift_aws_secret_access_key"
+ label="AWS Secret Access Key"
+ className="flex-1"
+ >
+ <LemonInput
+ placeholder={isNew ? 'e.g. secret-key' : 'Leave unchanged'}
+ type="password"
+ autoComplete="new-password"
+ />
+ </LemonField>
+ </div>
+ )}
+ </>
+ )}
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsx
new file mode 100644
index 000000000000..da11eed3876e
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/s3.tsx
@@ -0,0 +1,152 @@
+import { LemonCheckbox, LemonInput, LemonSelect, Link } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import { CompressionField, FileFormatField, MaxFileSizeField, S3_REGION_OPTIONS, validateBucketName } from './common'
+import type { DestinationDefinition } from './types'
+
+export const s3Definition: DestinationDefinition = {
+ type: 'S3',
+ defaults: () => ({
+ file_format: 'Parquet',
+ compression: 'zstd',
+ }),
+ requiredFields: ({ isNew }) => [
+ 'bucket_name',
+ 'region',
+ 'prefix',
+ ...(isNew ? ['aws_access_key_id'] : []),
+ ...(isNew ? ['aws_secret_access_key'] : []),
+ ...(isNew ? ['file_format'] : []),
+ ],
+ validate: (formValues) => ({
+ bucket_name: validateBucketName(formValues.bucket_name),
+ }),
+ eventTableExtraFields: {
+ person_id: {
+ name: 'person_id',
+ hogql_value: 'toString(person_id)',
+ type: 'string',
+ schema_valid: true,
+ },
+ person_properties: {
+ name: 'person_properties',
+ hogql_value: "nullIf(person_properties, '')",
+ type: 'string',
+ schema_valid: true,
+ },
+ created_at: {
+ name: 'created_at',
+ hogql_value: 'created_at',
+ type: 'datetime',
+ schema_valid: true,
+ },
+ },
+ eventTableOverrides: { includeGenericPersonFields: false },
+ Fields: function S3Fields({ isNew, formValues, configurationChanged }) {
+ return (
+ <>
+ <div className="flex gap-4">
+ <LemonField name="bucket_name" label="Bucket" className="flex-1">
+ <LemonInput placeholder="e.g. my-bucket" />
+ </LemonField>
+ <LemonField name="region" label="Region" className="flex-1">
+ <LemonSelect options={S3_REGION_OPTIONS} />
+ </LemonField>
+ </div>
+ <LemonField
+ name="prefix"
+ label="Key prefix"
+ info={
+ <>
+ Template variables are supported. Please check out the{' '}
+ <Link
+ to="https://posthog.com/docs/cdp/batch-exports/s3#s3-key-prefix-template-variables"
+ target="_blank"
+ >
+ docs
+ </Link>{' '}
+ for more information.
+ </>
+ }
+ >
+ <LemonInput placeholder="e.g. posthog-events/" />
+ </LemonField>
+
+ <div className="flex gap-4">
+ <FileFormatField />
+ <MaxFileSizeField />
+ </div>
+
+ <div className="flex gap-4">
+ <CompressionField
+ fileFormat={formValues.file_format}
+ isNew={isNew}
+ configurationChanged={configurationChanged}
+ />
+
+ <LemonField name="encryption" label="Encryption" className="flex-1">
+ <LemonSelect
+ options={[
+ { value: 'AES256', label: 'AES256' },
+ { value: 'aws:kms', label: 'aws:kms' },
+ { value: null, label: 'No encryption' },
+ ]}
+ />
+ </LemonField>
+ </div>
+
+ <div className="flex gap-4">
+ <LemonField name="aws_access_key_id" label="AWS Access Key ID" className="flex-1">
+ <LemonInput
+ placeholder={isNew ? 'e.g. AKIAIOSFODNN7EXAMPLE' : 'Leave unchanged'}
+ autoComplete="off"
+ />
+ </LemonField>
+
+ <LemonField name="aws_secret_access_key" label="AWS Secret Access Key" className="flex-1">
+ <LemonInput
+ placeholder={isNew ? 'e.g. secret-key' : 'Leave unchanged'}
+ type="password"
+ autoComplete="new-password"
+ />
+ </LemonField>
+
+ {formValues.encryption == 'aws:kms' && (
+ <LemonField name="kms_key_id" label="AWS KMS Key ID" className="flex-1">
+ <LemonInput
+ placeholder={isNew ? 'e.g. 1234abcd-12ab-34cd-56ef-1234567890ab' : 'leave unchanged'}
+ />
+ </LemonField>
+ )}
+ </div>
+
+ <LemonField
+ name="endpoint_url"
+ label="Endpoint URL"
+ showOptional
+ info={<>Only required if exporting to an S3-compatible blob storage (like MinIO)</>}
+ >
+ <LemonInput placeholder={isNew ? 'e.g. https://your-minio-host:9000' : 'Leave unchanged'} />
+ </LemonField>
+
+ <LemonField
+ name="use_virtual_style_addressing"
+ label="Virtual style addressing"
+ showOptional
+ info={
+ <>
+ Some non-AWS S3-compatible destinations may require this setting enabled. Check your
+ destination's documentation if "virtual hosted style" is required, otherwise leave unchecked
+ </>
+ }
+ >
+ <LemonCheckbox
+ bordered
+ label={<span className="flex gap-2 items-center">Use virtual style addressing</span>}
+ />
+ </LemonField>
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/snowflake.tsx b/frontend/src/scenes/data-pipelines/batch-exports/destinations/snowflake.tsx
new file mode 100644
index 000000000000..4fa930d7cb30
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/snowflake.tsx
@@ -0,0 +1,98 @@
+import { LemonInput, LemonSelect, LemonTextArea } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import type { DestinationDefinition } from './types'
+
+export const snowflakeDefinition: DestinationDefinition = {
+ type: 'Snowflake',
+ defaults: () => ({
+ authentication_type: 'password',
+ }),
+ requiredFields: ({ isNew, formValues }) => [
+ 'account',
+ 'database',
+ 'warehouse',
+ ...(isNew ? ['user'] : []),
+ ...(isNew && formValues.authentication_type == 'password' ? ['password'] : []),
+ ...(isNew && formValues.authentication_type == 'keypair' ? ['private_key'] : []),
+ 'schema',
+ 'table_name',
+ ],
+ eventTableOverrides: {
+ setName: 'people_set',
+ setOnceName: 'people_set_once',
+ },
+ eventTableExtraFields: {
+ snowflake_ingested_timestamp: {
+ name: 'snowflake_ingested_timestamp',
+ hogql_value: 'NOW64()',
+ type: 'datetime',
+ schema_valid: true,
+ },
+ },
+ Fields: function SnowflakeFields({ isNew, formValues }) {
+ return (
+ <>
+ <LemonField name="account" label="Account">
+ <LemonInput placeholder="my-account" />
+ </LemonField>
+
+ <LemonField name="user" label="User">
+ <LemonInput placeholder={isNew ? 'my-user' : 'Leave unchanged'} />
+ </LemonField>
+
+ <LemonField name="authentication_type" label="Authentication type" className="flex-1">
+ <LemonSelect
+ options={[
+ { value: 'password', label: 'Password' },
+ { value: 'keypair', label: 'Key pair' },
+ ]}
+ />
+ </LemonField>
+
+ {formValues.authentication_type != 'keypair' && (
+ <LemonField name="password" label="Password">
+ <LemonInput placeholder={isNew ? 'my-password' : 'Leave unchanged'} type="password" />
+ </LemonField>
+ )}
+
+ {formValues.authentication_type == 'keypair' && (
+ <>
+ <LemonField name="private_key" label="Private key">
+ <LemonTextArea
+ className="ph-ignore-input"
+ placeholder={isNew ? 'my-private-key' : 'Leave unchanged'}
+ minRows={4}
+ />
+ </LemonField>
+
+ <LemonField name="private_key_passphrase" label="Private key passphrase">
+ <LemonInput placeholder={isNew ? 'my-passphrase' : 'Leave unchanged'} />
+ </LemonField>
+ </>
+ )}
+
+ <LemonField name="database" label="Database">
+ <LemonInput placeholder="my-database" />
+ </LemonField>
+
+ <LemonField name="warehouse" label="Warehouse">
+ <LemonInput placeholder="my-warehouse" />
+ </LemonField>
+
+ <LemonField name="schema" label="Schema">
+ <LemonInput placeholder="my-schema" />
+ </LemonField>
+
+ <LemonField name="table_name" label="Table name">
+ <LemonInput placeholder="events" />
+ </LemonField>
+
+ <LemonField name="role" label="Role" showOptional>
+ <LemonInput placeholder="my-role" />
+ </LemonField>
+ </>
+ )
+ },
+}
diff --git a/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.ts b/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.ts
new file mode 100644
index 000000000000..c61f0d0d12a6
--- /dev/null
+++ b/frontend/src/scenes/data-pipelines/batch-exports/destinations/types.ts
@@ -0,0 +1,38 @@
+import type React from 'react'
+
+import type { DatabaseSchemaField } from '~/queries/schema/schema-general'
+import type { BatchExportService } from '~/types'
+
+export type BatchExportServiceType = BatchExportService['type']
+
+export interface DestinationContext {
+ isNew: boolean
+ formValues: Record<string, any>
+}
+
+// Overrides applied to the events table preview shown in the HogQL model picker.
+// `includeGenericPersonFields: false` opts out of the default set/set_once/site_url/ip/elements_chain block.
+export interface EventTableOverrides {
+ teamIdHogql?: string
+ setName?: string
+ setOnceName?: string
+ includeGenericPersonFields?: boolean
+}
+
+export interface DestinationDefinition {
+ type: BatchExportServiceType
+ defaults: () => Record<string, any>
+ requiredFields: (ctx: DestinationContext) => string[]
+ // Field-level errors beyond the "required" check. Return undefined for valid fields.
+ validate?: (formValues: Record<string, any>) => Record<string, string | undefined>
+ // Form fields → API destination.config payload. Default behaviour: pass remaining fields through unchanged.
+ serialize?: (formValues: Record<string, any>) => Record<string, any>
+ // API destination.config → flat form fields. Default: spread.
+ deserialize?: (config: Record<string, any>) => Record<string, any>
+ // Extra columns added to the events table preview for this destination.
+ eventTableExtraFields?: Record<string, DatabaseSchemaField>
+ eventTableOverrides?: EventTableOverrides
+ // Lift integration_id from destination.integration during deserialize and push it back during save.
+ usesIntegration?: boolean
+ Fields: React.FC<{ isNew: boolean; formValues: Record<string, any>; configurationChanged: boolean }>
+}