Read from a SQL database. Builds the connection factory from connection_url.
(self, sql: str, connection_url: str, **kwargs)
| 250 | ) |
| 251 | |
| 252 | def read_sql(self, sql: str, connection_url: str, **kwargs) -> Any: |
| 253 | """Read from a SQL database. Builds the connection factory from connection_url.""" |
| 254 | import sqlalchemy |
| 255 | |
| 256 | def _connection_factory(): |
| 257 | # raw_connection() returns a DB API2-compliant connection (with .cursor()) |
| 258 | # from the underlying driver. engine.connect() returns a SQLAlchemy 2.0 |
| 259 | # Connection object which does NOT expose .cursor(), failing Ray Data's |
| 260 | # DB API2 compliance check. |
| 261 | return sqlalchemy.create_engine(connection_url).raw_connection() |
| 262 | |
| 263 | return ray.data.read_sql(sql, _connection_factory, **kwargs) |
| 264 | |
| 265 | def from_huggingface( |
| 266 | self, dataset_name: str, split: str = "train", **kwargs |
no outgoing calls