Skip to content

Commit

Permalink
Merge pull request #119 from nrccua/DS-466-add-stage_table-argument-t…
Browse files Browse the repository at this point in the history
…o-merge_spark_df_in_db

Add stage_table optional argument to merge_spark_df_in_db ds.utils func
  • Loading branch information
nrccua-timr authored Dec 14, 2023
2 parents 896f4c6 + 6e27602 commit b7718ac
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ History
=======


v0.20.6 (2023-12-14)

* Add stage_table optional argument to merge_spark_df_in_db ds.utils function.
* Update aioboto3==12.1.0.
* Update boto3==1.33.1.
* Update botocore==1.33.1.


v0.20.5 (2023-12-08)

* Add function ese_db_catalog in ds_utils.
Expand Down
8 changes: 4 additions & 4 deletions aioradio/ds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def does_db_table_exists(name):
return exists


def merge_spark_df_in_db(df, target, on, partition_by=None):
def merge_spark_df_in_db(df, target, on, partition_by=None, stage_table=None):
"""Convert spark DF to staging table than merge with target table in
Databricks."""

stage = f"{target}_stage"
stage = f"{target}_stage" if stage_table is None else stage_table

if not does_db_table_exists(target):
if partition_by is None:
Expand All @@ -123,11 +123,11 @@ def merge_spark_df_in_db(df, target, on, partition_by=None):
raise


def merge_pandas_df_in_db(df, target, on, partition_by=None):
def merge_pandas_df_in_db(df, target, on, partition_by=None, stage_table=None):
"""Convert pandas DF to staging table than merge with target table in
Databricks."""

stage = f"{target}_stage"
stage = f"{target}_stage" if stage_table is None else stage_table

for col, dtype in df.dtypes.apply(lambda x: x.name).to_dict().items():
if dtype == 'object':
Expand Down
12 changes: 6 additions & 6 deletions aioradio/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
aioboto3==11.3.1
aioboto3==12.1.0
aiojobs==1.2.1
backoff==2.2.1
boto3==1.28.17
botocore==1.31.17
boto3==1.33.1
botocore==1.33.1
cython==3.0.6
ddtrace==1.11.2
dominodatalab==1.2.4
Expand All @@ -18,15 +18,15 @@ openpyxl==3.0.10
orjson==3.8.10
pandas==2.1.4
polars==0.19.19
pre-commit==3.5.0
pre-commit==3.6.0
psycopg2-binary==2.9.9
pyarrow==14.0.1
pylint==3.0.2
pylint==3.0.3
pyodbc==4.0.39 --no-binary=pyodbc
pysmb==1.2.9.1
pyspark==3.4.1
pytest==7.4.3
pytest-asyncio==0.23.2
pytest-asyncio==0.21.1
pytest-cov==4.1.0
python-json-logger==2.0.7
redis==5.0.1
Expand Down
15 changes: 10 additions & 5 deletions aioradio/tests/dynamodb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import pytest
from boto3.dynamodb.conditions import Attr, Key

from aioradio.aws.dynamodb import (add_regions, batch_get_items_from_dynamo,
batch_write_to_dynamo,
get_list_of_dynamo_tables,
put_item_in_dynamo, query_dynamo,
scan_dynamo, update_item_in_dynamo)
from aioradio.aws.dynamodb import (
add_regions,
batch_get_items_from_dynamo,
batch_write_to_dynamo,
get_list_of_dynamo_tables,
put_item_in_dynamo,
query_dynamo,
scan_dynamo,
update_item_in_dynamo
)

# ****************************************
# DO NOT CHANGE THE DB_TABLE OR REGION
Expand Down
9 changes: 7 additions & 2 deletions aioradio/tests/sqs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import orjson
import pytest

from aioradio.aws.sqs import (add_regions, delete_messages, get_messages,
purge_messages, send_messages)
from aioradio.aws.sqs import (
add_regions,
delete_messages,
get_messages,
purge_messages,
send_messages
)

QUEUE = 'pytest'
REGION = 'us-east-2'
Expand Down
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import aioboto3
import aiobotocore
import boto3
import pytest
import pytest_asyncio
from aiobotocore.config import AioConfig
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = fileobj.read()

setup(name='aioradio',
version='0.20.5',
version='0.20.6',
description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more',
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -21,11 +21,11 @@
],
install_requires=[
'cython>=0.29.33',
'aioboto3==11.3.1',
'aioboto3==12.1.0',
'aiojobs>=1.0.0',
'backoff>=2.1.2',
'botocore==1.31.17',
'boto3==1.28.17',
'botocore==1.33.1',
'boto3==1.33.1',
'ddtrace>=0.60.1',
'faust-cchardet>=2.1.18',
'fakeredis>=2.20.0',
Expand Down

0 comments on commit b7718ac

Please sign in to comment.