Open
Description
Environment:
- Python: 3.10
- pyodps: 0.12.3
- sqlalchemy: 2.0.41
Script:
from odps import ODPS
from odps import options
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, LargeBinary
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
def test_odps_with_sqlalchemy():
options.sql.use_odps2_extension = True
connection_string = ("odps://{access_id}:{access_key}@{project}?endpoint={endpoint}").format(
access_id=ACCESS_KEY_ID,
access_key=ACCESS_KEY_SECRET,
project=PROJECT,
endpoint=ENDPOINT,
)
engine = create_engine(connection_string)
Base = declarative_base()
class User(Base):
__tablename__ = 'test_odps_table'
id = Column(Integer, primary_key=True)
name = Column(String)
pickle = Column(LargeBinary)
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
sample_data = [
User(name='Alice', pickle=b'pickle_data_alice'),
User(name='Bob', pickle=b'pickle_data_bob'),
User(name='Charlie', pickle=b'pickle_data_charlie')
]
session.add_all(sample_data)
session.commit()
result = session.query(User).filter_by(name='Bob').first()
return result
if __name__ == "__main__":
test_odps_with_sqlalchemy()
Error Log:
sqlalchemy.exc.StatementError: (builtins.AttributeError) module 'odps.dbapi' has no attribute 'Binary'
[SQL: INSERT INTO test_odps_table (name, pickle) VALUES (:name, :pickle)]
[parameters: [{'name': 'Alice', 'pickle': b'pickle_data_alice'}]]
Metadata
Metadata
Assignees
Labels
No labels