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

未关闭
#2,588 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@DG47 已经在做这个了。

开始于 2026年11月10日。

  • #2589 来自 @DG47 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, spark, sql
领域
backend, databases

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Java
星标
153
派生
186
平均合并
2 天 19 小时
30 天内合并 PR
19

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OHDSI/WebAPI 的其他 Issue

查看 OHDSI/WebAPI 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。