import { type DbtRawModelNode, type SupportedDbtAdapter } from '../types/dbt';
import { type CompiledExploreJoin, type CompiledTable, type Explore, type ExploreJoin, type Table } from '../types/explore';
import { type CompiledCustomDimension, type CompiledCustomSqlDimension, type CompiledDimension, type CompiledMetric, type CompiledMetricRelativeDateFilter, type CompiledMetricTimestampFilter, type CustomDimension, type CustomSqlDimension, type Dimension, type Metric } from '../types/field';
import { type LightdashProjectConfig } from '../types/lightdashProjectConfig';
import { type PreAggregateDef } from '../types/preAggregate';
import { type DateGranularity } from '../types/timeFrames';
import { type WarehouseSqlBuilder } from '../types/warehouse';
export declare const lightdashVariablePattern: RegExp;
type Reference = {
    refTable: string;
    refName: string;
};
/**
 * Check if the SQL contains any aggregation functions.
 *
 * This is used to determine if a non-aggregate metric with dimension references
 * should be allowed. It's common to define metrics as type:number
 * with aggregation functions in the SQL field. These are valid in Lightdash
 * because the aggregation happens in the SQL itself.
 *
 * @param sql - The SQL expression to check
 * @returns True if the SQL contains aggregation functions, false otherwise
 */
export declare const sqlContainsAggregation: (sql: string | undefined | null) => boolean;
/**
 * Check if any of the given ${} references appear inside an SQL aggregation
 * function call. This is used to distinguish:
 * - `sum(${max_value})` — ref IS inside aggregation (nested aggregate)
 * - `sum(raw_col) / ${count_records}` — ref is NOT inside aggregation
 *
 * Uses a simple parenthesis-depth approach: track aggregation function
 * positions and check if references fall within their parentheses.
 */
export declare const sqlAggregationWrapsReferences: (sql: string, refNames: string[]) => boolean;
type FieldContext = {
    fieldType: 'metric' | 'dimension' | 'custom_dimension' | 'join' | 'sql_where';
    fieldName: string;
};
export declare const getParsedReference: (ref: string, currentTable: string) => Reference;
export declare const getAllReferences: (raw: string) => string[];
export declare const getTableColumnReferences: (raw: string) => string[];
export declare const parseAllReferences: (raw: string, currentTable: string) => Reference[];
export type UncompiledExplore = {
    name: string;
    label: string;
    tags: string[];
    baseTable: string;
    /** @deprecated Use groups instead */
    groupLabel?: string;
    groups?: string[];
    joinedTables: ExploreJoin[];
    tables: Record<string, Table>;
    targetDatabase: SupportedDbtAdapter;
    sqlWhere?: string;
    warehouse?: string;
    ymlPath?: string;
    sqlPath?: string;
    joinAliases?: Record<string, Record<string, string>>;
    spotlightConfig?: LightdashProjectConfig['spotlight'];
    aiHint?: string | string[];
    meta: DbtRawModelNode['meta'];
    databricksCompute?: string;
    projectParameters?: LightdashProjectConfig['parameters'];
    preAggregates?: PreAggregateDef[];
    caseSensitive?: boolean;
    projectDefaults?: LightdashProjectConfig['defaults'];
};
/**
 * Options for the ExploreCompiler.
 */
export type ExploreCompilerOptions = {
    /**
     * When enabled, fields that fail to compile will be marked with a
     * compilationError instead of causing the entire explore to fail.
     * This allows users to still access other fields in the explore.
     */
    allowPartialCompilation?: boolean;
};
export declare class ExploreCompiler {
    private readonly warehouseClient;
    private readonly options;
    constructor(warehouseClient: WarehouseSqlBuilder, options?: ExploreCompilerOptions);
    compileExplore({ name, label, tags, baseTable, joinedTables, tables, targetDatabase, groupLabel, groups, warehouse, ymlPath, sqlPath, spotlightConfig, meta, databricksCompute, aiHint, projectParameters, preAggregates, caseSensitive, projectDefaults, }: UncompiledExplore): Explore;
    /**
     * Creates a dimension with a compilation error marker.
     * Used when partial compilation is enabled and a dimension fails to compile.
     */
    private static createDimensionWithError;
    /**
     * Creates a metric with a compilation error marker.
     * Used when partial compilation is enabled and a metric fails to compile.
     */
    private static createMetricWithError;
    compileTable(table: Table, tables: Record<string, Table>, availableParameters: string[]): CompiledTable;
    private static expandShowUnderlyingValueSets;
    compileMetric(metric: Metric, tables: Record<string, Table>, availableParameters: string[]): CompiledMetric;
    compileMetricSql(metric: Metric, tables: Record<string, Table>, availableParameters: string[]): {
        sql: string;
        tablesReferences: Set<string>;
        valueSql?: string;
        compiledDistinctKeys?: string[];
        compiledRelativeDateFilters?: CompiledMetricRelativeDateFilter[];
        compiledTimestampFilters?: CompiledMetricTimestampFilter[];
    };
    compileDimension(dimension: Dimension, tables: Record<string, Table>, availableParameters: string[]): CompiledDimension;
    compileDimensionSql(dimension: Dimension, tables: Record<string, Table>): {
        sql: string;
        tablesReferences: Set<string>;
    };
    compileCustomDimensionSql(dimension: CustomSqlDimension, tables: Record<string, Table>, availableParameters: string[]): Pick<CompiledCustomSqlDimension, 'compiledSql' | 'tablesReferences' | 'parameterReferences'>;
    compileCustomDimension(customDimension: CustomDimension, tables: Record<string, Table>, availableParameters: string[]): CompiledCustomDimension;
    compileDimensionReference(ref: string, tables: Record<string, Table>, currentTable: string, fieldContext?: FieldContext): {
        sql: string;
        tablesReferences: Set<string>;
    };
    compileMetricReference(ref: string, tables: Record<string, Table>, currentTable: string, availableParameters: string[], fieldContext?: FieldContext): {
        sql: string;
        tablesReferences: Set<string>;
        compiledRelativeDateFilters?: CompiledMetricRelativeDateFilter[];
        compiledTimestampFilters?: CompiledMetricTimestampFilter[];
    };
    compileExploreJoinSql(join: Pick<ExploreJoin, 'sqlOn' | 'table'>, tables: Record<string, Table>): {
        sql: string;
        tablesReferences: Set<string>;
    };
    compileJoin(join: ExploreJoin, tables: Record<string, Table>, availableParameters: string[]): CompiledExploreJoin;
}
export declare const createDimensionWithGranularity: (dimensionName: string, baseTimeDimension: CompiledDimension, explore: Explore, warehouseSqlBuilder: WarehouseSqlBuilder, granularity: DateGranularity, availableParameters: string[]) => CompiledDimension;
export {};
//# sourceMappingURL=exploreCompiler.d.ts.map