Skip to content
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

Support for TIME(p) and TIMESTAMP(p) to SQLAlchemy #181

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

hovaesco
Copy link
Member

First point from #107

@@ -147,6 +147,39 @@ def visit_BLOB(self, type_, **kw):
def visit_DATETIME(self, type_, **kw):
return self.visit_TIMESTAMP(type_, **kw)

def visit_INTERVAL(self, type_, **kw):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure whether it's a correct approach. Interval in Trino has a different value and data type.
For instance:

  • data type: INTERVAL YEAR TO MONTH
  • value: INTERVAL '3' MONTH

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this func supposed to return the data type or value? It seems like it returns a mix of both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a part when I'm not sure in which way to go. Other SQLAlchemy dialects which support INTERVAL data type handles it in different way (one return a value, other data type). INTERVAL data type doesn't seem to be supported for other dialects..

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move to other PR.

@andrewdibiasio6
Copy link

Many checks are failing.

@hovaesco
Copy link
Member Author

I've opened a new PR just with just INTERVAL changes #184

@hovaesco hovaesco force-pushed the hovaesco/sqlalchemy-data-types branch from 2bda620 to 2eeb2dc Compare June 20, 2022 11:51
trino/sqlalchemy/compiler.py Outdated Show resolved Hide resolved
trino/sqlalchemy/datatype.py Outdated Show resolved Hide resolved
@hovaesco hovaesco force-pushed the hovaesco/sqlalchemy-data-types branch from 2eeb2dc to b039b35 Compare June 23, 2022 11:25
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide simple test script? As you already know, we don't have integration tests for sqlalchemy. I hesitate to merge with confidence.

@hovaesco
Copy link
Member Author

Use the below script to test it.

from sqlalchemy import create_engine
from sqlalchemy.schema import MetaData, Column, Table
from trino.sqlalchemy.datatype import TIMESTAMP, TIME

engine = create_engine('trino://user@localhost:8080/memory/default')

metadata_obj = MetaData()

user = Table('test_time_timestamp', metadata_obj,
    Column('col1', TIME(precision=6, timezone=False)),
    Column('col2', TIMESTAMP(precision=3, timezone=True))
)

metadata_obj.create_all(engine)

As you already know, we don't have integration tests for sqlalchemy.

It's a good candidate to create a new issue.

@ebyhr
Copy link
Member

ebyhr commented Jun 25, 2022

@hovaesco Thanks for providing the code. Could you test with precision=0? It creates time(3) now, but it should be time(0). Also, can we add an assertion to verify the precision is in valid ranges (0, 12)?

@hovaesco hovaesco force-pushed the hovaesco/sqlalchemy-data-types branch from b039b35 to a8a0026 Compare June 27, 2022 09:05
@hovaesco
Copy link
Member Author

Thanks for spotting this out @ebyhr. I fixed it and added an assertion.

@hovaesco hovaesco force-pushed the hovaesco/sqlalchemy-data-types branch from a8a0026 to a5cf57f Compare June 27, 2022 10:02
@andrewdibiasio6
Copy link

LGTM pending ebyhr approval.

@hovaesco hovaesco force-pushed the hovaesco/sqlalchemy-data-types branch from a5cf57f to b7a59a0 Compare June 27, 2022 18:23
@ebyhr ebyhr merged commit fb92e93 into trinodb:master Jun 28, 2022
@ebyhr
Copy link
Member

ebyhr commented Jun 28, 2022

Merge, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants