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

Another fix for views back in system.tables #45

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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