All files / server/types analysis.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140                                                                                                                                                                                                                                                                                       
/**
 * Query Analysis Types
 * Provides transparency into query planning decisions for debugging
 */
 
/**
 * Reason why a cube was selected as primary (FROM table)
 */
export type PrimaryCubeSelectionReason =
  | 'most_dimensions'        // Tier 1: Cube with most dimensions in query
  | 'most_connected'         // Tier 2: Most connected cube that can reach all others
  | 'alphabetical_fallback'  // Tier 3: Alphabetical order fallback
  | 'single_cube'            // Only one cube in query
 
/**
 * Candidate cube considered for primary selection
 */
export interface PrimaryCubeCandidate {
  /** Cube name */
  cubeName: string
  /** Number of dimensions from this cube in the query */
  dimensionCount: number
  /** Number of join definitions on this cube */
  joinCount: number
  /** Whether this cube can reach all other required cubes */
  canReachAll: boolean
}
 
/**
 * Primary cube selection analysis
 */
export interface PrimaryCubeAnalysis {
  /** Name of the selected primary cube */
  selectedCube: string
  /** Reason for selection */
  reason: PrimaryCubeSelectionReason
  /** Human-readable explanation */
  explanation: string
  /** Other candidates that were considered */
  candidates?: PrimaryCubeCandidate[]
}
 
/**
 * Single step in a join path
 */
export interface JoinPathStep {
  /** Source cube name */
  fromCube: string
  /** Target cube name */
  toCube: string
  /** Relationship type used */
  relationship: 'belongsTo' | 'hasOne' | 'hasMany' | 'belongsToMany'
  /** SQL join type that will be used */
  joinType: 'inner' | 'left' | 'right' | 'full'
  /** Join condition columns */
  joinColumns: Array<{
    sourceColumn: string
    targetColumn: string
  }>
  /** Junction table info for belongsToMany */
  junctionTable?: {
    tableName: string
    sourceColumns: string[]
    targetColumns: string[]
  }
}
 
/**
 * Complete join path from primary to target cube
 */
export interface JoinPathAnalysis {
  /** Target cube name */
  targetCube: string
  /** Whether a path was found */
  pathFound: boolean
  /** The join steps (if found) */
  path?: JoinPathStep[]
  /** Total path length */
  pathLength?: number
  /** Error message if path not found */
  error?: string
  /** Cubes that were visited during BFS search */
  visitedCubes?: string[]
}
 
/**
 * Pre-aggregation CTE analysis
 */
export interface PreAggregationAnalysis {
  /** Cube being pre-aggregated */
  cubeName: string
  /** CTE alias in the query */
  cteAlias: string
  /** Why this cube needs a CTE */
  reason: string
  /** Measures included in CTE */
  measures: string[]
  /** Join keys used */
  joinKeys: Array<{
    sourceColumn: string
    targetColumn: string
  }>
}
 
/**
 * Query structure summary
 */
export interface QuerySummary {
  /** Query type: 'single_cube', 'multi_cube_join', or 'multi_cube_cte' */
  queryType: 'single_cube' | 'multi_cube_join' | 'multi_cube_cte'
  /** Total number of joins */
  joinCount: number
  /** Total number of CTEs */
  cteCount: number
  /** Has hasMany relationships requiring aggregation */
  hasPreAggregation: boolean
}
 
/**
 * Complete query analysis result
 */
export interface QueryAnalysis {
  /** Timestamp of analysis */
  timestamp: string
  /** Number of cubes involved */
  cubeCount: number
  /** List of all cubes used */
  cubesInvolved: string[]
  /** Primary cube selection details */
  primaryCube: PrimaryCubeAnalysis
  /** Join path analysis for each joined cube */
  joinPaths: JoinPathAnalysis[]
  /** Pre-aggregation CTE details */
  preAggregations: PreAggregationAnalysis[]
  /** Overall query structure summary */
  querySummary: QuerySummary
  /** Warnings or potential issues */
  warnings?: string[]
}