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 de6bc82 PHOENIX-5936 sqlAlchemy get_columns KeyError: None
de6bc82 is described below
commit de6bc827d87d92f82815de5006e794e0116cd95c
Author: Istvan Toth <[email protected]>
AuthorDate: Thu Jun 4 10:26:33 2020 +0200
PHOENIX-5936 sqlAlchemy get_columns KeyError: None
Closes #36
---
python/phoenixdb/phoenixdb/sqlalchemy_phoenix.py | 22 +++++++++++-----------
.../phoenixdb/phoenixdb/tests/test_sqlalchemy.py | 19 +++++++++++++++++++
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/python/phoenixdb/phoenixdb/sqlalchemy_phoenix.py
b/python/phoenixdb/phoenixdb/sqlalchemy_phoenix.py
index 1d5da0a..e109fff 100644
--- a/python/phoenixdb/phoenixdb/sqlalchemy_phoenix.py
+++ b/python/phoenixdb/phoenixdb/sqlalchemy_phoenix.py
@@ -137,24 +137,24 @@ class PhoenixDialect(DefaultDialect):
def get_columns(self, connection, table_name, schema=None, **kw):
if schema is None:
- query = "SELECT COLUMN_NAME, DATA_TYPE, NULLABLE " \
- "FROM system.catalog " \
- "WHERE table_name = ? " \
- "ORDER BY ORDINAL_POSITION"
+ query = """SELECT COLUMN_NAME, DATA_TYPE, NULLABLE
+ FROM system.catalog
+ WHERE table_name = ?
+ AND ORDINAL_POSITION is not null
+ ORDER BY ORDINAL_POSITION"""
params = [table_name.upper()]
else:
- query = "SELECT COLUMN_NAME, DATA_TYPE, NULLABLE " \
- "FROM system.catalog " \
- "WHERE TABLE_SCHEM = ? " \
- "AND table_name = ? " \
- "ORDER BY ORDINAL_POSITION"
+ query = """SELECT COLUMN_NAME, DATA_TYPE, NULLABLE
+ FROM system.catalog
+ WHERE TABLE_SCHEM = ?
+ AND table_name = ?
+ AND ORDINAL_POSITION is not null
+ ORDER BY ORDINAL_POSITION"""
params = [schema.upper(), table_name.upper()]
# get all of the fields for this table
c = connection.execute(query, params)
cols = []
- # first always none
- c.fetchone()
while True:
row = c.fetchone()
if row is None:
diff --git a/python/phoenixdb/phoenixdb/tests/test_sqlalchemy.py
b/python/phoenixdb/phoenixdb/tests/test_sqlalchemy.py
index 2cf7a57..fe7bd1d 100644
--- a/python/phoenixdb/phoenixdb/tests/test_sqlalchemy.py
+++ b/python/phoenixdb/phoenixdb/tests/test_sqlalchemy.py
@@ -52,6 +52,25 @@ class SQLAlchemyTest(unittest.TestCase):
finally:
connection.execute('drop table if exists ALCHEMY_TEST')
+ def test_reflection(self):
+ engine = self._create_engine()
+ with engine.connect() as connection:
+ try:
+ inspector = db.inspect(engine)
+ columns_result = inspector.get_columns('DOES_NOT_EXIST')
+ self.assertEqual([], columns_result)
+ connection.execute('drop table if exists us_population')
+ connection.execute(text('''create table if not exists
US_POPULATION (
+ state CHAR(2) NOT NULL,
+ city VARCHAR NOT NULL,
+ population BIGINT
+ CONSTRAINT my_pk PRIMARY KEY (state, city))'''))
+ columns_result = inspector.get_columns('us_population')
+ self.assertEqual(len(columns_result), 3)
+ print(columns_result)
+ finally:
+ connection.execute('drop table if exists us_population')
+
@unittest.skip("ORM feature not implemented")
def test_orm(self):
pass