Skip to content

Allow ingesting in-memory file-like objects #435

Closed

Description

@dhirschfeld

Writing large amounts of data to disk, only for databricks-sql-connector to then read it back in from disk, is incredibly inefficient.

It would be much more efficient to be able to provide a file-like object to use instead of a filepath. In that way a user could write the data to an in-memory io.BytesIO object instead of writing the data to disk.

Activity

  1. dhirschfeld commented on Sep 2, 2024

    @dhirschfeld
    ContributorAuthor

    i.e. allow passing through fh rather than creating it internally by opening a file from the filesystem:

    def _handle_staging_put(
    self, presigned_url: str, local_file: str, headers: Optional[dict] = None
    ):
    """Make an HTTP PUT request
    Raise an exception if request fails. Returns no data.
    """
    if local_file is None:
    raise Error("Cannot perform PUT without specifying a local_file")
    with open(local_file, "rb") as fh:
    r = requests.put(url=presigned_url, data=fh, headers=headers)

  2. kravets-levko commented on Sep 4, 2024

    @kravets-levko
    Contributor

    Hi @dhirschfeld! This indeed sounds like an intersting feature, thank you for sharing it! I have to talk with the rest of team first. Databricks SQL GET and PUT commands should have local file path specified, but I don't know if we ever considered using streams instead of real files. If we agree that there are no risks with this approach - we would have to implement it across all drivers eventually

  3. susodapop commented on Sep 21, 2024

    @susodapop
    Contributor

    Some added context, @dhirschfeld's idea is exactly how the e2e tests for this feature behave (since we ran them in github actions where we don't have a real file system to write to). Should be a straightforward modification.

  4. gopalldb commented on Feb 27, 2025

    @gopalldb

    This is an interesting ask. We have implemented very similar solution in other SQL driver, should be able to port that solution here.

  5. jeffreyh1003 commented on Apr 25, 2025

    @jeffreyh1003

    +1 to OP's ask. This would be a huge win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions