forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ingest): bigquery - Fix BigQuery Datetime/Timestamp type column p…
…artition table profile bug (datahub-project#4658) * fix BigQuery Datetime type column partition table profile bug * inplace datetime replace * extract out 'if' blocks and write a unit-test * parse logic inside get_partition_range func
- Loading branch information
1 parent
754aa23
commit 8254d1e
Showing
2 changed files
with
109 additions
and
9 deletions.
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
56 changes: 56 additions & 0 deletions
56
metadata-ingestion/tests/unit/test_bq_get_partition_range.py
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,56 @@ | ||
import datetime | ||
|
||
from datahub.ingestion.source.sql.bigquery import get_partition_range_from_partition_id | ||
|
||
|
||
def test_get_partition_range_from_partition_id(): | ||
# yearly partition check | ||
assert get_partition_range_from_partition_id( | ||
"2022", datetime.datetime(2022, 1, 1) | ||
) == (datetime.datetime(2022, 1, 1), datetime.datetime(2023, 1, 1)) | ||
assert get_partition_range_from_partition_id( | ||
"2022", datetime.datetime(2022, 3, 12) | ||
) == (datetime.datetime(2022, 1, 1), datetime.datetime(2023, 1, 1)) | ||
assert get_partition_range_from_partition_id( | ||
"2022", datetime.datetime(2021, 5, 2) | ||
) == (datetime.datetime(2021, 1, 1), datetime.datetime(2022, 1, 1)) | ||
assert get_partition_range_from_partition_id("2022", None) == ( | ||
datetime.datetime(2022, 1, 1), | ||
datetime.datetime(2023, 1, 1), | ||
) | ||
# monthly partition check | ||
assert get_partition_range_from_partition_id( | ||
"202202", datetime.datetime(2022, 2, 1) | ||
) == (datetime.datetime(2022, 2, 1), datetime.datetime(2022, 3, 1)) | ||
assert get_partition_range_from_partition_id( | ||
"202202", datetime.datetime(2022, 2, 3) | ||
) == (datetime.datetime(2022, 2, 1), datetime.datetime(2022, 3, 1)) | ||
assert get_partition_range_from_partition_id( | ||
"202202", datetime.datetime(2021, 12, 13) | ||
) == (datetime.datetime(2021, 12, 1), datetime.datetime(2022, 1, 1)) | ||
assert get_partition_range_from_partition_id("202202", None) == ( | ||
datetime.datetime(2022, 2, 1), | ||
datetime.datetime(2022, 3, 1), | ||
) | ||
# daily partition check | ||
assert get_partition_range_from_partition_id( | ||
"20220205", datetime.datetime(2022, 2, 5) | ||
) == (datetime.datetime(2022, 2, 5), datetime.datetime(2022, 2, 6)) | ||
assert get_partition_range_from_partition_id( | ||
"20220205", datetime.datetime(2022, 2, 3) | ||
) == (datetime.datetime(2022, 2, 3), datetime.datetime(2022, 2, 4)) | ||
assert get_partition_range_from_partition_id("20220205", None) == ( | ||
datetime.datetime(2022, 2, 5), | ||
datetime.datetime(2022, 2, 6), | ||
) | ||
# hourly partition check | ||
assert get_partition_range_from_partition_id( | ||
"2022020509", datetime.datetime(2022, 2, 5, 9) | ||
) == (datetime.datetime(2022, 2, 5, 9), datetime.datetime(2022, 2, 5, 10)) | ||
assert get_partition_range_from_partition_id( | ||
"2022020509", datetime.datetime(2022, 2, 3, 1) | ||
) == (datetime.datetime(2022, 2, 3, 1), datetime.datetime(2022, 2, 3, 2)) | ||
assert get_partition_range_from_partition_id("2022020509", None) == ( | ||
datetime.datetime(2022, 2, 5, 9), | ||
datetime.datetime(2022, 2, 5, 10), | ||
) |