You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/05/13 19:20:40 UTC

[GitHub] [phoenix-queryserver] joshelser commented on pull request #32: PHOENIX-5880 Add SQLAchemy support to python driver

joshelser commented on pull request #32:
URL: https://github.com/apache/phoenix-queryserver/pull/32#issuecomment-628194549


   I've been trying my hand at this. A couple of things:
   
   ```
   Exception ignored in: <function Connection.__del__ at 0x1029991f0>
   Traceback (most recent call last):
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/phoenixdb-1.0.0.dev0-py3.8.egg/phoenixdb/connection.py", line 63, in __del__
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/phoenixdb-1.0.0.dev0-py3.8.egg/phoenixdb/connection.py", line 91, in close
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/phoenixdb-1.0.0.dev0-py3.8.egg/phoenixdb/avatica/client.py", line 341, in close_connection
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/phoenixdb-1.0.0.dev0-py3.8.egg/phoenixdb/avatica/client.py", line 207, in _apply
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/phoenixdb-1.0.0.dev0-py3.8.egg/phoenixdb/avatica/client.py", line 177, in _post_request
     File "/Users/jelser/projects/phoenix-queryserver.git/python/phoenixdb/.eggs/requests-2.23.0-py3.8.egg/requests/api.py", line 61, in request
     File "/Users/jelser/projects/phoenix-queryserver.git/python/phoenixdb/.eggs/requests-2.23.0-py3.8.egg/requests/sessions.py", line 520, in request
     File "/Users/jelser/projects/phoenix-queryserver.git/python/phoenixdb/.eggs/requests-2.23.0-py3.8.egg/requests/sessions.py", line 697, in merge_environment_settings
     File "/Users/jelser/projects/phoenix-queryserver.git/python/phoenixdb/.eggs/requests-2.23.0-py3.8.egg/requests/utils.py", line 766, in get_environ_proxies
     File "/Users/jelser/projects/phoenix-queryserver.git/python/phoenixdb/.eggs/requests-2.23.0-py3.8.egg/requests/utils.py", line 750, in should_bypass_proxies
     File "/Users/jelser/.pyenv/versions/3.8.2/lib/python3.8/urllib/request.py", line 2615, in proxy_bypass
     File "/Users/jelser/.pyenv/versions/3.8.2/lib/python3.8/urllib/request.py", line 2592, in proxy_bypass_macosx_sysconf
     File "/Users/jelser/.pyenv/versions/3.8.2/lib/python3.8/urllib/request.py", line 2539, in _proxy_bypass_macosx_sysconf
   ImportError: sys.meta_path is None, Python is likely shutting down
   ```
   
   I see this when python goes down. Is this an ordering thing where we've already cleaned up some state but are trying to close the connection? I called `close()` on the resources I thought I opened.
   
   I don't see a way to write data from sqlalchemy as it doesn't support our "UPSERT" instead of "INSERT". I guess we're in read-only mode for now?
   
   Similarly, the ORM adapter doesn't seem to properly pick up the constraint (or I'm just not doing it correctly)
   ```
   class User(Base):
       __tablename__ = 'users'
       id = Column(Integer, primary_key=True)
       name = Column(String)
       fullname = Column(String)
       nickname = Column(String)
       def __repr__(self):
           return "<Users(name='%s', fullname='%s', nickname='%s')>" % (self.name, self.fullname, self.nickname)
   ```
   
   nets me
   
   ```
   Traceback (most recent call last):
     File "test-phoenix-wizardry-orm.py", line 21, in <module>
       Base.metadata.create_all(engine)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/schema.py", line 4320, in create_all
       bind._run_visitor(
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/engine/base.py", line 2058, in _run_visitor
       conn._run_visitor(visitorcallable, element, **kwargs)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/engine/base.py", line 1627, in _run_visitor
       visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/visitors.py", line 144, in traverse_single
       return meth(obj, **kw)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/ddl.py", line 777, in visit_metadata
       self.traverse_single(
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/visitors.py", line 144, in traverse_single
       return meth(obj, **kw)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/ddl.py", line 821, in visit_table
       self.connection.execute(
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/engine/base.py", line 984, in execute
       return meth(self, multiparams, params)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
       return connection._execute_ddl(self, multiparams, params)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/engine/base.py", line 1035, in _execute_ddl
       compiled = ddl.compile(
     File "<string>", line 1, in <lambda>
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/elements.py", line 468, in compile
       return self._compiler(dialect, bind=bind, **kw)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/ddl.py", line 29, in _compiler
       return dialect.ddl_compiler(dialect, self, **kw)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 319, in __init__
       self.string = self.process(self.statement, **compile_kwargs)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 350, in process
       return obj._compiler_dispatch(self, **kwargs)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/visitors.py", line 95, in _compiler_dispatch
       return meth(self, **kw)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 2912, in visit_create_table
       const = self.create_table_constraints(
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 2961, in create_table_constraints
       return ", \n\t".join(
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 2961, in <genexpr>
       return ", \n\t".join(
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 2964, in <genexpr>
       self.process(constraint)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/compiler.py", line 350, in process
       return obj._compiler_dispatch(self, **kwargs)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/SQLAlchemy-1.3.16-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/sql/visitors.py", line 95, in _compiler_dispatch
       return meth(self, **kw)
     File "/Users/jelser/projects/phoenix-sqlalchemy.git/e/lib/python3.8/site-packages/phoenixdb-1.0.0.dev0-py3.8.egg/phoenixdb/sqlalchemy_phoenix.py", line 37, in visit_primary_key_constraint
   sqlalchemy.exc.CompileError: can't create primary key without a name
   ```
   This seems to be a constraint you added. I thought that adding the `primary_key=True` attribute on the class would be enough. Maybe not? The sqlalchemy docs here are kind of vague.
   
   Anyways, on this I was able to do. `tox` on 2.7, 3.{5,6,7,8} all came back green (3.4 wants to complain about openssl for me and not install itself). I was able to write some data via sqlline-thin and then read it back via a trivial sqlalchemy client.
   
   I think this is good (+1) and am looking forward to more to make this better :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org