-
Notifications
You must be signed in to change notification settings - Fork 315
feat: add support for INTERVAL data type to list_rows
#840
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5704f1e
test: refactor `list_rows` tests and add test for scalars
tswast 5eb3794
WIP: INTERVAL support
tswast 9e54277
feat: add support for INTERVAL data type to `list_rows`
tswast a89c1c1
Merge remote-tracking branch 'upstream/master' into issue826-interval
tswast 60d9ca7
fix relativedelta construction for non-microseconds
tswast da6ef5b
WIP: support INTERVAL query params
tswast b73a610
remove dead code
tswast 52f2b7b
INTERVAL not supported in query parameters
tswast ca8872e
Merge remote-tracking branch 'upstream/master' into issue826-interval
tswast 018a617
Merge branch 'master' into issue826-interval
tswast 2872d85
Merge remote-tracking branch 'upstream/master' into issue826-interval
tswast 31c3f92
revert query parameter changes
tswast e3a3a6a
Merge remote-tracking branch 'origin/issue826-interval' into issue826…
tswast 5f78311
Merge branch 'master' into issue826-interval
tswast bb03618
add validation error for interval
tswast f3711e7
add unit tests for extreme intervals
tswast 68035ba
add dateutil to intersphinx
tswast 9a011e9
Merge remote-tracking branch 'upstream/master' into issue826-interval
tswast 9f6b02d
use dictionary for intersphinx
tswast 7cccbd2
🦉 Updates from OwlBot
gcf-owl-bot[bot] 152e8c2
Merge remote-tracking branch 'upstream/master' into issue826-interval
tswast f0f3fbd
Merge remote-tracking branch 'origin/issue826-interval' into issue826…
tswast c4636fa
🦉 Updates from OwlBot
gcf-owl-bot[bot] 18aae17
Merge branch 'master' into issue826-interval
tswast eccea82
Merge branch 'main' into issue826-interval
tswast 5cdeffb
Merge remote-tracking branch 'upstream/main' into issue826-interval
tswast 0497b19
add test case for trailing .
tswast 92f41b9
Merge remote-tracking branch 'origin/issue826-interval' into issue826…
tswast 0318f54
explicit none
tswast 6b1f238
🦉 Updates from OwlBot
gcf-owl-bot[bot] 54e47f7
truncate nanoseconds
tswast ced356b
Merge remote-tracking branch 'origin/issue826-interval' into issue826…
tswast dcc8b57
use \d group for digits
tswast 5c31fe2
Merge branch 'main' into issue826-interval
tswast 2091478
Merge branch 'main' into issue826-interval
tswast 21a2975
Merge branch 'main' into issue826-interval
plamut 87b0d81
Merge remote-tracking branch 'upstream/main' into issue826-interval
tswast 7bd48be
Merge remote-tracking branch 'origin/issue826-interval' into issue826…
tswast d62b950
use \d for consistency
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,157 @@ | ||
# 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. | ||
|
||
from dateutil.relativedelta import relativedelta | ||
import pytest | ||
|
||
from google.cloud.bigquery.schema import SchemaField | ||
|
||
|
||
def create_field(mode="NULLABLE", type_="IGNORED"): | ||
return SchemaField("test_field", type_, mode=mode) | ||
|
||
|
||
@pytest.fixture | ||
def mut(): | ||
from google.cloud.bigquery import _helpers | ||
|
||
return _helpers | ||
|
||
|
||
def test_interval_from_json_w_none_nullable(mut): | ||
got = mut._interval_from_json(None, create_field()) | ||
assert got is None | ||
|
||
|
||
def test_interval_from_json_w_none_required(mut): | ||
with pytest.raises(TypeError): | ||
mut._interval_from_json(None, create_field(mode="REQUIRED")) | ||
|
||
|
||
def test_interval_from_json_w_invalid_format(mut): | ||
with pytest.raises(ValueError, match="NOT_AN_INTERVAL"): | ||
mut._interval_from_json("NOT_AN_INTERVAL", create_field()) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("value", "expected"), | ||
( | ||
("0-0 0 0:0:0", relativedelta()), | ||
# SELECT INTERVAL X YEAR | ||
("-10000-0 0 0:0:0", relativedelta(years=-10000)), | ||
("-1-0 0 0:0:0", relativedelta(years=-1)), | ||
("1-0 0 0:0:0", relativedelta(years=1)), | ||
("10000-0 0 0:0:0", relativedelta(years=10000)), | ||
# SELECT INTERVAL X MONTH | ||
("-0-11 0 0:0:0", relativedelta(months=-11)), | ||
("-0-1 0 0:0:0", relativedelta(months=-1)), | ||
("0-1 0 0:0:0", relativedelta(months=1)), | ||
("0-11 0 0:0:0", relativedelta(months=11)), | ||
# SELECT INTERVAL X DAY | ||
("0-0 -3660000 0:0:0", relativedelta(days=-3660000)), | ||
("0-0 -1 0:0:0", relativedelta(days=-1)), | ||
("0-0 1 0:0:0", relativedelta(days=1)), | ||
("0-0 3660000 0:0:0", relativedelta(days=3660000)), | ||
# SELECT INTERVAL X HOUR | ||
("0-0 0 -87840000:0:0", relativedelta(hours=-87840000)), | ||
("0-0 0 -1:0:0", relativedelta(hours=-1)), | ||
("0-0 0 1:0:0", relativedelta(hours=1)), | ||
("0-0 0 87840000:0:0", relativedelta(hours=87840000)), | ||
# SELECT INTERVAL X MINUTE | ||
("0-0 0 -0:59:0", relativedelta(minutes=-59)), | ||
("0-0 0 -0:1:0", relativedelta(minutes=-1)), | ||
("0-0 0 0:1:0", relativedelta(minutes=1)), | ||
("0-0 0 0:59:0", relativedelta(minutes=59)), | ||
# SELECT INTERVAL X SECOND | ||
("0-0 0 -0:0:59", relativedelta(seconds=-59)), | ||
("0-0 0 -0:0:1", relativedelta(seconds=-1)), | ||
("0-0 0 0:0:1", relativedelta(seconds=1)), | ||
("0-0 0 0:0:59", relativedelta(seconds=59)), | ||
# SELECT (INTERVAL -1 SECOND) / 1000000 | ||
("0-0 0 -0:0:0.000001", relativedelta(microseconds=-1)), | ||
("0-0 0 -0:0:59.999999", relativedelta(seconds=-59, microseconds=-999999)), | ||
("0-0 0 -0:0:59.999", relativedelta(seconds=-59, microseconds=-999000)), | ||
("0-0 0 0:0:59.999", relativedelta(seconds=59, microseconds=999000)), | ||
("0-0 0 0:0:59.999999", relativedelta(seconds=59, microseconds=999999)), | ||
# Test with multiple digits in each section. | ||
( | ||
"32-11 45 67:16:23.987654", | ||
relativedelta( | ||
years=32, | ||
months=11, | ||
days=45, | ||
hours=67, | ||
minutes=16, | ||
seconds=23, | ||
microseconds=987654, | ||
), | ||
), | ||
( | ||
"-32-11 -45 -67:16:23.987654", | ||
relativedelta( | ||
years=-32, | ||
months=-11, | ||
days=-45, | ||
hours=-67, | ||
minutes=-16, | ||
seconds=-23, | ||
microseconds=-987654, | ||
), | ||
), | ||
# Test with mixed +/- sections. | ||
( | ||
"9999-9 -999999 9999999:59:59.999999", | ||
relativedelta( | ||
years=9999, | ||
months=9, | ||
days=-999999, | ||
hours=9999999, | ||
minutes=59, | ||
seconds=59, | ||
microseconds=999999, | ||
), | ||
), | ||
# Test with fraction that is not microseconds. | ||
("0-0 0 0:0:42.", relativedelta(seconds=42)), | ||
("0-0 0 0:0:59.1", relativedelta(seconds=59, microseconds=100000)), | ||
("0-0 0 0:0:0.12", relativedelta(microseconds=120000)), | ||
("0-0 0 0:0:0.123", relativedelta(microseconds=123000)), | ||
("0-0 0 0:0:0.1234", relativedelta(microseconds=123400)), | ||
# Fractional seconds can cause rounding problems if cast to float. See: | ||
# https://github.com/googleapis/python-db-dtypes-pandas/issues/18 | ||
("0-0 0 0:0:59.876543", relativedelta(seconds=59, microseconds=876543)), | ||
( | ||
"0-0 0 01:01:01.010101", | ||
relativedelta(hours=1, minutes=1, seconds=1, microseconds=10101), | ||
), | ||
( | ||
"0-0 0 09:09:09.090909", | ||
relativedelta(hours=9, minutes=9, seconds=9, microseconds=90909), | ||
), | ||
( | ||
"0-0 0 11:11:11.111111", | ||
relativedelta(hours=11, minutes=11, seconds=11, microseconds=111111), | ||
), | ||
( | ||
"0-0 0 19:16:23.987654", | ||
relativedelta(hours=19, minutes=16, seconds=23, microseconds=987654), | ||
), | ||
# Nanoseconds are not expected, but should not cause error. | ||
("0-0 0 0:0:00.123456789", relativedelta(microseconds=123456)), | ||
("0-0 0 0:0:59.87654321", relativedelta(seconds=59, microseconds=876543)), | ||
), | ||
) | ||
def test_w_string_values(mut, value, expected): | ||
got = mut._interval_from_json(value, create_field()) | ||
assert got == expected |
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.
Uh oh!
There was an error while loading. Please reload this page.