CDM cache warming issues one record-count query per concept on Snowflake, Spark and BigQuery (getConceptsForBatch.sql relies on integer division)

Đang mở
#2,588 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@DG47 đang làm issue này rồi.

Từ ngày 10/11/2026.

  • #2589 của @DG47 — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, spark, sql
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start with getConceptsForBatch.sql and trace its use from CDMCacheService.warm into cacheRecordsBatch; the issue identifies the integer division expression that causes one group per concept on some platforms. Check how SqlRender handles the query for Snowflake, Spark/Databricks, and BigQuery, then verify warming batches concepts into ranges of 100,000 and reduces the number of getBatchConceptRecordCount queries.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Expected behavior

When the CDM record count cache is warmed for a source (CDMCacheService.warm), getConceptsForBatch.sql should split achilles_result_concept_count into ranges of 100,000 concepts (@batch_size), so that the warming job runs a handful of getBatchConceptRecordCount queries per source regardless of the database platform.

Actual behavior

The range id is computed as

select concept_id, ordinal / @batch_size as group_id
FROM (select concept_id, row_number() over (order by concept_id) as ordinal
      FROM @resultTableQualifier.achilles_result_concept_count c) Q

and the outer query groups by group_id. This only yields whole ranges where / on two integers is integer division (PostgreSQL, SQL Server, Redshift). SqlRender does not rewrite the expression for any dialect, so:

  • Snowflake: ordinal / 100000 is a NUMBER with six decimals (1 / 100000 = 0.000010), distinct for every ordinal.
  • Spark / Databricks: the quotient is a DOUBLE (1.0E-5), distinct for every ordinal.
  • BigQuery: / on INT64 returns FLOAT64, distinct for every ordinal.

So on those platforms every concept is its own group, the query returns one min_concept = max_concept row per concept, and cacheRecordsBatch runs one getBatchConceptRecordCount query per row of achilles_result_concept_count (typically several hundred thousand round trips). The warming job for such a source takes hours to days instead of minutes and in practice never completes.

Steps to reproduce behavior
  1. Configure a Snowflake, Databricks/Spark or BigQuery source with a results daimon whose schema contains achilles_result_concept_count (for example 300,000 rows) and is_cache_enabled = true.
  2. Start WebAPI (or call GET /cdmresults/clearCache to trigger warming) and watch the query history on the database.
  3. Observe select group_id, min(concept_id) ..., max(concept_id) ... group by group_id returning as many rows as the table has concepts, followed by one select cc.concept_id, record_count, descendant_record_count ... WHERE cc.concept_id >= ? and cc.concept_id <= ? per concept.

Directly on the platform:

-- Snowflake
select 1 / 100000;      -- 0.000010
-- Spark
select 1 / 100000;      -- 1.0E-5
-- BigQuery
select 1 / 100000;      -- 1.0E-5
-- PostgreSQL / SQL Server
select 1 / 100000;      -- 0
Environment
  • WebAPI master @ 89de588 (also present in 2.15.x; the query dates from the Data Sources caching work in #1993)
  • SqlRender 1.19.1
Ngôn ngữ chính
Java
Star
153
Fork
186
Merge trung bình
2 ngày 19 giờ
Pull request đã merge (30 ngày)
19

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của OHDSI/WebAPI

Tất cả issue của OHDSI/WebAPI

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.