Comments (7)
What about session.connection()
does that work?
from polars.
What about if you pass it the engine instead of the season?
from polars.
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.
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.
I'll look at handling this more gracefully so it "just works".
Will re-open and assign myself as a reminder ;)
from polars.
session.connection()
works!!
Thanks for the feedback. It's always appreciated when people let me know my suggestions work and are helpful.
from polars.
@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)
- Wrong results from `floordiv` HOT 9
- Wrong polars dtype for empty Series HOT 4
- `from_pandas` incorrect type for all null columns HOT 1
- partition_by on LazyFrame HOT 3
- `str.split` by an empty string produces incorrect results HOT 10
- Deprecate `str.explode`
- `Array` columns not supported by `extend()`
- Write support for Apache Iceberg HOT 2
- Linting error on `pl.read_csv(...)`: `Argument of type "IO[bytes]"` incompatible with `str | TextIO | BytesIO | Path | BinaryIO | bytes` HOT 4
- Pivot fail when one of the index columns is a list - regression from 0.20.6 HOT 7
- Improve documentation for floordiv
- read_csv issues a misleading warning when using non-utf8 encoding and glob pattern HOT 2
- len/count regression since 0.20.6 - 11x times slower in sample HOT 5
- df.assert_schema(expected_schema) HOT 5
- Allow not using cloudpickle in LazyFrame.serialize() HOT 1
- LazyFrame.deserialize() should document the security implications HOT 2
- `FromIterator` for `Series` should extend to `Option<String>` and `Option<&'a str>`
- Initialize `LazyFrame` from `LazyFrame` HOT 4
- Saving parquet to Google Cloud Storage with `df.write_parquet()` HOT 2
- Make `read_database` and `read_database_uri` consistent
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polars.