Refactor/analytics#97
Conversation
…dularization) Phase 1 — SQL Dialect Abstraction: - fieldRegistry.ts: single source of truth for event field definitions - sqlDialect.ts: common interface (buildSelect, buildWhere, getTotalCount) - postgresDialect.ts / clickHouseDialect.ts: dialect implementations - queryEvents.ts: unified handler that picks dialect via STORAGE_ADAPTER - Both PG and CH handlers now thin re-exports from common/queryEvents Phase 3 — Data Engine Modularization: - Extract dataQuery module from routes/gRPC/data/query into storage/query/ - Explicit field alias registry with auto-derived cast types from Drizzle metadata - Thin handler in routes/gRPC/data/query delegates to executeDataQuery/getDataTable - hasMore support in DataQueryResult
Greptile SummaryThis PR refactors event querying into backend-specific dialects. The main changes are:
Confidence Score: 4/5Mostly safe to merge once the already-threaded review findings are resolved or confirmed addressed. The current diff shows fixes for several earlier query issues, including tenant scoping, provider and output-cache mapping, metadata serialization, event type predicates, unknown aggregation validation, and ClickHouse pagination. No new distinct verified bug was found in this final pass. The score stays below the maximum because this is core query and auth-adjacent SQL code with backend-specific behavior.
What T-Rex did
Important Files Changed
|
|
yea no way in fuck Im reviewing all that.. LGTM |
This pull request introduces a major refactor to event querying by implementing a dialect-based abstraction for querying event data from both Postgres and ClickHouse backends. The logic for building queries, filtering, and aggregations is now encapsulated in dialect classes, improving modularity and maintainability. The main query handler now delegates to these dialects, and the previous table/field/condition logic is removed from the gRPC route in favor of a unified, backend-agnostic approach.
Event Query Refactor and Dialect Abstraction:
Query Routing and Handler Abstraction
handleQueryEventsthat routes event queries to the appropriate dialect (Postgres or ClickHouse) based on the configured storage adapter, and delegates all query and aggregation logic to the dialect classes. (src/storage/adapter/common/queryEvents.ts)Dialect Implementations
PostgresQueryDialectandClickHouseQueryDialectclasses that encapsulate all logic for building, executing, and aggregating queries against their respective databases, including SQL generation, field mapping, and result normalization. (src/storage/adapter/common/postgresDialect.ts,src/storage/adapter/common/clickHouseDialect.ts)QueryDialectinterface specifying the methods required for dialects, ensuring consistent usage and easier extensibility. (src/storage/adapter/common/sqlDialect.ts)Query Route Refactor
queryDataroute to remove all table/field/condition logic, and instead delegate query execution to a newexecuteDataQueryandgetDataTableabstraction, aligning with the new dialect-based approach. (src/routes/gRPC/data/query.ts)This refactor centralizes and standardizes event querying, making it easier to support multiple backends and reducing duplicate query logic across the codebase.