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(ingest): handle 'fields' list missing in bigquery-usage #2844

Merged
merged 2 commits into from
Jul 9, 2021
Merged
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 @@ -120,7 +120,7 @@ class ReadEvent:

resource: BigQueryTableRef
fieldsRead: List[str]
readReason: str
readReason: Optional[str]
jobName: Optional[str]

payload: Any
Expand All @@ -143,8 +143,8 @@ def from_entry(cls, entry: AuditLogEntry) -> "ReadEvent":
resourceName = entry.payload["resourceName"]
readInfo = entry.payload["metadata"]["tableDataRead"]

fields = readInfo["fields"]
readReason = readInfo["reason"]
fields = readInfo.get("fields", [])
readReason = readInfo.get("reason")
jobName = None
if readReason == "JOB":
jobName = readInfo["jobName"]
Expand Down Expand Up @@ -284,7 +284,7 @@ def _parse_bigquery_log_entries(
self, entries: Iterable[AuditLogEntry]
) -> Iterable[Union[ReadEvent, QueryEvent]]:
for entry in entries:
event: Union[ReadEvent, QueryEvent]
event: Union[None, ReadEvent, QueryEvent] = None
if ReadEvent.can_parse_entry(entry):
hsheth2 marked this conversation as resolved.
Show resolved Hide resolved
event = ReadEvent.from_entry(entry)
elif QueryEvent.can_parse_entry(entry):
Expand All @@ -294,7 +294,8 @@ def _parse_bigquery_log_entries(
f"{entry.log_name}-{entry.insert_id}",
f"unable to parse log entry: {entry!r}",
)
yield event
if event:
yield event

def _join_events_by_job_id(
self, events: Iterable[Union[ReadEvent, QueryEvent]]
Expand Down