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

Update sqlalchemy_presto.py add try_cast #6899

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion python/pyhive/tests/test_sqlalchemy_presto.py
Original file line number Diff line number Diff line change
@@ -6,15 +6,19 @@

import sqlalchemy

from pyhive.sqlalchemy_presto import PrestoDialect
from pyhive.tests.sqlalchemy_test_case import SqlAlchemyTestCase
from pyhive.tests.sqlalchemy_test_case import with_engine_connection
from sqlalchemy import types
from sqlalchemy import select
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import Column
from sqlalchemy.schema import MetaData
from sqlalchemy.schema import Table
from sqlalchemy.sql import text
from sqlalchemy.sql import try_cast
from sqlalchemy.types import String
from sqlalchemy.types import Double
from decimal import Decimal

import contextlib
@@ -102,4 +106,12 @@ def test_hash_table(self, engine, connection):
self.assertFalse(insp.has_table("THIS_TABLE_DOSE_not_exist"))
else:
self.assertFalse(Table('THIS_TABLE_DOSE_NOT_EXIST', MetaData(bind=engine)).exists())
self.assertFalse(Table('THIS_TABLE_DOSE_not_exits', MetaData(bind=engine)).exists())
self.assertFalse(Table('THIS_TABLE_DOSE_not_exits', MetaData(bind=engine)).exists())

def test_try_cast(self):
fake_table = Table('TestModel', MetaData(), Column('MaybeDouble', String))
query = str(select(try_cast(fake_table.c.MaybeDouble, Double)).compile(dialect=PrestoDialect(), compile_kwargs={"literal_binds": True}))
self.assertIn(
'try_cast("TestModel"."MaybeDouble" as DOUBLE)',
query
)