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

COPY INTO FROM ON CLIENT #102

Merged
merged 93 commits into from
Apr 12, 2022
Merged

COPY INTO FROM ON CLIENT #102

merged 93 commits into from
Apr 12, 2022

Conversation

joerivanruth
Copy link
Member

This work is not finished but I'm creating the pull request so you can keep an eye on it and make suggestions, and also to benefit from the CI. The idea is to add support for ON CLIENT. For example:

COPY INTO mytable FROM 'data.csv' ON CLIENT;

With ON CLIENT, the server does not open the the file by itself but sends a request to pymonetdb to open it on its behalf. The client opens the file and reads it, or makes up some data on the spot, and sends it to the server which processes it as usual.

ON CLIENT is useful to avoid having to first copy data to a location on the server accessible both to the user and the server, and for side stepping all sorts of permissions problems. Mclient has supported it for quite a while and recently I added support to monetdb-jdbc. Now I would like to add support for it to pymonetdb.

@joerivanruth joerivanruth marked this pull request as ready for review April 1, 2022 14:57
doc/examples/uploadsafe.py Outdated Show resolved Hide resolved
pymonetdb/filetransfer.py Outdated Show resolved Hide resolved
mapi._putblock(f"Invalid file transfer command: {cmd!r}")


def handle_upload(mapi, filename, text_mode, offset):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing type annotations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added a whole bunch of additional type annotations.
Not easy because the IO types don't type annotate well.
In particular, for some reason a BufferedIOBase is not accepted as an IO[bytes].

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, is this with all python versions?

pymonetdb/filetransfer.py Outdated Show resolved Hide resolved
pymonetdb/filetransfer.py Outdated Show resolved Hide resolved
pymonetdb/filetransfer.py Outdated Show resolved Hide resolved
pymonetdb/filetransfer.py Outdated Show resolved Hide resolved
pymonetdb/filetransfer.py Outdated Show resolved Hide resolved
tests/requirements.txt Show resolved Hide resolved
tests/util.py Show resolved Hide resolved
@gijzelaerr
Copy link
Collaborator

I just had a quick scan of the code, first impression is that It looks good, but i need to look better at the logic at some point.

My first biggest comment is:

  • Type annotations are missing on many locations, we should be adding them for all new code since the static code analysis with mypy will for sure find subtle bugs.
  • Maybe split up the filetransfer file into a module and a bunch of files for easier navigation and readability


from io import BufferedIOBase, BufferedWriter, RawIOBase, TextIOBase, TextIOWrapper
from typing import Any, Optional, Union
from pymonetdb import mapi as mapi_protocol
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just do from pymonetdb.mapi import Connection and use that as type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gave circular import problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants