Skip to content

Commit

Permalink
Fix bigquery type error when export format is parquet (#16027)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunki-hong committed May 26, 2021
1 parent faf4caf commit 8676885
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions airflow/providers/google/cloud/transfers/sql_to_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import json
import warnings
from tempfile import NamedTemporaryFile
from typing import Optional, Sequence, Union
from typing import Dict, Optional, Sequence, Union

import pyarrow as pa
import pyarrow.parquet as pq
Expand Down Expand Up @@ -278,7 +278,8 @@ def _convert_parquet_schema(self, cursor):
}

columns = [field[0] for field in cursor.description]
bq_types = [self.field_to_bigquery(field) for field in cursor.description]
bq_fields = [self.field_to_bigquery(field) for field in cursor.description]
bq_types = [bq_field.get('type') if bq_field is not None else None for bq_field in bq_fields]
pq_types = [type_map.get(bq_type, pa.string()) for bq_type in bq_types]
parquet_schema = pa.schema(zip(columns, pq_types))
return parquet_schema
Expand All @@ -288,7 +289,7 @@ def query(self):
"""Execute DBAPI query."""

@abc.abstractmethod
def field_to_bigquery(self, field):
def field_to_bigquery(self, field) -> Dict[str, str]:
"""Convert a DBAPI field to BigQuery schema format."""

@abc.abstractmethod
Expand Down
9 changes: 7 additions & 2 deletions tests/providers/google/cloud/transfers/test_sql_to_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import json
import unittest
from typing import Dict
from unittest import mock
from unittest.mock import MagicMock, Mock

Expand Down Expand Up @@ -62,8 +63,12 @@


class DummySQLToGCSOperator(BaseSQLToGCSOperator):
def field_to_bigquery(self, field):
pass
def field_to_bigquery(self, field) -> Dict[str, str]:
return {
'name': field[0],
'type': 'STRING',
'mode': 'NULLABLE',
}

def convert_type(self, value, schema_type):
return 'convert_type_return_value'
Expand Down

0 comments on commit 8676885

Please sign in to comment.