import { $ as QueryClient, M as Sql } from '../view-BCWJcLF6.js';
import '@clickhouse/client';
import 'typia';
import 'typia/lib/tags';
import 'node:stream';

/**
 * ClickHouse diagnostic helpers for benchmarking and profiling queries.
 *
 * Provides utilities to:
 *   - EXPLAIN a query and extract index/granule stats
 *   - Profile query execution via system.query_log
 *   - Benchmark a query over N runs with p50/p95 percentiles
 *   - Get row count, part count, and disk size for a table
 */

interface BenchmarkResult {
    readonly profiles: readonly ProfileResult[];
    readonly p50: number;
    readonly p95: number;
}
declare function percentile(values: number[], p: number): number;
interface ExplainResult {
    readonly indexCondition: string;
    readonly selectedGranules: number;
    readonly totalGranules: number;
    readonly granuleSkipPct: number;
    readonly rawPlan: string;
}
/**
 * Run EXPLAIN indexes=1 on a query and extract index condition and granule stats.
 *
 * Note: The query is rendered via `toQueryPreview` and re-wrapped with `sql.raw`.
 * This bakes parameterized values into the EXPLAIN string as literals, which
 * matches ClickHouse EXPLAIN behavior (it does not support parameterized queries).
 */
declare function explain(queryClient: QueryClient, query: Sql): Promise<ExplainResult>;
interface ProfileResult {
    readonly queryId: string;
    readonly readRows: number;
    readonly readBytes: number;
    readonly memoryUsage: number;
    readonly durationMs: number;
    readonly resultRows: number;
    readonly diskReadUs: number;
    readonly osReadBytes: number;
}
/**
 * Execute a query and return its query_id for later profile resolution.
 * Does NOT flush logs or read system.query_log — call resolveProfiles() after all runs.
 */
declare function profileQuery(queryClient: QueryClient, query: Sql): Promise<string>;
/**
 * Flush logs once and batch-resolve all query_ids from system.query_log.
 * Call this after all profileQuery() calls are complete.
 *
 * Query IDs are parameterized via the `sql` template tag to prevent injection.
 */
declare function resolveProfiles(queryClient: QueryClient, queryIds: string[]): Promise<ProfileResult[]>;
/**
 * Run a query N times, then batch-resolve all profiles in one flush + one lookup.
 * Returns profiles with p50/p95 of server-side duration.
 */
declare function profileBenchmark(queryClient: QueryClient, query: Sql, runs: number): Promise<BenchmarkResult>;
interface TableStats {
    readonly table: string;
    readonly rows: number;
    readonly parts: number;
    readonly diskSize: string;
}
declare function tableStats(queryClient: QueryClient, table: string): Promise<TableStats>;

/**
 * Test report accumulator — collects results from test cases
 * and writes a timestamped JSON detail file.
 */
interface TestReportTarget {
    readonly host: string;
    readonly database: string;
}
interface TestReport {
    readonly timestamp: string;
    readonly target: TestReportTarget;
    tests: Record<string, unknown>;
}
interface TestReporterOptions {
    /** Prefix for the output filename (e.g. "benchmark-details") */
    prefix: string;
    /** Directory to write report files into */
    outputDir: string;
    /** ClickHouse target info. If omitted, reads from MOOSE_CLICKHOUSE_CONFIG__* env vars. */
    target?: TestReportTarget;
}
declare function createTestReporter(options: TestReporterOptions): {
    results: TestReport;
    flush: () => Promise<string>;
};

export { type BenchmarkResult, type ExplainResult, type ProfileResult, type TableStats, type TestReport, type TestReportTarget, type TestReporterOptions, createTestReporter, explain, percentile, profileBenchmark, profileQuery, resolveProfiles, tableStats };
