-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from GlobalFishingWatch/feature/PIPELINE-2170
Moves view to table cotaining fishing events with restricted list
- Loading branch information
Showing
15 changed files
with
270 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import logging | ||
|
||
|
||
def dest_table_description(**extra_items): | ||
return ( | ||
f"{extra_items['base_table_description']}\n" | ||
f"{extra_items['table_description']}" | ||
) | ||
from pipe_events.utils.bigquery import dest_table_description | ||
|
||
|
||
def run(bq, params): | ||
log = logging.getLogger() | ||
dest = params["destination"] + params['reference_date'] | ||
schema_path = "./assets/bigquery/fishing-events-4-authorization-schema.json" | ||
|
||
bq.create_table( | ||
params["destination"], | ||
schema_file="./assets/bigquery/fishing-events-4-authorization-schema.json", | ||
dest, | ||
schema_file=schema_path, | ||
table_description=dest_table_description(**params), | ||
partition_field="event_end_date", | ||
clustering_fields=["event_end_date", "seg_id", "event_start"], | ||
labels=params["labels"], | ||
) | ||
|
||
log.info("*** 1. Creates the authorized with regions.") | ||
log.info("*** 1. Creates the authorized with regions. Or less restrictive table.") | ||
auth_query = bq.format_query("fishing-events-4-authorization.sql.j2", **params) | ||
bq.run_query( | ||
auth_query, | ||
dest_table=params["destination"], | ||
dest_table=dest, | ||
write_disposition="WRITE_TRUNCATE", | ||
partition_field="event_end_date", | ||
clustering_fields=["event_end_date", "seg_id", "event_start"], | ||
labels=params["labels"], | ||
) | ||
bq.update_table_schema( | ||
dest, | ||
schema_path | ||
) # schema should be kept after trucate | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
from pipe_events.utils.bigquery import dest_table_description | ||
|
||
|
||
def run(bq, params): | ||
log = logging.getLogger() | ||
ref_date = params['reference_date'] | ||
params["source_restrictive_events"] += ref_date | ||
dest = params["dest_restrictive_events"] + ref_date | ||
# schama is the same just with fishing strict list | ||
schema_path = "./assets/bigquery/fishing-events-4-authorization-schema.json" | ||
bq.create_table( | ||
dest, | ||
schema_file=schema_path, | ||
table_description=dest_table_description(**params), | ||
partition_field="event_end_date", | ||
clustering_fields=["event_end_date", "seg_id", "event_start"], | ||
labels=params["labels"], | ||
) | ||
|
||
log.info("*** 1. Creates the restrictive table.") | ||
auth_query = bq.format_query("fishing-events-5-restrictive.sql.j2", **params) | ||
bq.run_query( | ||
auth_query, | ||
dest_table=dest, | ||
write_disposition="WRITE_TRUNCATE", | ||
partition_field="event_end_date", | ||
clustering_fields=["event_end_date", "seg_id", "event_start"], | ||
labels=params["labels"], | ||
) | ||
bq.update_table_schema(dest, schema_path) # schema should be kept after trucate | ||
log.info(f"The table {dest} is ready.") | ||
return True |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.