@@ -228,7 +228,7 @@ def run(
228228 ),
229229 base_url : str = BIOMARK_BASE_URL ,
230230):
231- """Biomark PIT registering salmon data synchronization ."""
231+ """Download PIT data from BioMark's API to a .duckdb file ."""
232232
233233 # validate that either place or all_locations is specified
234234 if not all_locations and not place :
@@ -283,7 +283,11 @@ def replicate(
283283 access_key : str = BIOMARK_ACCESS_KEY ,
284284 secret_key : str = BIOMARK_SECRET_KEY ,
285285 region : str = BIOMARK_REGION ,
286+ tags : bool = typer .Option (False , help = "Add tags data to S3" ),
287+ readers : bool = typer .Option (False , help = "Add readers voltage data to S3" ),
288+ environment : bool = typer .Option (False , help = "Add environment data to S3" ),
286289):
290+ """Upload data from .duckdb to S3 bucket."""
287291 os .environ ["NINAS3" ] = f"{{type: s3, bucket: { bucket } , use_environment: true }}"
288292 os .environ ["AWS_ACCESS_KEY_ID" ] = access_key
289293 os .environ ["AWS_SECRET_ACCESS_KEY" ] = secret_key
@@ -293,20 +297,24 @@ def replicate(
293297 "{type: duckdb, instance: biomark_pit_registering_salmon_v1.duckdb}"
294298 )
295299
296- Replication (
297- source = "DUCKDB" ,
298- target = "NINAS3" ,
299- defaults = {
300- "object" : "tables/{stream_name}/{part_year}/{part_month}/{part_day}" ,
301- "mode" : "incremental" ,
302- "target_options" : {"format" : "parquet" },
303- },
304- streams = {
305- "readers_voltage__" + location : {
300+ # Validate that at least one data type is selected
301+ if not any ([readers , tags , environment ]):
302+ typer .echo (
303+ "Error: At least one data type must be selected "
304+ "(--readers, --tags, or --environment)"
305+ )
306+ raise typer .Exit (1 )
307+
308+ # Build streams dictionary by merging all selected data types
309+ streams = {}
310+
311+ if readers :
312+ reader_streams = {
313+ f"readers_voltage__{ location } " : {
306314 "primary_key" : ["read_at" ],
307315 "update_key" : "read_at" ,
308316 "object" : (
309- f"test /readers_voltage/location={ location } /"
317+ f"tables /readers_voltage/location={ location } /"
310318 f"{{part_year}}/{{part_month}}/{{part_day}}"
311319 ),
312320 "mode" : "incremental" ,
@@ -319,7 +327,67 @@ def replicate(
319327 "sql_parameters" : [location ],
320328 }
321329 for location in SITES .values ()
330+ }
331+ streams .update (reader_streams )
332+ typer .echo (f"Added { len (reader_streams )} reader voltage streams" )
333+
334+ if tags :
335+ tag_streams = {
336+ f"tags__{ location } " : {
337+ "primary_key" : ["detected_at" ],
338+ "update_key" : "detected_at" ,
339+ "object" : (
340+ f"tables/tags/location={ location } /"
341+ f"{{part_year}}/{{part_month}}/{{part_day}}"
342+ ),
343+ "mode" : "incremental" ,
344+ "target_options" : {"format" : "parquet" },
345+ "sql" : (
346+ "select * replace (detected_at at time zone 'UTC' as detected_at) "
347+ "from tags where reader__site__slug = ? "
348+ "and {incremental_where_cond}"
349+ ),
350+ "sql_parameters" : [location ],
351+ }
352+ for location in SITES .values ()
353+ }
354+ streams .update (tag_streams )
355+ typer .echo (f"Added { len (tag_streams )} tag streams" )
356+
357+ if environment :
358+ env_streams = {
359+ f"environment__{ location } " : {
360+ "primary_key" : ["read_at" ],
361+ "update_key" : "read_at" ,
362+ "object" : (
363+ f"tables/environment/location={ location } /"
364+ f"{{part_year}}/{{part_month}}/{{part_day}}"
365+ ),
366+ "mode" : "incremental" ,
367+ "target_options" : {"format" : "parquet" },
368+ "sql" : (
369+ "select * replace (read_at at time zone 'UTC' as read_at) "
370+ "from environment where reader__site__slug = ? "
371+ "and {incremental_where_cond}"
372+ ),
373+ "sql_parameters" : [location ],
374+ }
375+ for location in SITES .values ()
376+ }
377+ streams .update (env_streams )
378+ typer .echo (f"Added { len (env_streams )} environment streams" )
379+
380+ typer .echo (f"Total streams to replicate: { len (streams )} " )
381+
382+ Replication (
383+ source = "DUCKDB" ,
384+ target = "NINAS3" ,
385+ defaults = {
386+ "object" : "tables/{stream_name}/{part_year}/{part_month}/{part_day}" ,
387+ "mode" : "incremental" ,
388+ "target_options" : {"format" : "parquet" },
322389 },
390+ streams = streams ,
323391 env = {"SLING_STATE" : "NINAS3/data/sling" , "SLING_DIRECT_INSERT" : "True" },
324392 debug = True ,
325393 ).run ()
0 commit comments