You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2020/07/16 03:41:45 UTC

[phoenix-queryserver] branch master updated: PHOENIX-5994 SqlAlchemy schema filtering incorrect semantics (addendum: sqlalchemy fixes)

This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix-queryserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 7da03fc  PHOENIX-5994 SqlAlchemy schema filtering incorrect semantics (addendum: sqlalchemy fixes)
7da03fc is described below

commit 7da03fc89971a5ee426b5d7d3200db570c187742
Author: Istvan Toth <st...@apache.org>
AuthorDate: Wed Jul 15 17:42:09 2020 +0200

    PHOENIX-5994 SqlAlchemy schema filtering incorrect semantics (addendum: sqlalchemy fixes)
    
    fixed in addendum:
    - get_table_names() noe correctly lists system tables
    - always return '' from get_schema_names()
---
 python-phoenixdb/phoenixdb/sqlalchemy_phoenix.py    | 8 ++++++--
 python-phoenixdb/phoenixdb/tests/test_sqlalchemy.py | 7 ++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/python-phoenixdb/phoenixdb/sqlalchemy_phoenix.py b/python-phoenixdb/phoenixdb/sqlalchemy_phoenix.py
index ad75d6d..61cb4b8 100644
--- a/python-phoenixdb/phoenixdb/sqlalchemy_phoenix.py
+++ b/python-phoenixdb/phoenixdb/sqlalchemy_phoenix.py
@@ -136,14 +136,18 @@ class PhoenixDialect(DefaultDialect):
 
     def get_schema_names(self, connection, **kw):
         schemas = connection.connect().connection.meta().get_schemas()
-        return [schema['TABLE_SCHEM'] for schema in schemas]
+        schema_names = [schema['TABLE_SCHEM'] for schema in schemas]
+        # Phoenix won't return the default schema if there aren't any tables in it
+        if '' not in schema_names:
+            schema_names.insert(0, '')
+        return schema_names
 
     def get_table_names(self, connection, schema=None, order_by=None, **kw):
         '''order_by is ignored'''
         if schema is None:
             schema = ''
         tables = connection.connect().connection.meta().get_tables(
-            schemaPattern=schema, typeList=('TABLE', 'SYSTEM_TABLE'))
+            schemaPattern=schema, typeList=('TABLE', 'SYSTEM TABLE'))
         return [table['TABLE_NAME'] for table in tables]
 
     def get_view_names(self, connection, schema=None, **kw):
diff --git a/python-phoenixdb/phoenixdb/tests/test_sqlalchemy.py b/python-phoenixdb/phoenixdb/tests/test_sqlalchemy.py
index 99df3be..37ed5a0 100644
--- a/python-phoenixdb/phoenixdb/tests/test_sqlalchemy.py
+++ b/python-phoenixdb/phoenixdb/tests/test_sqlalchemy.py
@@ -56,17 +56,18 @@ class SQLAlchemyTest(unittest.TestCase):
         engine = self._create_engine()
         with engine.connect() as connection:
             try:
+                inspector = db.inspect(engine)
+
                 connection.execute('drop table if exists ALCHEMY_TEST')
                 connection.execute('drop table if exists A.ALCHEMY_TEST_A')
                 connection.execute('drop table if exists B.ALCHEMY_TEST_B')
 
+                self.assertEqual(inspector.get_schema_names(), ['', 'SYSTEM'])
+
                 connection.execute(text('create table ALCHEMY_TEST (ID integer primary key)'))
                 connection.execute(text('create table A.ALCHEMY_TEST_A (ID_A integer primary key)'))
                 connection.execute(text('create table B.ALCHEMY_TEST_B (ID_B integer primary key)'))
 
-                inspector = db.inspect(engine)
-                print(inspector.default_schema_name)
-
                 self.assertEqual(inspector.get_schema_names(), ['', 'A', 'B', 'SYSTEM'])
 
                 self.assertEqual(inspector.get_table_names(), ['ALCHEMY_TEST'])