본문 바로가기
공부/프로그래밍

[airflow] BigQueryOperator 사용할때 location 에러

by demonic_ 2021. 1. 4.
반응형

다음에러가 떴을 경우.

...

'errors': [{'reason': 'notFound', 'message': 'Not found: Dataset [프로젝트명]:`[dateset이름] was not found in location US'}]

...

 

내 경우 데이터셋을 서울리전(asia-northeast3) 에 저장하게 했는데, 기본값은 US여서 문제가 발생한줄 알고 찾았다. BigQueryOperator의 파라미터중 location이 있길래 옵션으로 다음처럼 넣어봤는데도 동일한 에러가 났다.

checker = BigQueryOperator(
    dag=dag
    , task_id='bq_check_exist_table'
    , sql=sql
    , location='asia-northeast3'
)

 

첫번째 실험은 location만 지정하는 거였다. 그런데 위와 동일한 에러가 발생했다.

 

그래서 인터넷에 보니 location과 destination_dataset_table을 직접 지정하여 하는 경우도 있었다.

이사람은 도쿄리전에 하는거였는데 그의 테스트에 따르면 location과 destination_dataset_table을 같이 설정하면 되더라는 말이다.

This operator has destination_dataset_table so I tested the following four patterns. I suppose it works as expected.
(OK) source dataset in US, destination_dataset in US, no location specified
(OK) source dataset in Tokyo, destination_dataset in Tokyo, location specified as asia-northeast1
(Fail) source dataset in Tokyo, destination_dataset in US, location specified as asia-northeast1
(Fail) source dataset in US, destination_dataset in Tokyo, no location specified

https://github.com/apache/airflow/pull/4324

 

[AIRFLOW-3327] Add support for location in BigQueryHook by kaxil · Pull Request #4324 · apache/airflow

Make sure you have checked all steps below. Jira My PR addresses the following Airflow Jira issues and references them in the PR title. For example, "[AIRFLOW-XXX] My Airflow PR" https...

github.com

 

하지만 그래도 안되었다.....

다음과 같은 에러가 발생

checker = BigQueryOperator(
    dag=dag
    , task_id='bq_check_exist_table'
    , sql=sql
    , location='asia-northeast3
    , destination_dataset_table='[데이터셋].[테이블명]'
)
'errors': [{'reason': 'notFound', 'message': 'Not found: Dataset [프로젝트 ID]:`[데이터셋 명] was not found in location asia-northeast3'}], 'state': 'DONE'}}

 

아까와 에러가 달라졌다. 리전은 제대로 들어간거 같았는데 왜 인식은 못할까?

 

문제점을 정리해보면

1) location만 넣었을 때는 US로 인식한다.

2) localtion과 destination_dataset_table을 함께 넣으면 위치는 잘 잡지만 데이터셋을 검색하지 못한다.

 

그래서 이번에는 location과 destination_dataset_table을 제거하고 sql쪽을 수정하기로 했다.

 

조회하려는 SQL문은 다음과 같았다

sql = """
    select count(1) as cnt 
    from `[데이터셋].[테이블명]` 
""";

 

내 경우 프로젝트 이름에 하이픈이 들어가서 콘솔에서 조회할때 앞뒤로 ``를 넣는다. 그 버릇이 있어 그대로 넣었었는데 혹시나 해서 이걸 제거해보고 실행해봤다. 그랬더니 된다.

sql = """
    select count(1) as cnt 
    from [데이터셋].[테이블명]
"""

checker = BigQueryOperator(
    dag=dag
    , task_id='bq_check_exist_table'
    , sql=sql
)

 

즉 에러문구대로 `를 포함한 테이블명을 조회해서 발생한 문제였다.

 

location은 특별히 지정하지 않는 한 자동으로 찾아 검색하는듯 보인다.

 

 

 

반응형

댓글