From 7e14387288957ea14dd8b4a4140040ec069db5fd Mon Sep 17 00:00:00 2001 From: Marc Suchard Date: Tue, 5 Nov 2024 12:01:11 -0800 Subject: [PATCH 1/2] attempt to patch count(*) overflow --- R/AggregateCovariates.R | 2 +- inst/settings/resultsDataModelSpecification.csv | 2 +- inst/sql/sql_server/ResultTables.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/AggregateCovariates.R b/R/AggregateCovariates.R index 8a3c220..6292b1d 100644 --- a/R/AggregateCovariates.R +++ b/R/AggregateCovariates.R @@ -260,7 +260,7 @@ computeTargetAggregateCovariateAnalyses <- function( message("Extracting target cohort counts") sql <- "select cohort_definition_id, - count(*) row_count, + count_big(*) row_count, count(distinct subject_id) person_count, min(datediff(day, cohort_start_date, cohort_end_date)) min_exposure_time, avg(datediff(day, cohort_start_date, cohort_end_date)) mean_exposure_time, diff --git a/inst/settings/resultsDataModelSpecification.csv b/inst/settings/resultsDataModelSpecification.csv index 3dc0e59..ecd5d9e 100644 --- a/inst/settings/resultsDataModelSpecification.csv +++ b/inst/settings/resultsDataModelSpecification.csv @@ -113,7 +113,7 @@ cohort_counts,start_anchor,varchar(15),No,No,No,No,The start anchor cohort_counts,end_anchor,varchar(15),No,No,No,No,The end anchor cohort_counts,min_prior_observation,int,No,No,No,No,Minimum time observed before index cohort_counts,outcome_washout_days,int,No,No,No,No,Patients with outcome during washout are excluded -cohort_counts,row_count,int,Yes,No,No,No,The number of rows in each cohort +cohort_counts,row_count,bigint,Yes,No,No,No,The number of rows in each cohort cohort_counts,person_count,int,Yes,No,No,No,The number of distinct people in each cohort cohort_counts,min_exposure_time,bigint,No,No,No,No,Minimum exposure time across cohort cohort_counts,mean_exposure_time,bigint,No,No,No,No,Mean exposure time across cohort diff --git a/inst/sql/sql_server/ResultTables.sql b/inst/sql/sql_server/ResultTables.sql index edb85e2..5012558 100644 --- a/inst/sql/sql_server/ResultTables.sql +++ b/inst/sql/sql_server/ResultTables.sql @@ -155,7 +155,7 @@ CREATE TABLE @my_schema.@table_prefixcohort_counts( end_anchor varchar(15), min_prior_observation int, outcome_washout_days int, - row_count int NOT NULL, + row_count bigint NOT NULL, person_count int NOT NULL, min_exposure_time int, mean_exposure_time int, From 5c30f7404bfb3b285b515bd7275f5c59387a3fac Mon Sep 17 00:00:00 2001 From: Anthony Sena Date: Tue, 5 Nov 2024 16:12:18 -0500 Subject: [PATCH 2/2] Add migration instead of changing ResultTables.sql directly --- inst/sql/sql_server/ResultTables.sql | 2 +- .../migrations/Migration_2-v2_0_2_row_count_bigint.sql | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 inst/sql/sql_server/migrations/Migration_2-v2_0_2_row_count_bigint.sql diff --git a/inst/sql/sql_server/ResultTables.sql b/inst/sql/sql_server/ResultTables.sql index 5012558..edb85e2 100644 --- a/inst/sql/sql_server/ResultTables.sql +++ b/inst/sql/sql_server/ResultTables.sql @@ -155,7 +155,7 @@ CREATE TABLE @my_schema.@table_prefixcohort_counts( end_anchor varchar(15), min_prior_observation int, outcome_washout_days int, - row_count bigint NOT NULL, + row_count int NOT NULL, person_count int NOT NULL, min_exposure_time int, mean_exposure_time int, diff --git a/inst/sql/sql_server/migrations/Migration_2-v2_0_2_row_count_bigint.sql b/inst/sql/sql_server/migrations/Migration_2-v2_0_2_row_count_bigint.sql new file mode 100644 index 0000000..5d6f626 --- /dev/null +++ b/inst/sql/sql_server/migrations/Migration_2-v2_0_2_row_count_bigint.sql @@ -0,0 +1,5 @@ +-- Database migrations for verion 2.0.2 +-- This migration updates the schema: + -- 1. To expand the row_count column to a bigint + +ALTER TABLE @database_schema.@table_prefixcohort_counts ALTER COLUMN row_count BIGINT;