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 SchemaField description #552

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.5] - 2024-07-30

### Changed
- Fixed get_bq_schema_from_json_schema() SchemaField parameters

## [Unreleased]

### Internal
Expand All @@ -12,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.0.4] - 2023-10-24

## Changed
### Changed
- Upgrade to Pydantic V2

## [1.0.2] - 2023-10-10
Expand Down
8 changes: 4 additions & 4 deletions gbq/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def get_bq_schema_from_json_schema(source: List[Dict]) -> List[SchemaField]:

for key, value in enumerate(source):
schema_field = SchemaField(
str(value.get("name")),
str(value.get("type")),
value.get("mode", "NULLABLE"),
value.get("description", None),
name=str(value.get("name")),
field_type=str(value.get("type")),
mode=value.get("mode", "NULLABLE"),
description=value.get("description", None),
)

# Add the field to the list of fields
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "gbq"
version = "1.0.4"
version = "1.0.5"
description = "Python wrapper for interacting Google BigQuery."
readme = "README.md"
license = {text = "MIT"}
Expand Down
15 changes: 13 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,23 @@ def nested_json_schema():
{"name": "username", "mode": "NULLABLE", "type": "STRING"},
{
"fields": [
{"name": "id", "mode": "NULLABLE", "type": "INTEGER"},
{"name": "street", "mode": "NULLABLE", "type": "STRING"},
{
"name": "id",
"mode": "NULLABLE",
"type": "INTEGER",
"description": "ID DESCRIPTION",
},
{
"name": "street",
"mode": "NULLABLE",
"type": "STRING",
"description": "STREET DESCRIPTION",
},
],
"name": "address",
"mode": "REPEATED",
"type": "RECORD",
"description": "ADDRESS DESCRIPTION",
},
]

Expand Down
8 changes: 5 additions & 3 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def test_get_bq_credentials(mocker):


def test_convert_to_bq_schema(nested_json_schema):
address_schema = SchemaField("address", "RECORD", "REPEATED")
address_schema = SchemaField(
"address", "RECORD", "REPEATED", None, "ADDRESS DESCRIPTION"
)
address_nested_schema = [
SchemaField("id", "INTEGER", "NULLABLE"),
SchemaField("street", "STRING", "NULLABLE"),
SchemaField("id", "INTEGER", "NULLABLE", None, "ID DESCRIPTION"),
SchemaField("street", "STRING", "NULLABLE", None, "STREET DESCRIPTION"),
]
address_schema._fields = address_nested_schema
expected = [
Expand Down