@@ -117,6 +117,24 @@ function create_forecast_df(results::NamedTuple, output_type::PipelineOutput)
117117 return forecast_df
118118end
119119
120+ function _quote_duckdb_string (value:: AbstractString )
121+ return " '" * replace (value, " '" => " ''" ) * " '"
122+ end
123+
124+ function _write_parquet_with_duckdb (path:: AbstractString , table)
125+ con = DBInterface. connect (DuckDB. DB, " :memory:" )
126+ return try
127+ DuckDB. register_data_frame (con, table, " forecast_samples" )
128+ DBInterface. execute (
129+ con,
130+ " COPY forecast_samples TO $(_quote_duckdb_string (path)) (FORMAT parquet)"
131+ )
132+ finally
133+ DBInterface. close (con)
134+ end
135+ end
136+
137+
120138"""
121139 create_forecast_output(input, results, output_dir, output_type; kwargs...) -> DataFrame
122140
@@ -219,7 +237,7 @@ function create_forecast_output(
219237 Dict (
220238 " observed" => " observed_ed_visits" ,
221239 " other" => " other_ed_visits" ,
222- " pct" => " prop_disease_ed_visits" ,
240+ " pct" => " prop_disease_ed_visits"
223241 )[input. ed_visit_type]
224242 end
225243
@@ -236,21 +254,11 @@ function create_forecast_output(
236254 forecast_df[! , :geo_value ] .= input. location
237255 forecast_df[! , :disease ] .= input. pathogen
238256
239- # Add metadata columns for hubverse compatibility
240- forecast_df[! , :geo_value ] .= input. location
241- forecast_df[! , :disease ] .= input. pathogen
242-
243- # Convert date column to string for parquet compatibility
244- # Julia parquet does not support writing Dates
245- forecast_df[! , :date ] = string .(forecast_df[! , :date ])
246-
247257 # Save as parquet if requested
248258 if save_output
249- # Use model-specific naming with frequency prefix
250- # This matches the convention: {frequency}_{model}_samples_{target_letter}.parquet
251- parquet_path = joinpath (output_dir, " samples_raw.parquet" )
259+ parquet_path = joinpath (output_dir, " samples.parquet" )
252260 mkpath (dirname (parquet_path))
253- Parquet . write_parquet (parquet_path, forecast_df)
261+ _write_parquet_with_duckdb (parquet_path, forecast_df)
254262
255263 @info " Saved pipeline forecast samples to $parquet_path "
256264 end
0 commit comments