Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc817509

Browse files
author
Jesse Whitehouse
committed
Stop skipping TimeTest
This fix follows the same pattern used to make DateTimeHistoricTest worktest_suite.py::TimeTest_databricks+databricks::test_literal PASSEDtest_suite.py::TimeTest_databricks+databricks::test_null PASSEDtest_suite.py::TimeTest_databricks+databricks::test_null_bound_comparison PASSEDtest_suite.py::TimeTest_databricks+databricks::test_round_trip PASSEDtest_suite.py::TimeTest_databricks+databricks::test_round_trip_decorated PASSEDtest_suite.py::TimeTest_databricks+databricks::test_select_direct PASSEDSigned-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
1 parentf4a59f5 commitc817509

File tree

3 files changed

+34
-48
lines changed

3 files changed

+34
-48
lines changed

‎src/databricks/sqlalchemy/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class DatabricksDialect(default.DefaultDialect):
4949
paramstyle:str="named"
5050

5151
colspecs= {
52-
sqlalchemy.types.DateTime:dialect_type_impl.DatabricksDateTimeNoTimezoneType
52+
sqlalchemy.types.DateTime:dialect_type_impl.DatabricksDateTimeNoTimezoneType,
53+
sqlalchemy.types.Time:dialect_type_impl.DatabricksTimeType,
5354
}
5455

5556
@classmethod

‎src/databricks/sqlalchemy/_types.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,35 @@ def process_result_value(self, value: Union[None, datetime], dialect):
100100
ifvalueisNone:
101101
returnNone
102102
returnvalue.replace(tzinfo=None)
103+
104+
classDatabricksTimeType(sqlalchemy.types.TypeDecorator):
105+
"""Databricks has no native TIME type. So we store it as a string.
106+
"""
107+
108+
impl=sqlalchemy.types.Time
109+
cache_ok=True
110+
111+
112+
defprocess_bind_param(self,value:Union[datetime.time,None],dialect)->str:
113+
"""Values sent to the database are converted to %:H:%M:%S strings.
114+
"""
115+
ifvalueisNone:
116+
returnNone
117+
returnvalue.strftime("%H:%M:%S")
118+
119+
defprocess_literal_param(self,value,dialect)->datetime.time:
120+
"""It's not clear to me why this is necessary. Without it, SQLAlchemy's Timetest:test_literal fails
121+
because the string literal renderer receives a str() object and calls .isoformat() on it.
122+
123+
Whereas this method receives a datetime.time() object which is subsequently passed to that
124+
same renderer. And that works.
125+
"""
126+
returnvalue
127+
128+
129+
defprocess_result_value(self,value:Union[None,str],dialect)->Union[datetime.time,None]:
130+
"""Values received from the database are parsed into datetime.time() objects
131+
"""
132+
ifvalueisNone:
133+
returnNone
134+
returndatetime.strptime(value,"%H:%M:%S").time()

‎src/databricks/sqlalchemy/test/test_suite.py‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -355,53 +355,6 @@ def test_select_direct(self):
355355
"""
356356

357357

358-
classTimeTest(TimeTest):
359-
@pytest.mark.skip(
360-
reason="Time type implementation needs work. Dialect cannot write literal values."
361-
)
362-
deftest_literal(self):
363-
"""
364-
Exception:
365-
sqlalchemy.exc.CompileError: No literal value renderer is available for literal value "datetime.time(12, 57, 18)" with datatype TIME
366-
"""
367-
368-
@pytest.mark.skip(
369-
reason="Time type implementation needs work. Dialect cannot write literal values."
370-
)
371-
deftest_null_bound_comparison(self):
372-
"""
373-
Exception:
374-
sqlalchemy.exc.ProgrammingError: (databricks.sql.exc.ProgrammingError) Unsupported object 12:57:18
375-
"""
376-
377-
@pytest.mark.skip(
378-
reason="Time type implementation needs work. Dialect cannot write literal values."
379-
)
380-
deftest_round_trip(self):
381-
"""
382-
Exception:
383-
sqlalchemy.exc.ProgrammingError: (databricks.sql.exc.ProgrammingError) Unsupported object 12:57:18
384-
"""
385-
386-
@pytest.mark.skip(
387-
reason="Time type implementation needs work. Dialect cannot write literal values."
388-
)
389-
deftest_round_trip_decorated(self):
390-
"""
391-
Exception:
392-
sqlalchemy.exc.ProgrammingError: (databricks.sql.exc.ProgrammingError) Unsupported object 12:57:18
393-
"""
394-
395-
@pytest.mark.skip(
396-
reason="Time type implementation needs work. Dialect cannot write literal values."
397-
)
398-
deftest_select_direct(self):
399-
"""
400-
Exception:
401-
sqlalchemy.exc.ProgrammingError: (databricks.sql.exc.ProgrammingError) Unsupported object 12:57:18
402-
"""
403-
404-
405358
classTimestampMicrosecondsTest(TimestampMicrosecondsTest):
406359
@pytest.mark.skip(
407360
reason="Time type implementation needs work. Timezone not preserved. Cannot render literal values."

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp