Skip to content

Commit 6875474

Browse files
committed
Added more supporting formats
1 parent 47a0fbe commit 6875474

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/databricks/sql/utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,13 @@ def convert_decimals_in_arrow_table(table, description) -> "pyarrow.Table":
629629

630630

631631
def datetime_parser(datetime_string):
632-
formats = ["%Y-%m-%d %H:%M:%S", "%Y-%m-%d"]
632+
formats = [
633+
"%Y-%m-%d %H:%M:%S.%f", # MySQL and PostgreSQL format
634+
"%Y-%m-%d %H:%M:%S", # Common SQL format
635+
"%Y-%m-%d", # MySQL Date only
636+
"%m/%d/%Y %I:%M:%S %p", # US format MSSQL Server
637+
"%d-%b-%Y %H:%M:%S", # Oracle format
638+
]
633639

634640
for fmt in formats:
635641
try:

tests/unit/test_util.py

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def get_column_table_and_description(self):
2020
("date_column", "date", None, None, None, None, None),
2121
("timestamp_column", "timestamp", None, None, None, None, None),
2222
("timestamp_ntz_column", "timestamp", None, None, None, None, None),
23+
("timestamp_column_2", "timestamp", None, None, None, None, None),
24+
("timestamp_column_3", "timestamp", None, None, None, None, None),
25+
("timestamp_column_4", "timestamp", None, None, None, None, None),
2326
("binary_column", "binary", None, None, None, None, None),
2427
("array_column", "array", None, None, None, None, None),
2528
("map_column", "map", None, None, None, None, None),
@@ -41,6 +44,9 @@ def get_column_table_and_description(self):
4144
("2023-12-31",),
4245
("2023-12-31 12:30:00",),
4346
("2023-12-31 12:30:00",),
47+
("2021-09-30 11:27:35.123",),
48+
("03/08/2024 02:30:15 PM",),
49+
("08-Mar-2024 14:30:15",),
4450
(b"\xde\xad\xbe\xef",),
4551
('["item1","item2"]',),
4652
('{"key1":"value1","key2":"value2"}',),
@@ -71,6 +77,9 @@ def test_convert_to_assigned_datatypes_in_column_table(self):
7177
(datetime.date(2023, 12, 31), datetime.date),
7278
(datetime.datetime(2023, 12, 31, 12, 30, 0), datetime.datetime),
7379
(datetime.datetime(2023, 12, 31, 12, 30, 0), datetime.datetime),
80+
(datetime.datetime(2021, 9, 30, 11, 27, 35, 123000), datetime.datetime),
81+
(datetime.datetime(2024, 3, 8, 14, 30, 15), datetime.datetime),
82+
(datetime.datetime(2024, 3, 8, 14, 30, 15), datetime.datetime),
7483
(b"\xde\xad\xbe\xef", bytes),
7584
('["item1","item2"]', str),
7685
('{"key1":"value1","key2":"value2"}', str),

0 commit comments

Comments
 (0)