Skip to content

Commit

Permalink
Another fix for views back in system.tables (#45)
Browse files Browse the repository at this point in the history
* Another fix for views back in system.tables

* Skip Enum Test

* Try setting format_null_as_str=0

 * This is ugly, should be set global on the database or connection string
  • Loading branch information
rad-pat authored Sep 16, 2024
1 parent 3226f10 commit 3b65a30
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
29 changes: 21 additions & 8 deletions databend_sqlalchemy/databend_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,21 +846,34 @@ def get_table_options(self, connection, table_name, schema=None, **kw):

# engine_regex = r'ENGINE=(\w+)'
# cluster_key_regex = r'CLUSTER BY \((.*)\)'

query = text(
query_text = (
"""
SELECT engine_full, cluster_by, is_transient
FROM system.tables
WHERE database = :schema_name
and name = :table_name
"""
)
# This handles bug that existed a while
# https://github.com/datafuselabs/databend/pull/16149
if self.server_version_info > (1, 2, 410) and self.server_version_info <= (1, 2, 604):
query_text = (
"""
SELECT engine_full, cluster_by, is_transient
FROM system.tables
WHERE database = :schema_name
and name = :table_name
UNION
UNION
SELECT engine_full, NULL as cluster_by, NULL as is_transient
FROM system.views
WHERE database = :schema_name
and name = :table_name
"""
SELECT engine_full, NULL as cluster_by, NULL as is_transient
FROM system.views
WHERE database = :schema_name
and name = :table_name
"""
)
query = text(
query_text
).bindparams(
bindparam("table_name", type_=sqltypes.Unicode),
bindparam("schema_name", type_=sqltypes.Unicode)
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sqlalchemy.dialects import registry
from sqlalchemy import event, Engine, text
import pytest

registry.register("databend.databend", "databend_sqlalchemy.databend_dialect", "DatabendDialect")
Expand All @@ -7,3 +8,10 @@
pytest.register_assert_rewrite("sa.testing.assertions")

from sqlalchemy.testing.plugin.pytestplugin import *


@event.listens_for(Engine, "connect")
def receive_engine_connect(conn, r):
cur = conn.cursor()
cur.execute('SET global format_null_as_str = 0')
cur.close()
8 changes: 8 additions & 0 deletions tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from sqlalchemy.testing.suite import ServerSideCursorsTest as _ServerSideCursorsTest
from sqlalchemy.testing.suite import IntervalTest as _IntervalTest
from sqlalchemy.testing.suite import PrecisionIntervalTest as _PrecisionIntervalTest
from sqlalchemy.testing.suite import EnumTest as _EnumTest
from sqlalchemy import types as sql_types
from sqlalchemy import testing, select
from sqlalchemy.testing import config, eq_
Expand Down Expand Up @@ -322,3 +323,10 @@ def test_arithmetic_operation_table_date_and_literal_interval(
self, connection, arithmetic_table_fixture
):
pass

class EnumTest(_EnumTest):
__backend__ = True

@testing.skip("databend") # Skipped because no supporting enums yet
def test_round_trip_executemany(self, connection):
pass

0 comments on commit 3b65a30

Please sign in to comment.