import { AnyType, CreateDuckdbCredentials, CreateDuckdbMotherduckCredentials, DimensionType, Metric, SupportedDbtAdapter, WarehouseCatalog, WarehouseResults, WarehouseTables, type TimestampDomain, type WarehouseQueryPhase } from '@lightdash/common'; import WarehouseBaseClient from './WarehouseBaseClient'; import WarehouseBaseSqlBuilder from './WarehouseBaseSqlBuilder'; export type DuckdbS3SessionConfig = { endpoint: string; region?: string; accessKey?: string; secretKey?: string; forcePathStyle: boolean; useSsl: boolean; /** Limit this DuckDB secret to trusted S3 URIs or prefixes. */ scope?: string[]; /** PEM bundle httpfs verifies HTTPS object storage with. */ caCertFile?: string; }; export type DuckdbResourceLimits = { memoryLimit?: string; threads?: number; }; export type DuckdbLogger = { info: (message: string, metadata?: Record) => void; warn?: (message: string, metadata?: Record) => void; }; export type DuckdbQueryProfileMetrics = { latencyMs: number; cpuMs: number; waitMs: number; readParquetMs: number | null; bytesRead: number | null; rowsReturned: number | null; rowsScanned: number | null; scanAmplification: number | null; }; export type DuckdbS3Credentials = { type: 'duckdb_s3'; s3Config: DuckdbS3SessionConfig; }; /** Server-owned manifest. Never accept this configuration from project APIs. */ export type DuckdbParquetSource = { scope: string; tables: { name: string; urls: string[]; }[]; /** Typed, empty lookups for snapshots which have not been published yet. */ emptyTables?: { name: string; columns: { name: string; type: 'VARCHAR' | 'BOOLEAN' | 'TIMESTAMP' | 'INTEGER' | 'BIGINT'; }[]; }[]; /** Exact server-signed GET URLs; never combine with bucket credentials. */ signedUrls?: boolean; httpAuth?: { bearerToken: string; }; s3Config?: DuckdbS3SessionConfig; }; export type DuckdbParquetCredentials = { type: 'duckdb_parquet'; /** Resolve again for every session so new files and refreshed credentials are visible. */ resolveSource: () => Promise; }; export type DuckdbConnectionCredentials = DuckdbS3Credentials | DuckdbParquetCredentials; export type DuckdbWarehouseClientOptions = { /** Resource-constrained isolated sessions, used for materialization/parquet conversion and embedded databases. */ resourceLimits?: DuckdbResourceLimits; /** Resource limits for query sessions. When combined with instanceCacheKey, they apply to the shared warm instance. */ sharedResourceLimits?: DuckdbResourceLimits; /** * Optional process-wide cache key for a shared DuckDB instance. * The cache key is the instance identity: callers must use a different key for * different connection settings / resource limits. Leave undefined for non-shared * usage such as materialization and future MotherDuck querying. */ instanceCacheKey?: string; logger?: DuckdbLogger; enableQueryProfiling?: boolean; onQueryProfile?: (profile: DuckdbQueryProfileMetrics) => void; embeddedQueryTimeoutMs?: number; enableInstanceCache?: boolean; projectUuid?: string; /** Process-local per-organization cap for isolated S3 query clients. */ organizationConcurrencyLimit?: number; }; export declare const mapFieldTypeFromTypeId: (typeId: number) => DimensionType; export declare const getDuckdbTimestampDomainFromString: (typeName: string) => TimestampDomain | undefined; export declare class DuckdbSqlBuilder extends WarehouseBaseSqlBuilder { getAdapterType(): SupportedDbtAdapter; getFloatingType(): string; getMetricSql(sql: string, metric: Metric): string; concatString(...args: string[]): string; } export declare const buildMotherduckConnectionString: ({ database, token, }: Pick) => string; export declare class DuckdbWarehouseClient extends WarehouseBaseClient { private static readonly sharedInstances; private static readonly sharedInstanceResourceLimits; private static readonly sharedInstanceSemaphores; private static readonly embeddedConcurrencyBudget; private static readonly embeddedOrganizationConcurrencyBudgets; private static readonly organizationConcurrencyBudgets; private static readonly sqlBuilder; private readonly databasePath; private readonly s3Config?; private readonly parquetConfig?; private readonly ducklakeConfig?; private readonly embeddedConfig?; private readonly resourceLimits?; private readonly sharedResourceLimits?; private readonly instanceCacheKey?; private readonly logger?; private readonly enableQueryProfiling; private readonly onQueryProfile?; private readonly embeddedQueryTimeoutMs; private readonly enableInstanceCache; private readonly projectUuid?; private readonly organizationConcurrencyLimit?; private allowsPreAggregateFileReads; private hasWarnedAboutMotherduckTimezone; constructor(credentials?: CreateDuckdbCredentials | DuckdbConnectionCredentials, options?: DuckdbWarehouseClientOptions); private static hashDucklakeConfig; static createForPreAggregate(credentials: DuckdbS3Credentials, options?: DuckdbWarehouseClientOptions): DuckdbWarehouseClient; private static getSharedInstanceSemaphore; private getRequiredInstanceCacheKey; private static tryAcquireEmbeddedConcurrency; private static tryAcquireOrganizationConcurrency; private getSQLWithMetadata; private static hardenInstance; private static applyResourceLimits; private static usesS3CredentialChain; private static getBundledExtensionPath; private loadExtension; private loadAwsExtensionForCredentialChain; private static bootstrapQuerySession; private bootstrapParquetViews; private static bootstrapSharedInstance; private static getOrCreateSharedInstance; private static clearSharedInstance; /** Reset shared state without closing — for use in tests with mocked instances. */ static resetSharedDuckdbStateForTesting(): void; close(): Promise; private static readonly DUCKLAKE_CATALOG_SECRET; private static readonly DUCKLAKE_DATA_SECRET; private static readonly DUCKLAKE_SECRET; private static escapeDuckdbString; private static quoteIdent; private static buildDucklakeCatalogSecretSql; private static buildDucklakeDataSecretSql; private static catalogUsesSecret; private static buildDucklakeSecretSql; private static buildDucklakeAttachSql; private static buildS3SecretSql; private static readonly CONNECT_RETRIES_BEFORE_RECREATE; private connectWithRetry; /** Bootstrap for isolated instances — no shared locks needed. */ private bootstrapIsolatedSession; /** Ephemeral DuckDB instance with resource limits (e.g. parquet conversion). */ private withIsolatedSession; private withEphemeralQuerySession; private withSharedSession; private hasResourceLimits; private isMotherduck; private withSession; private withMotherduckCachedSession; /** Direct connection to the configured MotherDuck database. */ private withDirectSession; private withEmbeddedQueryDeadline; private getEmbeddedQueryTimeoutError; private getBindValues; private logQueryProfile; private static getFieldsFromStreamResult; private static stripSqlComments; private static validateSqlFunctions; static validateUserSqlFileAccess(sql: string): void; private validateSelectSql; private validateUserSql; private validatePreAggregateSql; private validateInternalSql; streamQuery(sql: string, streamCallback: (data: WarehouseResults) => void | Promise, options?: { values?: AnyType[]; queryParams?: Record; tags?: Record; timezone?: string; onPhaseTiming?: (phase: WarehouseQueryPhase, durationMs: number) => void; }): Promise; executeAsyncQuery(...args: Parameters['executeAsyncQuery']>): Promise<{ queryId: string | null; queryMetadata: import("@lightdash/common").WarehouseQueryMetadata | null; totalRows: number; phaseTimings: import("@lightdash/common").WarehousePhaseTimings; durationMs: number; }>; runSql(sql: string): Promise; runSqlWithMetrics(sql: string): Promise<{ bootstrapMs: number; queryMs: number; totalMs: number; }>; runQuery(...args: Parameters['runQuery']>): Promise<{ fields: Record; rows: Record[]; }>; test(): Promise; getCatalog(config: { database: string; schema: string; table: string; }[]): Promise; getAllTables(schema?: string, tags?: Record): Promise; getFields(tableName: string, schema?: string, database?: string, _tags?: Record): Promise; } //# sourceMappingURL=DuckdbWarehouseClient.d.ts.map