Builds SQL queries using modular fragments
| 41 | |
| 42 | |
| 43 | class QueryBuilder: |
| 44 | """Builds SQL queries using modular fragments""" |
| 45 | |
| 46 | # Columns that require specific data sources |
| 47 | COLUMN_SOURCE_MAP = { |
| 48 | # Syscall latency columns |
| 49 | 'sc.min_lat_us': 'syscend', |
| 50 | 'sc.avg_lat_us': 'syscend', |
| 51 | 'sc.max_lat_us': 'syscend', |
| 52 | 'sc.p50_us': 'syscend', |
| 53 | 'sc.p95_us': 'syscend', |
| 54 | 'sc.p99_us': 'syscend', |
| 55 | 'sc.p999_us': 'syscend', |
| 56 | 'sclat_histogram': 'syscend', |
| 57 | |
| 58 | # I/O latency columns |
| 59 | 'io.min_lat_us': 'iorqend', |
| 60 | 'io.avg_lat_us': 'iorqend', |
| 61 | 'io.max_lat_us': 'iorqend', |
| 62 | 'io.p50_us': 'iorqend', |
| 63 | 'io.p95_us': 'iorqend', |
| 64 | 'io.p99_us': 'iorqend', |
| 65 | 'io.p999_us': 'iorqend', |
| 66 | 'iolat_histogram': 'iorqend', |
| 67 | 'iorq_flags': 'iorqend', |
| 68 | 'io.iorq_flags': 'iorqend', |
| 69 | |
| 70 | # Device columns |
| 71 | 'devname': 'partitions', |
| 72 | 'devname': 'partitions', |
| 73 | |
| 74 | # Stack columns |
| 75 | 'kstack_hash': 'kstacks', |
| 76 | 'kstack_syms': 'kstacks', |
| 77 | 'kstack_current_func': 'kstacks', |
| 78 | |
| 79 | 'ustack_hash': 'ustacks', |
| 80 | 'ustack_syms': 'ustacks', |
| 81 | 'ustack_current_func': 'ustacks', |
| 82 | } |
| 83 | |
| 84 | # Computed columns that are always available in enriched_samples |
| 85 | COMPUTED_COLUMNS = [ |
| 86 | 'filenamesum', 'fext', 'comm2', 'connection', |
| 87 | 'connection2', 'connectionsumlocal', 'connectionsumpeer', 'connectionsumboth' |
| 88 | ] |
| 89 | |
| 90 | def __init__(self, datadir: Path, fragments_path: Path, |
| 91 | use_materialized: bool = False): |
| 92 | """ |
| 93 | Initialize query builder. |
| 94 | |
| 95 | Args: |
| 96 | datadir: Path to data directory |
| 97 | fragments_path: Path to SQL fragments directory |
| 98 | use_materialized: If True, use materialized tables instead of CSV |
| 99 | """ |
| 100 | self.datadir = datadir |
no outgoing calls