Skip to content

Commit

Permalink
prepare test release 0.0.101
Browse files Browse the repository at this point in the history
added tests around the dialect. bumped up versions to support superset 3.0.0 while retaining backwards compatibility
  • Loading branch information
marregui committed Oct 16, 2023
1 parent 218152a commit e7c709d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ venv
questdb_connect.egg-info
__pycache__
dist
build
3 changes: 0 additions & 3 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ This will be the URI for QuestDB:
questdb://admin:quest@host.docker.internal:8812/main
```

**Note**: As per [https://github.com/apache/superset/pull/24172](https://github.com/apache/superset/pull/24172)
the `Superset Engine Spec` has been moved to superset's repository.

## Build questdb-connect wheel and publish it

Follow the guidelines
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
[project]
name = 'questdb-connect'
#version = '1.0.10' # Standalone production version (with engine)
version = '0.0.100' # testing version
version = '0.0.101' # testing version
authors = [{ name = 'questdb.io', email = 'miguel@questdb.io' }]
description = "SqlAlchemy library"
readme = "README.md"
Expand Down Expand Up @@ -54,9 +54,9 @@ questdb = 'qdb_superset.db_engine_specs.questdb:QuestDbEngineSpec'
[project.optional-dependencies]
test = [
'psycopg2-binary~=2.9.6',
'SQLAlchemy<=1.4.47',
'apache-superset>=2.1.0',
'sqlparse==0.4.3',
'SQLAlchemy>=1.4, <2',
'apache-superset>=3.0.0',
'sqlparse==0.4.4',
'pytest~=7.3.0',
'pytest_mock~=3.11.1',
'black~=23.3.0',
Expand Down
10 changes: 5 additions & 5 deletions src/qdb_superset/db_engine_specs/questdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@

class QuestDbParametersSchema(Schema):
username = fields.String(
description=__("username"),
metadata={"description": __("username")},
dump_default="admin",
load_default="admin",
)
password = fields.String(
description=__("password"),
metadata={"description": __("password")},
dump_default="quest",
load_default="quest",
)
host = fields.String(
description=__("host"),
metadata={"description": __("host")},
dump_default="host.docker.internal",
load_default="host.docker.internal",
)
port = fields.Integer(
description=__("port"),
metadata={"description": __("port")},
dump_default="8812",
load_default="8812",
)
database = fields.String(
description=__("database"),
metadata={"description": __("database")},
dump_default="main",
load_default="main",
)
Expand Down
4 changes: 2 additions & 2 deletions src/questdb_connect/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def get_schema_names(self, conn, **kw):
return ["public"]

def get_table_names(self, conn, schema=None, **kw):
return [row.table for row in self._exec(conn, "SHOW TABLES")]
return [row.table_name for row in self._exec(conn, "SHOW tables")]

def has_table(self, conn, table_name, schema=None):
return self._exec(conn, f"tables() WHERE name='{table_name}'").rowcount == 1
return table_name in set(self.get_table_names(conn, schema))

@sqlalchemy.engine.reflection.cache
def get_columns(self, conn, table_name, schema=None, **kw):
Expand Down
9 changes: 8 additions & 1 deletion src/questdb_connect/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#
import abc

import psycopg2
import sqlalchemy

from .common import PartitionBy
Expand Down Expand Up @@ -52,7 +53,13 @@ def reflect_table(
_extend_on=None,
):
table_name = table.name
result_set = self.bind.execute(f"tables() WHERE name = '{table_name}'")
try:
result_set = self.bind.execute(
f"tables() WHERE table_name = '{table_name}'"
)
except psycopg2.DatabaseError:
# older version
result_set = self.bind.execute(f"tables() WHERE name = '{table_name}'")
if not result_set:
self._panic_table(table_name)
table_attrs = result_set.first()
Expand Down
24 changes: 24 additions & 0 deletions tests/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ def test_bulk_insert(test_engine, test_model):
assert collect_select_all_raw_connection(test_engine, expected_rows=num_rows) == expected


def test_dialect_get_schema_names(test_engine):
dialect = qdbc.QuestDBDialect()
with test_engine.connect() as conn:
assert dialect.get_schema_names(conn) == ["public"]


def test_dialect_get_table_names(test_engine):
dialect = qdbc.QuestDBDialect()
with test_engine.connect() as conn:
table_names = dialect.get_table_names(conn, schema="public")
assert table_names == dialect.get_table_names(conn)
assert len(table_names) > 0


def test_dialect_has_table(test_engine):
dialect = qdbc.QuestDBDialect()
with test_engine.connect() as conn:
for table_name in dialect.get_table_names(conn):
if not dialect.has_table(conn, table_name):
raise AssertionError()
if not dialect.has_table(conn, table_name, schema="public"):
raise AssertionError()


def test_functions(test_engine):
with test_engine.connect() as conn:
expected = [row[0] for row in conn.execute("SELECT name FROM functions()").fetchall()]
Expand Down

0 comments on commit e7c709d

Please sign in to comment.