Skip to content

Commit

Permalink
fix(bigquery): resolve deprecation warnings for StructType and `Sch…
Browse files Browse the repository at this point in the history
…ema`
  • Loading branch information
kszucs authored and cpcloud committed Jan 24, 2023
1 parent 318179a commit c9e7078
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
12 changes: 3 additions & 9 deletions ibis/backends/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,16 @@ def _fully_qualified_name(self, name, database):
def _get_schema_using_query(self, query):
job_config = bq.QueryJobConfig(dry_run=True, use_query_cache=False)
job = self.client.query(query, job_config=job_config)
names, ibis_types = self._adapt_types(job.schema)
return sch.Schema(names, ibis_types)
fields = self._adapt_types(job.schema)
return sch.Schema(fields)

def _get_table_schema(self, qualified_name):
dataset, table = qualified_name.rsplit(".", 1)
assert dataset is not None, "dataset is None"
return self.get_schema(table, database=dataset)

def _adapt_types(self, descr):
names = []
adapted_types = []
for col in descr:
names.append(col.name)
typename = bigquery_field_to_ibis_dtype(col)
adapted_types.append(typename)
return names, adapted_types
return {col.name: bigquery_field_to_ibis_dtype(col) for col in descr}

def _execute(self, stmt, results=True, query_parameters=None):
job_config = bq.job.QueryJobConfig()
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def bigquery_param(dtype, value, name):

@bigquery_param.register
def bq_param_struct(dtype: dt.Struct, value, name):
fields = dtype.pairs
fields = dtype.fields
field_params = [bigquery_param(fields[k], v, k) for k, v in value.items()]
result = bq.StructQueryParameter(name, *field_params)
return result
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/bigquery/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def trans_struct(t):
return "STRUCT<{}>".format(
", ".join(
f"{name} {ibis_type_to_bigquery_type(dt.dtype(type_))}"
for name, type_ in zip(t.names, t.types)
for name, type_ in t.fields.items()
)
)

Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/bigquery/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _(typ: dt.Struct) -> Mapping[str, Any]:
return {
"field_type": "RECORD",
"mode": "NULLABLE" if typ.nullable else "REQUIRED",
"fields": ibis_schema_to_bq_schema(ibis.schema(typ.pairs)),
"fields": ibis_schema_to_bq_schema(ibis.schema(typ.fields)),
}


Expand Down

0 comments on commit c9e7078

Please sign in to comment.