-
Notifications
You must be signed in to change notification settings - Fork 309
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: support empty array in _from_api_repr_struct #2010
Open
TommyDew42
wants to merge
4
commits into
googleapis:main
Choose a base branch
from
TommyDew42:issue-2009
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,8 +169,10 @@ def test_from_api_repr(self): | |
self.assertEqual(field._type, "STRING") | ||
|
||
def test_to_api_repr(self): | ||
from google.cloud.bigquery.query import ScalarQueryParameterType | ||
from google.cloud.bigquery.query import StructQueryParameterType | ||
from google.cloud.bigquery.query import ( | ||
ScalarQueryParameterType, | ||
StructQueryParameterType, | ||
) | ||
|
||
array_item_type = StructQueryParameterType( | ||
ScalarQueryParameterType("INTEGER", name="weight", description="in kg"), | ||
|
@@ -223,8 +225,10 @@ def test_raises_error_without_any_fields(self): | |
self._make_one() | ||
|
||
def test_from_api_repr(self): | ||
from google.cloud.bigquery.query import ArrayQueryParameterType | ||
from google.cloud.bigquery.query import ScalarQueryParameterType | ||
from google.cloud.bigquery.query import ( | ||
ArrayQueryParameterType, | ||
ScalarQueryParameterType, | ||
) | ||
|
||
api_resource = { | ||
"type": "STRUCT", | ||
|
@@ -1299,8 +1303,46 @@ def test_from_api_repr_w_none_values(self): | |
self.assertEqual(param.array_type, "INT64") | ||
self.assertEqual(param.values, [1, None]) | ||
|
||
def test_from_api_repr_w_struct_type(self): | ||
from google.cloud.bigquery.query import StructQueryParameter | ||
def test_from_api_repr_w_empty_struct_array(self): | ||
from google.cloud.bigquery.query import ( | ||
ScalarQueryParameterType, | ||
StructQueryParameterType, | ||
) | ||
|
||
RESOURCE = { | ||
"parameterType": { | ||
"type": "ARRAY", | ||
"arrayType": { | ||
"type": "STRUCT", | ||
"structTypes": [ | ||
{"name": "name", "type": {"type": "STRING"}}, | ||
{"name": "age", "type": {"type": "INT64"}}, | ||
], | ||
}, | ||
}, | ||
"parameterValue": {"arrayValues": []}, | ||
} | ||
|
||
klass = self._get_target_class() | ||
param = klass.from_api_repr(RESOURCE) | ||
|
||
self.assertEqual( | ||
str(param.array_type), | ||
str( | ||
StructQueryParameterType( | ||
ScalarQueryParameterType("STRING", name="name"), | ||
ScalarQueryParameterType("INT64", name="age"), | ||
) | ||
), | ||
) | ||
self.assertEqual(param.values, []) | ||
|
||
def test_from_api_repr_w_nonempty_struct_array(self): | ||
from google.cloud.bigquery.query import ( | ||
ScalarQueryParameterType, | ||
StructQueryParameter, | ||
StructQueryParameterType, | ||
) | ||
|
||
RESOURCE = { | ||
"parameterType": { | ||
|
@@ -1342,7 +1384,16 @@ def test_from_api_repr_w_struct_type(self): | |
_make_subparam("name", "STRING", "Bharney Rhubbyl"), | ||
_make_subparam("age", "INT64", 31), | ||
) | ||
self.assertEqual(param.array_type, "STRUCT") | ||
|
||
self.assertEqual( | ||
str(param.array_type), | ||
str( | ||
StructQueryParameterType( | ||
ScalarQueryParameterType("STRING", name="name"), | ||
ScalarQueryParameterType("INT64", name="age"), | ||
) | ||
), | ||
) | ||
Comment on lines
+1388
to
+1396
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't work to do |
||
self.assertEqual(param.values, [phred, bharney]) | ||
|
||
def test_to_api_repr_w_name(self): | ||
|
@@ -1414,8 +1465,10 @@ def test_to_api_repr_w_record_type(self): | |
self.assertEqual(param.to_api_repr(), EXPECTED) | ||
|
||
def test_to_api_repr_w_empty_array_of_records_type(self): | ||
from google.cloud.bigquery.query import ScalarQueryParameterType | ||
from google.cloud.bigquery.query import StructQueryParameterType | ||
from google.cloud.bigquery.query import ( | ||
ScalarQueryParameterType, | ||
StructQueryParameterType, | ||
) | ||
|
||
EXPECTED = { | ||
"parameterType": { | ||
|
@@ -1497,8 +1550,10 @@ def test___repr__array_type_scalar_type_instance(self): | |
self.assertEqual(repr(int_items), expected) | ||
|
||
def test___repr__array_type_struct_type_instance(self): | ||
from google.cloud.bigquery.query import ScalarQueryParameterType | ||
from google.cloud.bigquery.query import StructQueryParameterType | ||
from google.cloud.bigquery.query import ( | ||
ScalarQueryParameterType, | ||
StructQueryParameterType, | ||
) | ||
|
||
struct_items = self._make_one( | ||
"struct_items", | ||
|
@@ -2054,6 +2109,7 @@ def test_w_scalar(self): | |
|
||
def test_w_scalar_timestamp(self): | ||
from google.cloud._helpers import UTC | ||
|
||
from google.cloud.bigquery.query import ScalarQueryParameter | ||
|
||
RESOURCE = { | ||
|
@@ -2073,6 +2129,7 @@ def test_w_scalar_timestamp(self): | |
|
||
def test_w_scalar_timestamp_micros(self): | ||
from google.cloud._helpers import UTC | ||
|
||
from google.cloud.bigquery.query import ScalarQueryParameter | ||
|
||
RESOURCE = { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do import within each test instead of at the top of the test module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And i believe these import changes are from running
nox -s blacken
andnox -s lint
.