-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tech: update amp flow to use update instead of delete all
- Loading branch information
1 parent
d8ac43d
commit cef4c59
Showing
6 changed files
with
334 additions
and
231 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
import pandas as pd | ||
from prefect import task | ||
import prefect | ||
|
||
|
||
@task(checkpoint=False) | ||
def update_required(ids_to_update: set) -> bool: | ||
logger = prefect.context.get("logger") | ||
n = len(ids_to_update) | ||
if n > 0: | ||
logger.info(f"Found {n} row(s) to update.") | ||
res = True | ||
else: | ||
logger.info("No row update was found.") | ||
res = False | ||
return res | ||
|
||
@task(checkpoint=False) | ||
def merge_hashes( | ||
local_hashes: pd.DataFrame, remote_hashes: pd.DataFrame, how: str = "outer" | ||
) -> pd.DataFrame: | ||
return pd.merge(local_hashes, remote_hashes, on="id", how=how) | ||
|
||
@task(checkpoint=False) | ||
def select_ids_to_update(hashes: pd.DataFrame) -> set: | ||
ids_to_update = set( | ||
hashes.loc[ | ||
(hashes.cacem_row_hash.notnull()) | ||
& (hashes.cacem_row_hash != hashes.monitorenv_row_hash), | ||
"id", | ||
] | ||
) | ||
|
||
return ids_to_update | ||
|
||
@task(checkpoint=False) | ||
def select_ids_to_delete(hashes: pd.DataFrame) -> set: | ||
return set(hashes.loc[hashes.cacem_row_hash.isna(), "id"]) | ||
|
||
@task(checkpoint=False) | ||
def select_ids_to_insert(hashes: pd.DataFrame) -> set: | ||
return set(hashes.loc[hashes.monitorenv_row_hash.isna(), "id"]) | ||
|
||
@task(checkpoint=False) | ||
def insert_required(ids_to_insert: set) -> bool: | ||
logger = prefect.context.get("logger") | ||
n = len(ids_to_insert) | ||
if n > 0: | ||
logger.info(f"Found {n} row(s) to add.") | ||
res = True | ||
else: | ||
logger.info("No row to add was found.") | ||
res = False | ||
return res | ||
|
||
@prefect.task(checkpoint=False) | ||
def delete_required(ids_to_delete: set) -> bool: | ||
logger = prefect.context.get("logger") | ||
n = len(ids_to_delete) | ||
if n > 0: | ||
logger.info(f"Found {n} row(s) to delete.") | ||
res = True | ||
else: | ||
logger.info("No row to delete was found.") | ||
res = False | ||
return res |
Oops, something went wrong.