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

Add scripts extract and transform the #120

Closed
wants to merge 8 commits into from

Conversation

GeekAngus
Copy link
Collaborator

Types of changes

  • New feature

Description

Background: Start from 2022, we extract the KKTIX data via KKTIX API and load to "pycontw-225217.ods.ods_kktix_attendeeId_datetime". However most of the data are store in the ATTENDEE_INFO column with json format. To use metabase with SQL, users need to extract the data by json_extract with the knowledge kktix format instead of flat database. And we also need to rewrite all the SQLs build for current databases.
Solution: Transform the tables in backend that we could keep the same user experience by using Metabase.

Checklist:

  • Add test cases to all the changes you introduce
  • Run poetry run pytest locally to ensure all linter checks pass
  • Update the documentation if necessary

Steps to Test This Pull Request

./kktix_bq_etl.py 2023

Expected behavior

The data had been load to ods_kktix_ticket_${ticket_type}_attendees_test on bigquery
ticket_type = corporate individual reserved

"ods_kktix_attendeeId_datetime" table and load to the legecy tables:
: ods_kktix_ticket_(corporate, individual, reserved)_attendees
Comment on lines 22 to 27
1. Background: Start from 2022, we extract the KKTIX data via KKTIX API and load to "pycontw-225217.ods.ods_kktix_attendeeId_datetime". However most of the data are store in the ATTENDEE_INFO column with json format. To use metabase with SQL, users need to extract the data by json_extract with the knowledge kktix format instead of flat database. And we also need to rewrite all the SQLs build for current databases.
2. Solution: Transform the tables in backend that we could keep the same user experience by using Metabase.
3. Run:
- `./kktix_bq_etl.py -t ods_kktix_ticket_reserved_attendees_test -k reserved -y 2023 --upload`
- for 3 tables: `./kktix_bq_etl.py 2023`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for documenting these up 🙏

Comment on lines 54 to 76
CANONICAL_COLUMN_NAMES_2020_EXTRA_CORPORATE = {
"invoice_policy",
"invoiced_company_name",
"unified_business_no",
"pynight_attendee_numbers",
"know_financial_aid",
"have_you_ever_attended_pycon_tw",
"pynight_attending_or_not",
"how_did_you_know_pycon_tw",
}

CANONICAL_COLUMN_NAMES_2020_EXTRA_INDIVIDUAL = {
"pynight_attendee_numbers",
"know_financial_aid",
"have_you_ever_attended_pycon_tw",
"pynight_attending_or_not",
"how_did_you_know_pycon_tw",
}

CANONICAL_COLUMN_NAMES_2020_EXTRA_RESERVED: Set = set()


CANONICAL_COLUMN_NAMES_2019_CORE = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to me that these canonical_xxx sets are unused?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the main code is from upload-kktix-ticket-csv-to-bigquery.py and I jus keep them, the set was used for unit test.



HEURISTIC_COMPATIBLE_MAPPING_TABLE = {
# from 2020 reformatted column names
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for writting these comments 🙏

"ive_already_read_and_i_accept_the_epidemic_prevention_of_pycon_tw_2020_pycon_tw_2020_covid19": "ive_already_read_and_i_accept_the_epidemic_prevention_of_pycon_tw",
"do_you_know_we_have_financial_aid_this_year": "know_financial_aid",
"contact_email": "email",
# from 2020 reformatted column names which made it duplicate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 519 to 521
# print(df.columns)
sanitized_df = sanitize_column_names(df)
hash_privacy_info(sanitized_df)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for remembering hashing these sensitive columns. However, we've already encrypted data on extract side. so no need to do it again~

transformed_event_raw_data_array = kktix_transformer.transform(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, could be removed after confirmed.

Comment on lines 499 to 500
df_dict = df_dict.drop(columns = useless_columns)
df_dict = df_dict.rename(columns = {"reg_no": "registration_no", "ticket_name": "ticket_type", "is_paid": "payment_status"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you thiink if we keep all of the original data in the warehouse, and only deserialize/extract those "useful" columns from JSON to another DB layer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should keep all the of the original data that maybe useful someday.

@GeekAngus GeekAngus closed this Aug 12, 2023
@GeekAngus
Copy link
Collaborator Author

Use #123 instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants