bigquery json 업로드 오류 해결

한빈수윤·2025년 2월 13일

빅쿼리에 json 데이터를 파이썬 코드로 업로드 할 때 스키마 불일치가 생겼다.

400 Error while reading data, error message: JSON table encountered too many errors, giving up.
Rows: 757; errors: 1. Please look into the errors[] collection for more details.
reason: invalid, message: JSON parsing error in row starting at position 1035021: JSON object specified for non-record field: productgroup

이를 해결하기 위한 방법은 생각보다 간단하다.

1) ALLOW_FIELD_ADDITION 옵션추가
BigQuery에서 스키마를 변경할 수 있도록 허용하는 설정을 추가했다.
이 옵션을 사용하면, 기존 테이블에 없는 필드가 추가되더라도 업로드가 가능해진다.

2) ignore_unknown_values=True 추가하기
디폴트 값은 false이지만 임의로 true를 설정해주면 빅쿼리 안에 없는 필드는 무시하고 업로드할 수 있어진다. !

계속 json 파일만 수정하면서 하나하나 번거로웠는데 구글 참고문서에서 찾았다.
이 두개의 코드만 추가해주면 바로 빅쿼리로 올라간다.

참고링크: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.allow_quoted_newlines

profile
할 수 있다 방돌!!!

0개의 댓글