-
Notifications
You must be signed in to change notification settings - Fork 113
Support multiple timestamp formats in non arrow flow #533
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd0243d
Added check for 2 formats
jprakash-db 9b5862c
Wrote unit tests
jprakash-db 47a0fbe
Merge branch 'main' into jprakash-db/non-arrow-timestamp-parser
jprakash-db 6875474
Added more supporting formats
jprakash-db 68c5964
Added the T format datetime
jprakash-db b284161
Added more timestamp formats
jprakash-db b070483
Added python-dateutil library
jprakash-db 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import decimal | ||
import datetime | ||
|
||
from databricks.sql.utils import convert_to_assigned_datatypes_in_column_table | ||
|
||
|
||
class TestUtils: | ||
def get_column_table_and_description(self): | ||
table_description = [ | ||
("id", "int", None, None, None, None, None), | ||
("varchar_column", "string", None, None, None, None, None), | ||
("boolean_column", "boolean", None, None, None, None, None), | ||
("integer_column", "int", None, None, None, None, None), | ||
("bigint_column", "bigint", None, None, None, None, None), | ||
("smallint_column", "smallint", None, None, None, None, None), | ||
("tinyint_column", "tinyint", None, None, None, None, None), | ||
("float_column", "float", None, None, None, None, None), | ||
("double_column", "double", None, None, None, None, None), | ||
("decimal_column", "decimal", None, None, 10, 2, None), | ||
("date_column", "date", None, None, None, None, None), | ||
("timestamp_column", "timestamp", None, None, None, None, None), | ||
("timestamp_ntz_column", "timestamp", None, None, None, None, None), | ||
("timestamp_column_2", "timestamp", None, None, None, None, None), | ||
("timestamp_column_3", "timestamp", None, None, None, None, None), | ||
("timestamp_column_4", "timestamp", None, None, None, None, None), | ||
("binary_column", "binary", None, None, None, None, None), | ||
("array_column", "array", None, None, None, None, None), | ||
("map_column", "map", None, None, None, None, None), | ||
("struct_column", "struct", None, None, None, None, None), | ||
("variant_column", "string", None, None, None, None, None), | ||
] | ||
|
||
column_table = [ | ||
(9,), | ||
("Test Varchar",), | ||
(True,), | ||
(123,), | ||
(9876543210,), | ||
(32000,), | ||
(120,), | ||
(1.23,), | ||
(4.56,), | ||
("7890.12",), | ||
("2023-12-31",), | ||
("2023-12-31 12:30:00",), | ||
("2023-12-31 12:30:00",), | ||
("2021-09-30 11:27:35.123",), | ||
("03/08/2024 02:30:15 PM",), | ||
("08-Mar-2024 14:30:15",), | ||
(b"\xde\xad\xbe\xef",), | ||
('["item1","item2"]',), | ||
('{"key1":"value1","key2":"value2"}',), | ||
('{"name":"John","age":30}',), | ||
('"semi-structured data"',), | ||
] | ||
|
||
return column_table, table_description | ||
|
||
def test_convert_to_assigned_datatypes_in_column_table(self): | ||
column_table, description = self.get_column_table_and_description() | ||
converted_column_table = convert_to_assigned_datatypes_in_column_table( | ||
column_table, description | ||
) | ||
|
||
# (data , datatype) | ||
expected_convertion = [ | ||
(9, int), | ||
("Test Varchar", str), | ||
(True, bool), | ||
(123, int), | ||
(9876543210, int), | ||
(32000, int), | ||
(120, int), | ||
(1.23, float), | ||
(4.56, float), | ||
(decimal.Decimal("7890.12"), decimal.Decimal), | ||
(datetime.date(2023, 12, 31), datetime.date), | ||
(datetime.datetime(2023, 12, 31, 12, 30, 0), datetime.datetime), | ||
(datetime.datetime(2023, 12, 31, 12, 30, 0), datetime.datetime), | ||
(datetime.datetime(2021, 9, 30, 11, 27, 35, 123000), datetime.datetime), | ||
(datetime.datetime(2024, 3, 8, 14, 30, 15), datetime.datetime), | ||
(datetime.datetime(2024, 3, 8, 14, 30, 15), datetime.datetime), | ||
(b"\xde\xad\xbe\xef", bytes), | ||
('["item1","item2"]', str), | ||
('{"key1":"value1","key2":"value2"}', str), | ||
('{"name":"John","age":30}', str), | ||
('"semi-structured data"', str), | ||
] | ||
|
||
for index, entry in enumerate(converted_column_table): | ||
assert entry[0] == expected_convertion[index][0] | ||
assert isinstance(entry[0], expected_convertion[index][1]) |
Oops, something went wrong.
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.