Giter Site home page Giter Site logo

Comments (7)

deanm0000 avatar deanm0000 commented on June 19, 2024 1

What about session.connection() does that work?

from polars.

deanm0000 avatar deanm0000 commented on June 19, 2024

What about if you pass it the engine instead of the season?

from polars.

WilliamStam avatar WilliamStam commented on June 19, 2024

passing the engine in works!

df = polars.read_database(query, connection=engine)

i really thought i was being clever with this issue :P but alas...


with engine however, we loose some stuff by letting polars handle the session. in my use-case i set the schema session.execute(text(f"ALTER SESSION SET CURRENT_SCHEMA = MY_SCHEMA")) for oracle and log connections. im guessing you also wont be able to use connection pools then?

seems self.result._metadata.keys works for both as well tho.

from polars.

WilliamStam avatar WilliamStam commented on June 19, 2024

got to love sqlalchemy <3 like a billion things for slightly different purposes but essentially very similar

session.connection() works!!

import polars

from sqlalchemy import create_engine, text, String, Integer, select
from sqlalchemy.orm import sessionmaker, mapped_column, Mapped, DeclarativeBase


class Base(DeclarativeBase):
    pass

class SourceTable(Base):
    __tablename__ = "TABLE"


    UPD_SEQ: Mapped[int] = mapped_column(Integer, primary_key=True)
    UPD_VERS1: Mapped[str] = mapped_column(String(2), nullable=True)
    UPD_VERS2: Mapped[str] = mapped_column(String(2), nullable=True)
    UPD_VERS3: Mapped[str] = mapped_column(String(2), nullable=True)


engine = create_engine('oracle+oracledb://***:***@***/***',echo=True)
session_maker = sessionmaker(bind=engine)
session = session_maker()

session.execute(text(f"ALTER SESSION SET CURRENT_SCHEMA = ***"))

query = select(*[
    SourceTable.UPD_SEQ,
    SourceTable.UPD_VERS1,
    SourceTable.UPD_VERS2,
])
query = query.limit(10).offset(0)
query = query.filter(SourceTable.UPD_SEQ > 10)

df = polars.read_database(query, connection=session.connection())
print(df)

the type for connection shows as wrong (it did the same with just session. but was happy with engine)

Expected type 'BasicConnection | BasicCursor | Cursor | Engine | str', got 'Connection' instead

dudethem.. you rock!

from polars.

alexander-beedie avatar alexander-beedie commented on June 19, 2024

I'll look at handling this more gracefully so it "just works".
Will re-open and assign myself as a reminder ;)

from polars.

deanm0000 avatar deanm0000 commented on June 19, 2024

session.connection() works!!

Thanks for the feedback. It's always appreciated when people let me know my suggestions work and are helpful.

from polars.

alexander-beedie avatar alexander-beedie commented on June 19, 2024

@WilliamStam: your query should work in the next release without any modification (keep an eye out for the imminent 0.20.10) 👌

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.