/** * Join Executor * * Executes cross-database joins using various strategies: * - Hash Join: Best for equality joins with one small side * - Nested Loop: Best for small datasets or inequality joins * - Sort-Merge: Best for large pre-sorted datasets */ import { IJoinClause, IJoinResult } from '../../types'; /** * Actual join strategies used for execution */ export type ActualJoinStrategy = 'hash' | 'nested_loop' | 'sort_merge'; /** * Join strategy (including 'auto' for auto-selection) */ export type JoinStrategy = ActualJoinStrategy | 'auto'; /** * Options for join execution */ export interface IJoinOptions { /** Preferred strategy (auto-selects if not specified) */ strategy?: JoinStrategy; /** Maximum memory for hash tables (bytes) */ maxMemory?: number; /** Enable parallel processing */ parallel?: boolean; } /** * Row with source tracking */ export interface IJoinableRow { /** Source alias */ _source: string; /** Original row data */ [key: string]: any; } /** * Join Executor * * Performs in-memory joins between datasets from different sources. */ export declare class JoinExecutor { private readonly defaultMaxMemory; /** * Execute a join between two datasets */ execute>(left: Record[], right: Record[], join: IJoinClause, leftAlias: string, options?: IJoinOptions): IJoinResult; /** * Execute multiple joins in sequence */ executeMultiple>(initial: Record[], initialAlias: string, joins: { data: Record[]; join: IJoinClause; }[], options?: IJoinOptions): IJoinResult; /** * Hash join implementation * * 1. Build hash table from smaller dataset * 2. Probe with larger dataset */ private hashJoin; /** * Nested loop join implementation * * For each row in left, scan all rows in right for matches. * Simple but O(n*m) complexity. */ private nestedLoopJoin; /** * Sort-merge join implementation * * 1. Sort both sides by join key * 2. Merge sorted lists */ private sortMergeJoin; /** * Select the best join strategy based on data characteristics */ private selectStrategy; /** * Get key extractor functions for hash join */ private getKeyExtractors; /** * Get matcher function for join condition */ private getMatcher; /** * Get matcher for single condition */ private getSingleMatcher; /** * Extract field name from path, checking if it matches the alias */ private extractFieldName; /** * Merge two rows into a single result row */ private mergeRows; }