집계 엔진
GitLab Aggregation Framework를 사용하여 PostgreSQL 및 ClickHouse 백엔드에서 분석 쿼리를 구축하는 집계 엔진의 정의, 구성 요소, 사용 방법 및 GraphQL 통합을 설명합니다.
Aggregation Framework는 서로 다른 데이터베이스 백엔드에서 분석 쿼리를 구축하기 위한 통합 인터페이스를 제공합니다. PostgreSQL(ActiveRecord를 통해)과 ClickHouse를 모두 지원하며, 개발자가 메트릭, 차원, 필터를 포함한 재사용 가능한 집계 엔진을 정의할 수 있습니다. ActiveRecord 엔진 정의 # ActiveRecord 엔진( Gitlab::Database::Aggregation::ActiveRecord::Engine )은 ActiveRecord의 쿼리 인터페이스를 사용하여 PostgreSQL 쿼리를 생성합니다. ActiveRecord 엔진 예시 # class IssueAggregationEngine < Gitlab::Database::Aggregation::ActiveRecord::Engine filters do exact_match :project_id, :integer, description: 'Filter by project ID' exact_match :state, :string, description: 'Filter by issue state' end dimensions do column :author_id, :integer, description: 'Group by author' date_bucket :created_at, :datetime, parameters: { granularity: { in: %i[daily weekly monthly yearly], type: :string } }, description: 'Group by creation date' end metrics do count description: 'Total number of issues' mean :weight, :float, description: 'Average issue weight' end end ActiveRecord 엔진은 단일 레벨 SQL 쿼리를 생성합니다: SELECT "issues"."author_id" AS aeq_author_id, date_trunc('month', "issues"."created_at") AS aeq_created_at, COUNT(*) AS aeq_total_count, AVG("issues"."weight") AS aeq_mean_weight FROM "issues" WHERE "issues"."project_id" IN (1, 2, 3) AND "issues"."state" IN ('opened') GROUP BY aeq_author_id, aeq_created_at ORDER BY aeq_author_id, aeq_created_at 주요 특성: 모든 칼럼은 aeq_ 접두사(Aggregation Engine Query)가 붙습니다. 이 접두사는 AggregationResult 객체에 의해 제거됩니다. 필터는 WHERE 또는 HAVING 절로 적용됩니다. 차원은 GROUP BY 칼럼이 됩니다. 메트릭은 집계 함수( COUNT , AVG )를 사용합니