|
| 1 | +from databricks import sql |
| 2 | +from typing import AnyStr |
| 3 | + |
| 4 | +from sqlalchemy import types |
| 5 | +from sqlalchemy import util |
| 6 | + |
| 7 | +from sqlalchemy.engine import default |
| 8 | + |
| 9 | + |
| 10 | +class DatabricksDialect(default.DefaultDialect): |
| 11 | + |
| 12 | + # Possible attributes are defined here: https://docs.sqlalchemy.org/en/14/core/internals.html#sqlalchemy.engine.Dialect |
| 13 | + name: str = "databricks" |
| 14 | + driver: str= "thrift" |
| 15 | + default_schema_name: str = "default" |
| 16 | + |
| 17 | + @classmethod |
| 18 | + def dbapi(cls): |
| 19 | + return sql |
| 20 | + |
| 21 | + def create_connect_args(self, url): |
| 22 | + # Expected URI format is: databricks+thrift://token:dapi***@***.cloud.databricks.com?http_path=/sql/*** |
| 23 | + |
| 24 | + kwargs = { |
| 25 | + "server_hostname": url.host, |
| 26 | + "access_token": url.password, |
| 27 | + "http_path": url.query.get("http_path") |
| 28 | + } |
| 29 | + |
| 30 | + return [], kwargs |
| 31 | + |
| 32 | + def get_table_names(self, *args, **kwargs): |
| 33 | + |
| 34 | + # TODO: Implement with native driver `.tables()` call |
| 35 | + return super().get_table_names(*args, **kwargs) |
| 36 | + |
| 37 | + def get_columns(self, *args, **kwargs): |
| 38 | + |
| 39 | + # TODO: Implement with native driver `.columns()` call |
| 40 | + |
| 41 | + return super().get_columns(*args, **kwargs) |
| 42 | + |
| 43 | + def do_rollback(self, dbapi_connection): |
| 44 | + # Databricks SQL Does not support transaction |
| 45 | + pass |
0 commit comments