Python Driver para Apache Phoenix (pendiente)#
Última modificación: Mayo 25, 2022
[7]:
%%writefile demo_phoenix.py
import phoenixdb
import phoenixdb.cursor
database_url = "http://0.0.0.0:8765"
conn = phoenixdb.connect(database_url, autocommit=True)
cursor = conn.cursor()
cursor.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username VARCHAR)")
cursor.execute("UPSERT INTO users VALUES (?, ?)", (1, "admin"))
cursor.execute("SELECT * FROM users")
print(cursor.fetchall())
cursor = conn.cursor(cursor_factory=phoenixdb.cursor.DictCursor)
cursor.execute("SELECT * FROM users WHERE id=1")
print(cursor.fetchone()["USERNAME"])
Overwriting demo_phoenix.py
[8]:
!python3 demo_phoenix.py
Traceback (most recent call last):
File "demo_phoenix.py", line 3, in <module>
import phoenixdb
File "/usr/local/lib/python3.8/dist-packages/phoenixdb/__init__.py", line 19, in <module>
from phoenixdb import errors, types
File "/usr/local/lib/python3.8/dist-packages/phoenixdb/types.py", line 21, in <module>
from phoenixdb.avatica.proto import common_pb2
File "/usr/local/lib/python3.8/dist-packages/phoenixdb/avatica/__init__.py", line 16, in <module>
from .client import AvaticaClient # noqa: F401
File "/usr/local/lib/python3.8/dist-packages/phoenixdb/avatica/client.py", line 27, in <module>
from phoenixdb.avatica.proto import common_pb2, requests_pb2, responses_pb2
File "/usr/local/lib/python3.8/dist-packages/phoenixdb/avatica/proto/common_pb2.py", line 47, in <module>
_descriptor.EnumValueDescriptor(
File "/usr/local/lib/python3.8/dist-packages/google/protobuf/descriptor.py", line 755, in __new__
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates