Skip to content

Commit

Permalink
Merge branch 'main' into add_encoding_arg_to_copy_s3_func
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunagm authored May 23, 2024
2 parents d58a0a4 + 3536c44 commit db22cac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions parsons/google/google_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,10 @@ def get_row_count(self, schema: str, table_name: str) -> int:
"""
Gets the row count for a BigQuery materialization.
Caution: This method uses SELECT COUNT(*) which can be expensive for large tables,
especially those with many columns. This is because BigQuery scans all table data
to perform the count, even though only the row count is returned.
`Args`:
schema: str
The schema name
Expand Down
25 changes: 21 additions & 4 deletions parsons/mobilecommons/mobilecommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,18 @@ def _mc_get_request(
response_dict = self._parse_get_request(endpoint=endpoint, params=page_params)
# Check to see if page was empty if num parameter is available
if page_indicator == "num":
empty_page = int(response_dict["response"][first_data_key]["num"]) > 0
empty_page = int(response_dict["response"][first_data_key]["num"]) == 0

if not empty_page:
# Extract data
response_table = Table(response_dict["response"][first_data_key][second_data_key])
response_data = response_dict["response"][first_data_key][second_data_key]
# When only one row of data it is returned as dict instead of list, which
# cannot be put into table
if isinstance(response_data, dict):
response_data = [response_data]

response_table = Table(response_data)

# Append to final table
final_table.concat(response_table)
final_table.materialize()
Expand Down Expand Up @@ -347,6 +354,9 @@ def get_profiles(
custom_cols = "true" if include_custom_columns else "false"
subscriptions = "true" if include_subscriptions else "false"

if phones:
phones = ",".join(phones)

params = {
"phone_number": phones,
"from": _format_date(first_date),
Expand Down Expand Up @@ -376,9 +386,10 @@ def create_profile(
city=None,
state=None,
opt_in_path_id=None,
custom_column_values=None,
):
"""
A function for creating a single MobileCommons profile
A function for creating or updating a single MobileCommons profile
`Args:`
phone: str
Expand All @@ -400,9 +411,12 @@ def create_profile(
opt_in_path_id: str
ID of the opt-in path to send new profile through. This will determine the welcome
text they receive.
custom_column_values: dict
Dictionary with custom column names as keys and custom column values
as dictionary values
`Returns:`
ID of created profile
ID of created/updated profile
"""

params = {
Expand All @@ -418,5 +432,8 @@ def create_profile(
**self.default_params,
}

if custom_column_values:
params = params.merge(custom_column_values)

response = self._mc_post_request("profile_update", params=params)
return response["profile"]["id"]

0 comments on commit db22cac

Please sign in to comment.