Skip to content

Bugzilla etl refactor #343

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 2 additions & 3 deletions jobs/webcompat-kb/tests/test_bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from webcompat_kb.bugzilla import BugzillaToBigQuery
from webcompat_kb.bugzilla import extract_int_from_field
from webcompat_kb.bugzilla import parse_string_to_json
from webcompat_kb.bugzilla import RELATION_CONFIG, LINK_FIELDS, ETP_RELATION_CONFIG


def to_history(data: list[dict[str, Any]]) -> Mapping[int, list[History]]:
Expand Down Expand Up @@ -999,13 +998,13 @@ def test_extract_int_from_field():
field = extract_int_from_field("P3")
assert field == 3

field = extract_int_from_field("critical")
field = extract_int_from_field("critical", value_map={"critical": 1})
assert field == 1

field = extract_int_from_field("--")
assert field is None

field = extract_int_from_field("N/A")
field = extract_int_from_field("N/A", value_map={"n/a": None})
assert field is None

field = extract_int_from_field("")
Expand Down
19 changes: 19 additions & 0 deletions jobs/webcompat-kb/webcompat_kb/bqhelpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from google.cloud import bigquery


def ensure_table(
client: bigquery.Client, bq_dataset_id: str, table_id: str, recreate: bool
) -> None:
table = bigquery.Table(
f"{client.project}.{bq_dataset_id}.{table_id}",
schema=[
bigquery.SchemaField("number", "INTEGER", mode="REQUIRED"),
bigquery.SchemaField("who", "STRING", mode="REQUIRED"),
bigquery.SchemaField("change_time", "TIMESTAMP", mode="REQUIRED"),
bigquery.SchemaField("score_delta", "FLOAT", mode="REQUIRED"),
bigquery.SchemaField("reasons", "STRING", mode="REPEATED"),
],
)
if recreate:
client.delete_table(table, not_found_ok=True)
client.create_table(table, exists_ok=True)
Loading