-
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
test: refactor list_rows
tests and add test for scalars
#829
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5704f1e
test: refactor `list_rows` tests and add test for scalars
tswast ac88b92
Merge branch 'master' into issue826-list_rows-tests
tswast 8c17f98
Merge branch 'master' into issue826-list_rows-tests
tswast fbebd5d
Merge branch 'master' into issue826-list_rows-tests
tswast 4040794
fix JSON formatting
tswast 0bef8ba
Merge remote-tracking branch 'upstream/master' into issue826-list_row…
tswast 9e94db5
add TODO for INTERVAL Arrow support
tswast 6000852
format tests
tswast 017787d
Merge remote-tracking branch 'origin/issue826-list_rows-tests' into i…
tswast 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
{"bool_col": true, "bytes_col": "abcd", "date_col": "2021-07-21", "datetime_col": "2021-07-21 11:39:45", "geography_col": "POINT(-122.0838511 37.3860517)", "int64_col": "123456789", "numeric_col": "1.23456789", "bignumeric_col": "10.111213141516171819", "float64_col": "1.25", "string_col": "Hello, World", "time_col": "11:41:43.07616", "timestamp_col": "2021-07-21T17:43:43.945289Z"} | ||
{"bool_col": null, "bytes_col": null, "date_col": null, "datetime_col": null, "geography_col": null, "int64_col": null, "numeric_col": null, "bignumeric_col": null, "float64_col": null, "string_col": null, "time_col": null, "timestamp_col": null} | ||
{"bool_col": true, "bytes_col": "SGVsbG8sIFdvcmxkIQ==", "date_col": "2021-07-21", "datetime_col": "2021-07-21 11:39:45", "geography_col": "POINT(-122.0838511 37.3860517)", "int64_col": "123456789", "interval_col": "P7Y11M9DT4H15M37.123456S", "numeric_col": "1.23456789", "bignumeric_col": "10.111213141516171819", "float64_col": "1.25", "rowindex": 0, "string_col": "Hello, World!", "time_col": "11:41:43.07616", "timestamp_col": "2021-07-21T17:43:43.945289Z"} | ||
{"bool_col": null, "bytes_col": null, "date_col": null, "datetime_col": null, "geography_col": null, "int64_col": null, "interval_col": null, "numeric_col": null, "bignumeric_col": null, "float64_col": null, "rowindex": 1, "string_col": null, "time_col": null, "timestamp_col": null} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{"bool_col": true, "bytes_col": "DQo=\n", "date_col": "9999-12-31", "datetime_col": "9999-12-31 23:59:59.999999", "geography_col": "POINT(-135.0000 90.0000)", "int64_col": "9223372036854775807", "numeric_col": "9.9999999999999999999999999999999999999E+28", "bignumeric_col": "9.999999999999999999999999999999999999999999999999999999999999999999999999999E+37", "float64_col": "+inf", "string_col": "Hello, World", "time_col": "23:59:59.99999", "timestamp_col": "9999-12-31T23:59:59.999999Z"} | ||
{"bool_col": false, "bytes_col": "8J+Zgw==\n", "date_col": "0001-01-01", "datetime_col": "0001-01-01 00:00:00", "geography_col": "POINT(45.0000 -90.0000)", "int64_col": "-9223372036854775808", "numeric_col": "-9.9999999999999999999999999999999999999E+28", "bignumeric_col": "-9.999999999999999999999999999999999999999999999999999999999999999999999999999E+37", "float64_col": "-inf", "string_col": "Hello, World", "time_col": "00:00:00", "timestamp_col": "0001-01-01T00:00:00.000000Z"} | ||
{"bool_col": true, "bytes_col": "AA==\n", "date_col": "1900-01-01", "datetime_col": "1900-01-01 00:00:00", "geography_col": "POINT(-180.0000 0.0000)", "int64_col": "-1", "numeric_col": "0.000000001", "bignumeric_col": "-0.00000000000000000000000000000000000001", "float64_col": "nan", "string_col": "こんにちは", "time_col": "00:00:00.000001", "timestamp_col": "1900-01-01T00:00:00.000000Z"} | ||
{"bool_col": false, "bytes_col": "", "date_col": "1970-01-01", "datetime_col": "1970-01-01 00:00:00", "geography_col": "POINT(0 0)", "int64_col": "0", "numeric_col": "0.0", "bignumeric_col": "0.0", "float64_col": 0.0, "string_col": "", "time_col": "12:00:00", "timestamp_col": "1970-01-01T00:00:00.000000Z"} | ||
{"bool_col": null, "bytes_col": null, "date_col": null, "datetime_col": null, "geography_col": null, "int64_col": null, "numeric_col": null, "bignumeric_col": null, "float64_col": null, "string_col": null, "time_col": null, "timestamp_col": null} | ||
{"bool_col": true, "bytes_col": "DQo=\n", "date_col": "9999-12-31", "datetime_col": "9999-12-31 23:59:59.999999", "geography_col": "POINT(-135.0000 90.0000)", "int64_col": "9223372036854775807", "interval_col": "P-10000Y0M-3660000DT-87840000H0M0S", "numeric_col": "9.9999999999999999999999999999999999999E+28", "bignumeric_col": "9.999999999999999999999999999999999999999999999999999999999999999999999999999E+37", "float64_col": "+inf", "rowindex": 0, "string_col": "Hello, World", "time_col": "23:59:59.999999", "timestamp_col": "9999-12-31T23:59:59.999999Z"} | ||
{"bool_col": false, "bytes_col": "8J+Zgw==\n", "date_col": "0001-01-01", "datetime_col": "0001-01-01 00:00:00", "geography_col": "POINT(45.0000 -90.0000)", "int64_col": "-9223372036854775808", "interval_col": "P10000Y0M3660000DT87840000H0M0S", "numeric_col": "-9.9999999999999999999999999999999999999E+28", "bignumeric_col": "-9.999999999999999999999999999999999999999999999999999999999999999999999999999E+37", "float64_col": "-inf", "rowindex": 1, "string_col": "Hello, World", "time_col": "00:00:00", "timestamp_col": "0001-01-01T00:00:00.000000Z"} | ||
{"bool_col": true, "bytes_col": "AA==\n", "date_col": "1900-01-01", "datetime_col": "1900-01-01 00:00:00", "geography_col": "POINT(-180.0000 0.0000)", "int64_col": "-1", "interval_col": "P0Y0M0DT0H0M0.000001S", "numeric_col": "0.000000001", "bignumeric_col": "-0.00000000000000000000000000000000000001", "float64_col": "nan", "rowindex": 2, "string_col": "こんにちは", "time_col": "00:00:00.000001", "timestamp_col": "1900-01-01T00:00:00.000000Z"} | ||
{"bool_col": false, "bytes_col": "", "date_col": "1970-01-01", "datetime_col": "1970-01-01 00:00:00", "geography_col": "POINT(0 0)", "int64_col": "0", "interval_col": "P0Y0M0DT0H0M0S", "numeric_col": "0.0", "bignumeric_col": "0.0", "float64_col": 0.0, "rowindex": 3, "string_col": "", "time_col": "12:00:00", "timestamp_col": "1970-01-01T00:00:00.000000Z"} | ||
{"bool_col": null, "bytes_col": null, "date_col": null, "datetime_col": null, "geography_col": null, "int64_col": null, "interval_col": null, "numeric_col": null, "bignumeric_col": null, "float64_col": null, "rowindex": 4, "string_col": null, "time_col": null, "timestamp_col": null} |
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
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import datetime | ||
import decimal | ||
|
||
from google.cloud import bigquery | ||
from google.cloud.bigquery import enums | ||
|
||
|
||
def test_list_rows_empty_table(bigquery_client: bigquery.Client, table_id: str): | ||
from google.cloud.bigquery.table import RowIterator | ||
|
||
table = bigquery_client.create_table(table_id) | ||
|
||
# It's a bit silly to list rows for an empty table, but this does | ||
# happen as the result of a DDL query from an IPython magic command. | ||
rows = bigquery_client.list_rows(table) | ||
assert isinstance(rows, RowIterator) | ||
assert tuple(rows) == () | ||
|
||
|
||
def test_list_rows_page_size(bigquery_client: bigquery.Client, table_id: str): | ||
num_items = 7 | ||
page_size = 3 | ||
num_pages, num_last_page = divmod(num_items, page_size) | ||
|
||
to_insert = [{"string_col": "item%d" % i, "rowindex": i} for i in range(num_items)] | ||
bigquery_client.load_table_from_json(to_insert, table_id).result() | ||
|
||
df = bigquery_client.list_rows( | ||
table_id, | ||
selected_fields=[bigquery.SchemaField("string_col", enums.SqlTypeNames.STRING)], | ||
page_size=page_size, | ||
) | ||
pages = df.pages | ||
|
||
for i in range(num_pages): | ||
page = next(pages) | ||
assert page.num_items == page_size | ||
page = next(pages) | ||
assert page.num_items == num_last_page | ||
|
||
|
||
def test_list_rows_scalars(bigquery_client: bigquery.Client, scalars_table: str): | ||
rows = list( | ||
sorted( | ||
bigquery_client.list_rows(scalars_table), key=lambda row: row["rowindex"] | ||
) | ||
) | ||
plamut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
row = rows[0] | ||
assert row["bool_col"] # True | ||
assert row["bytes_col"] == b"Hello, World!" | ||
assert row["date_col"] == datetime.date(2021, 7, 21) | ||
assert row["datetime_col"] == datetime.datetime(2021, 7, 21, 11, 39, 45) | ||
assert row["geography_col"] == "POINT(-122.0838511 37.3860517)" | ||
assert row["int64_col"] == 123456789 | ||
assert row["numeric_col"] == decimal.Decimal("1.23456789") | ||
assert row["bignumeric_col"] == decimal.Decimal("10.111213141516171819") | ||
assert row["float64_col"] == 1.25 | ||
assert row["string_col"] == "Hello, World!" | ||
assert row["time_col"] == datetime.time(11, 41, 43, 76160) | ||
assert row["timestamp_col"] == datetime.datetime( | ||
2021, 7, 21, 17, 43, 43, 945289, tzinfo=datetime.timezone.utc | ||
) | ||
|
||
nullrow = rows[1] | ||
for column, value in nullrow.items(): | ||
if column == "rowindex": | ||
assert value == 1 | ||
else: | ||
assert value is None | ||
|
||
|
||
def test_list_rows_scalars_extreme( | ||
bigquery_client: bigquery.Client, scalars_extreme_table: str | ||
): | ||
rows = list( | ||
sorted( | ||
bigquery_client.list_rows(scalars_extreme_table), | ||
key=lambda row: row["rowindex"], | ||
) | ||
) | ||
plamut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
row = rows[0] | ||
assert row["bool_col"] # True | ||
assert row["bytes_col"] == b"\r\n" | ||
assert row["date_col"] == datetime.date(9999, 12, 31) | ||
assert row["datetime_col"] == datetime.datetime(9999, 12, 31, 23, 59, 59, 999999) | ||
assert row["geography_col"] == "POINT(-135 90)" | ||
assert row["int64_col"] == 9223372036854775807 | ||
assert row["numeric_col"] == decimal.Decimal( | ||
"9.9999999999999999999999999999999999999E+28" | ||
) | ||
assert row["bignumeric_col"] == decimal.Decimal( | ||
"9.999999999999999999999999999999999999999999999999999999999999999999999999999E+37" | ||
plamut marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
assert row["float64_col"] == float("Inf") | ||
assert row["string_col"] == "Hello, World" | ||
assert row["time_col"] == datetime.time(23, 59, 59, 999999) | ||
assert row["timestamp_col"] == datetime.datetime( | ||
9999, 12, 31, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc | ||
) | ||
|
||
nullrow = rows[4] | ||
for column, value in nullrow.items(): | ||
if column == "rowindex": | ||
assert value == 4 | ||
else: | ||
assert value is None |
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.
Good catch of a missing nine digit in timestamp's microseconds. 👍