Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Made the changes to fix schema alignment for google_political_ads #895

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"spend_range_max_eur",
"spend_range_max_inr",
"spend_range_max_bgn",
"spend_range_max_hrk",
"spend_range_max_czk",
"spend_range_max_dkk",
"spend_range_max_huf",
Expand All @@ -47,7 +46,6 @@
"spend_inr",
"spend_bgn",
"spend_czk",
"spend_hrk",
"spend_dkk",
"spend_huf",
"spend_pln",
Expand All @@ -62,6 +60,7 @@
"spend_ars",
"spend_zar",
"spend_clp",
"spend_mxn",
]


Expand Down Expand Up @@ -92,13 +91,7 @@ def main(
logging.info(f"Opening file {zip_file}")
df = read_csv_file(zip_file, csv_file)

logging.info(f"Transforming.. {csv_file}")
if "Spend_HRK" not in df.columns:
df["Spend_HRK"] = 0
if "Spend_Range_Max_HRK" not in df.columns:
df["Spend_Range_Max_HRK"] = 0
if "Spend_Range_Min_HRK" not in df.columns:
df["Spend_Range_Min_HRK"] = 0
new_func(csv_file, df)

logging.info(f"Transform: Rename columns for {table_name}..")
rename_headers(df, rename_mappings)
Expand Down Expand Up @@ -128,6 +121,16 @@ def main(
)


def new_func(csv_file, df):
logging.info(f"Transforming.. {csv_file}")
if "Spend_MXN" not in df.columns:
df["Spend_MXN"] = 0
if "Spend_Range_Max_MXN" not in df.columns:
df["Spend_Range_Max_MXN"] = 0
if "Spend_Range_Min_MXN" not in df.columns:
df["Spend_Range_Min_MXN"] = 0


def save_to_new_file(df: pd.DataFrame, file_path: str, table_name: str) -> None:
if table_name != "creative_stats" and "spend_usd" in df:
for column in NUMERIC_COLUMNS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License

---
resources:
Expand Down Expand Up @@ -213,7 +213,6 @@ dag:
"spend_eur",
"spend_inr",
"spend_bgn",
"spend_hrk",
"spend_czk",
"spend_dkk",
"spend_huf",
Expand All @@ -228,7 +227,8 @@ dag:
"spend_brl",
"spend_ars",
"spend_zar",
"spend_clp"
"spend_clp",
"spend_mxn"
]
RENAME_MAPPINGS: >-
{
Expand All @@ -240,7 +240,6 @@ dag:
"Spend_EUR": "spend_eur",
"Spend_INR": "spend_inr",
"Spend_BGN": "spend_bgn",
"Spend_HRK": "spend_hrk",
"Spend_CZK": "spend_czk",
"Spend_DKK": "spend_dkk",
"Spend_HUF": "spend_huf",
Expand All @@ -255,7 +254,8 @@ dag:
"Spend_BRL": "spend_brl",
"Spend_ARS": "spend_ars",
"Spend_ZAR": "spend_zar",
"Spend_CLP": "spend_clp"
"Spend_CLP": "spend_clp",
"Spend_MXN": "spend_mxn"
}
container_resources:
memory:
Expand Down Expand Up @@ -307,10 +307,6 @@ dag:
type: "integer"
description: "Total amount in BGN spent on election ads in this region."
mode: "nullable"
- name: "spend_hrk"
type: "integer"
description: "Total amount in HRK spent on election ads in this region."
mode: "nullable"
- name: "spend_czk"
type: "integer"
description: "Total amount in CZK spent on election ads in this region."
Expand Down Expand Up @@ -371,8 +367,10 @@ dag:
type: "integer"
description: "Total amount in CLP spent on election ads in this region."
mode: "nullable"

# advertiser_stats
- name: "spend_mxn"
type: "integer"
description: "Total amount in MXN spent on election ads in this region."
mode: "nullable"
- operator: "GKEStartPodOperator"
description: "Run CSV transform within kubernetes pod"
args:
Expand Down Expand Up @@ -406,7 +404,6 @@ dag:
"spend_eur",
"spend_inr",
"spend_bgn",
"spend_hrk",
"spend_czk",
"spend_dkk",
"spend_huf",
Expand All @@ -421,7 +418,8 @@ dag:
"spend_brl",
"spend_ars",
"spend_zar",
"spend_clp"
"spend_clp",
"spend_mxn"
]
RENAME_MAPPINGS: >-
{
Expand All @@ -435,7 +433,6 @@ dag:
"Spend_EUR": "spend_eur",
"Spend_INR": "spend_inr",
"Spend_BGN": "spend_bgn",
"Spend_HRK": "spend_hrk",
"Spend_CZK": "spend_czk",
"Spend_DKK": "spend_dkk",
"Spend_HUF": "spend_huf",
Expand All @@ -450,7 +447,8 @@ dag:
"Spend_BRL": "spend_brl",
"Spend_ARS": "spend_ars",
"Spend_ZAR": "spend_zar",
"Spend_CLP": "spend_clp"
"Spend_CLP": "spend_clp",
"Spend_MXN": "spend_mxn"
}
container_resources:
memory:
Expand Down Expand Up @@ -510,10 +508,6 @@ dag:
type: "integer"
description: "Total amount in BGN spent on election ads by the advertiser."
mode: "nullable"
- name: "spend_hrk"
type: "integer"
description: "Total amount in HRK spent on election ads by the advertiser."
mode: "nullable"
- name: "spend_czk"
type: "integer"
description: "Total amount in CZK spent on election ads by the advertiser."
Expand Down Expand Up @@ -574,8 +568,10 @@ dag:
type: "integer"
description: "Total amount in CLP spent on election ads by the advertiser."
mode: "nullable"

# advertiser_weekly_spend
- name: "spend_mxn"
type: "integer"
description: "Total amount in MXN spent on election ads by the advertiser."
mode: "nullable"
- operator: "GKEStartPodOperator"
description: "Run CSV transform within kubernetes pod"
args:
Expand Down Expand Up @@ -607,7 +603,6 @@ dag:
"spend_eur",
"spend_inr",
"spend_bgn",
"spend_hrk",
"spend_czk",
"spend_dkk",
"spend_huf",
Expand All @@ -622,7 +617,8 @@ dag:
"spend_brl",
"spend_ars",
"spend_zar",
"spend_clp"
"spend_clp",
"spend_mxn"
]
RENAME_MAPPINGS: >-
{
Expand All @@ -634,7 +630,6 @@ dag:
"Spend_EUR": "spend_eur",
"Spend_INR": "spend_inr",
"Spend_BGN": "spend_bgn",
"Spend_HRK": "spend_hrk",
"Spend_CZK": "spend_czk",
"Spend_DKK": "spend_dkk",
"Spend_HUF": "spend_huf",
Expand All @@ -649,7 +644,8 @@ dag:
"Spend_BRL": "spend_brl",
"Spend_ARS": "spend_ars",
"Spend_ZAR": "spend_zar",
"Spend_CLP": "spend_clp"
"Spend_CLP": "spend_clp",
"Spend_MXN": "spend_mxn"
}
container_resources:
memory:
Expand Down Expand Up @@ -701,10 +697,6 @@ dag:
type: "integer"
description: "The amount in BGN spent on election ads during the given week by the advertiser."
mode: "nullable"
- name: "spend_hrk"
type: "integer"
description: "The amount in HRK spent on election ads during the given week by the advertiser."
mode: "nullable"
- name: "spend_czk"
type: "integer"
description: "The amount in CZK spent on election ads during the given week by the advertiser."
Expand Down Expand Up @@ -765,7 +757,10 @@ dag:
type: "integer"
description: "The amount in CLP spent on election ads during the given week by the advertiser."
mode: "nullable"

- name: "spend_mxn"
type: "integer"
description: "The amount in MXN spent on election ads during the given week by the advertiser."
mode: "nullable"
- operator: "GKEStartPodOperator"
description: "Run CSV transform within kubernetes pod"
args:
Expand Down Expand Up @@ -922,8 +917,6 @@ dag:
"spend_range_max_inr",
"spend_range_min_bgn",
"spend_range_max_bgn",
"spend_range_min_hrk",
"spend_range_max_hrk",
"spend_range_min_czk",
"spend_range_max_czk",
"spend_range_min_dkk",
Expand Down Expand Up @@ -979,8 +972,6 @@ dag:
"Spend_Range_Max_INR": "spend_range_max_inr",
"Spend_Range_Min_BGN": "spend_range_min_bgn",
"Spend_Range_Max_BGN": "spend_range_max_bgn",
"Spend_Range_Min_HRK": "spend_range_min_hrk",
"Spend_Range_Max_HRK": "spend_range_max_hrk",
"Spend_Range_Min_CZK": "spend_range_min_czk",
"Spend_Range_Max_CZK": "spend_range_max_czk",
"Spend_Range_Min_DKK": "spend_range_min_dkk",
Expand Down Expand Up @@ -1011,14 +1002,14 @@ dag:
"Spend_Range_Max_ZAR": "spend_range_max_zar",
"Spend_Range_Min_CLP": "spend_range_min_clp",
"Spend_Range_Max_CLP": "spend_range_max_clp",
"Spend_Range_Min_MXN": "spend_range_min_mxn",
"Spend_Range_Max_MXN": "spend_range_max_mxn",
"Age_Targeting": "age_targeting",
"Gender_Targeting": "gender_targeting",
"Geo_Targeting_Included": "geo_targeting_included",
"Geo_Targeting_Excluded": "geo_targeting_excluded",
"First_Served_Timestamp": "first_served_timestamp",
"Last_Served_Timestamp": "last_served_timestamp",
"Spend_Range_Min_MXN": "spend_range_min_mxn",
"Spend_Range_Max_MXN": "spend_range_max_mxn",
"Is_Funded_By_Google_Ad_Grants": "is_funded_by_google_ad_grants"
}
container_resources:
Expand Down Expand Up @@ -1277,7 +1268,6 @@ dag:
type: "integer"
description: "Upper bound of the amount in MXN spent by the advertiser on the election ad."
mode: "nullable"

- operator: "GKEStartPodOperator"
description: "Run CSV transform within kubernetes pod"
args:
Expand Down Expand Up @@ -1308,7 +1298,6 @@ dag:
"spend_eur",
"spend_inr",
"spend_bgn",
"spend_hrk",
"spend_czk",
"spend_dkk",
"spend_huf",
Expand All @@ -1323,7 +1312,8 @@ dag:
"spend_brl",
"spend_ars",
"spend_zar",
"spend_clp"
"spend_clp",
"spend_mxn"
]
RENAME_MAPPINGS: >-
{
Expand All @@ -1334,7 +1324,6 @@ dag:
"Spend_EUR": "spend_eur",
"Spend_INR": "spend_inr",
"Spend_BGN": "spend_bgn",
"Spend_HRK": "spend_hrk",
"Spend_CZK": "spend_czk",
"Spend_DKK": "spend_dkk",
"Spend_HUF": "spend_huf",
Expand All @@ -1349,7 +1338,8 @@ dag:
"Spend_BRL": "spend_brl",
"Spend_ARS": "spend_ars",
"Spend_ZAR": "spend_zar",
"Spend_CLP": "spend_clp"
"Spend_CLP": "spend_clp",
"Spend_MXN": "spend_mxn"
}
container_resources:
memory:
Expand Down Expand Up @@ -1396,10 +1386,6 @@ dag:
type: "integer"
description: "Total amount in BGN spent on election ads in this region."
mode: "nullable"
- name: "spend_hrk"
type: "integer"
description: "Total amount in HRK spent on election ads in this region."
mode: "nullable"
- name: "spend_czk"
type: "integer"
description: "Total amount in CZK spent on election ads in this region."
Expand Down Expand Up @@ -1460,7 +1446,10 @@ dag:
type: "integer"
description: "Total amount in CLP spent on election ads in this region."
mode: "nullable"

- name: "spend_mxn"
type: "integer"
description: "Total amount in MXN spent on election ads in this region."
mode: "nullable"
- operator: "GKEStartPodOperator"
description: "Run CSV transform within kubernetes pod"
args:
Expand Down
Loading
Loading