Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pl.write_database with adbc not writing to a specified schema #12803

Closed
2 tasks done
StuffbyYuki opened this issue Nov 30, 2023 · 4 comments
Closed
2 tasks done

pl.write_database with adbc not writing to a specified schema #12803

StuffbyYuki opened this issue Nov 30, 2023 · 4 comments
Labels
bug Something isn't working python Related to Python Polars

Comments

@StuffbyYuki
Copy link

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

# my dataframe
df = pl.DataFrame({'brand': ['Volvo', 'BMW', 'Toyota'], 'model': ['p1800', 'M1', 'Celica'], 'year': [1968, 1978, 1975]})

# this results in writing the dataframe to the public schema
df.write_database(table_name="sandbox.cars_output", connection=uri, engine="adbc", if_exists='replace')

Log output

No response

Issue description

When writing a dataframe to a Postgres database with pl.write_database using adbc, the specified schema don't get reflected in the result. It writes to the public schema instead. And the whole string I specify in the table_name parameter becomes the table name created in the public schema. But with sqlalchemy, it writes to the specified scheme with no problems.

image

Expected behavior

I expect the dataframe written to the specified schema, "sandbox", instead of the "public".

Installed versions

--------Version info---------
Polars:               0.19.17
Index type:           UInt32
Platform:             macOS-14.1.1-arm64-arm-64bit
Python:               3.11.3 (main, Apr 15 2023, 22:27:28) [Clang 14.0.3 (clang-1403.0.22.14.1)]

----Optional dependencies----
adbc_driver_manager:  0.7.0
cloudpickle:          <not installed>
connectorx:           0.3.2
deltalake:            0.12.0
fsspec:               2023.10.0
gevent:               <not installed>
matplotlib:           3.8.0
numpy:                1.26.1
openpyxl:             <not installed>
pandas:               2.1.1
pyarrow:              12.0.0
pydantic:             2.4.2
pyiceberg:            0.5.0
pyxlsb:               <not installed>
sqlalchemy:           2.0.22
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@StuffbyYuki StuffbyYuki added bug Something isn't working python Related to Python Polars labels Nov 30, 2023
@deanm0000
Copy link
Collaborator

This is probably an issue for adbc rather than polars.

That said I believe you can do what you need with

df.write_database(table_name="cars_output", connection=f"{uri}?currentSchema=sandbox", engine="adbc", if_exists='replace')

Citing this for that hint.

If your uri already has parameters then change my ? to a & alternatively you could use a library to make it more robust like this

@deanm0000
Copy link
Collaborator

@stinodego might be a close, not sure if polars wants to take this on or leave to adbc and possibly connectorx or leave to user to augment their conn string.

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Nov 30, 2023

I actually raised this issue with the adbc folks a while ago (end of September), and they have since both confirmed the bug and fixed it: apache/arrow-adbc#1109

If you install their recent 0.8.0 release (I see you're on 0.7.0) it'll work.

You should probably also update to the latest polars release 0.19.18, as I added some additional checks and affordances relating to adbc; for instance, if we see you relying on a db schema name with an adbc version below 0.8.0 we'll raise an error and tell you to go upgrade, eg:

ModuleNotFoundError("use of schema-qualified table names requires ADBC version >= 0.8, found 0.7.0")

@StuffbyYuki
Copy link
Author

@alexander-beedie Updated both versions and it works like a charm. Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

3 participants