/** * Query Parser * * Parses and validates warehouse queries, building an abstract syntax tree (AST) * for execution planning. */ import { IWarehouseQuery, IDataSource, IJoinClause, IUnifiedWhereClause, IOrderBy } from '../types'; import { DataSourceRegistry } from '../registry'; /** * Parsed query AST */ export interface IQueryAST { /** Operation type */ operation: 'select' | 'insert' | 'update' | 'delete' | 'upsert'; /** Primary data source */ primarySource: IParsedDataSource; /** Parsed field selections */ fields?: IParsedField[]; /** Parsed joins */ joins?: IParsedJoin[]; /** Parsed where clause */ where?: IParsedWhere; /** Parsed aggregations */ aggregations?: IParsedAggregation[]; /** Group by fields */ groupBy?: string[]; /** Having clause */ having?: IParsedWhere; /** Order by */ orderBy?: IOrderBy[]; /** Limit */ limit?: number; /** Offset */ offset?: number; /** Data for writes */ data?: Record | Record[]; /** Return results */ returning?: boolean | string[]; /** Transaction info */ hasTransaction: boolean; /** All source aliases used in the query */ aliases: Map; /** All field references */ fieldReferences: Set; } /** * Parsed data source */ export interface IParsedDataSource { /** Original data source */ original: IDataSource; /** Resolved alias (generated if not provided) */ alias: string; /** Environment (from registry) */ env?: string; /** Product (from registry) */ product?: string; } /** * Parsed field selection */ export interface IParsedField { /** Full field path (e.g., "u.name") */ path: string; /** Source alias */ sourceAlias?: string; /** Field name within source */ fieldName: string; /** Output alias */ outputAlias?: string; /** Is wildcard (*) */ isWildcard: boolean; } /** * Parsed join */ export interface IParsedJoin { /** Original join clause */ original: IJoinClause; /** Parsed source */ source: IParsedDataSource; /** Join type */ type: 'inner' | 'left' | 'right' | 'full' | 'cross' | 'semantic' | 'graph'; /** Parsed join condition fields */ leftFields?: string[]; rightFields?: string[]; /** Dependencies on other sources */ dependsOn: string[]; } /** * Parsed where clause */ export interface IParsedWhere { /** Original where clause */ original: IUnifiedWhereClause; /** Fields referenced */ referencedFields: string[]; /** Sources referenced */ referencedSources: string[]; /** Has vector operators */ hasVectorOps: boolean; /** Has graph operators */ hasGraphOps: boolean; /** Can be pushed down to source */ canPushDown: boolean; } /** * Parsed aggregation */ export interface IParsedAggregation { /** Aggregate function */ function: 'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct'; /** Field to aggregate */ field: string; /** Source alias (if field is qualified) */ sourceAlias?: string; /** Output alias */ outputAlias: string; } /** * Query validation error */ export declare class QueryValidationError extends Error { readonly errors: string[]; readonly query?: IWarehouseQuery; constructor(message: string, errors: string[], query?: IWarehouseQuery); } /** * Query Parser * * Validates and parses warehouse queries into an AST for execution. */ export declare class QueryParser { private readonly registry?; private aliasCounter; constructor(registry?: DataSourceRegistry); /** * Parse a warehouse query into an AST */ parse(query: IWarehouseQuery): IQueryAST; /** * Validate a warehouse query */ validate(query: IWarehouseQuery): string[]; /** * Validate a data source */ private validateDataSource; /** * Parse a data source */ private parseDataSource; /** * Parse a join clause */ private parseJoin; /** * Parse field selections */ private parseFields; /** * Parse a field string */ private parseFieldString; /** * Parse a field mapping */ private parseFieldMapping; /** * Parse where clause */ private parseWhere; /** * Parse aggregation */ private parseAggregation; /** * Generate an alias for a data source */ private generateAlias; }