databricks-sqlalchemy 2.0.6__py3-none-any.whl → 2.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,10 @@
1
1
  from databricks.sqlalchemy.base import DatabricksDialect
2
- from databricks.sqlalchemy._types import TINYINT, TIMESTAMP, TIMESTAMP_NTZ
2
+ from databricks.sqlalchemy._types import (
3
+ TINYINT,
4
+ TIMESTAMP,
5
+ TIMESTAMP_NTZ,
6
+ DatabricksArray,
7
+ DatabricksMap,
8
+ )
3
9
 
4
- __all__ = ["TINYINT", "TIMESTAMP", "TIMESTAMP_NTZ"]
10
+ __all__ = ["TINYINT", "TIMESTAMP", "TIMESTAMP_NTZ", "DatabricksArray", "DatabricksMap"]
@@ -5,6 +5,7 @@ from typing import Any, Union, Optional
5
5
  import sqlalchemy
6
6
  from sqlalchemy.engine.interfaces import Dialect
7
7
  from sqlalchemy.ext.compiler import compiles
8
+ from sqlalchemy.types import TypeDecorator, UserDefinedType
8
9
 
9
10
  from databricks.sql.utils import ParamEscaper
10
11
 
@@ -26,6 +27,11 @@ def process_literal_param_hack(value: Any):
26
27
  return value
27
28
 
28
29
 
30
+ def identity_processor(value):
31
+ """This method returns the value itself, when no other processor is provided"""
32
+ return value
33
+
34
+
29
35
  @compiles(sqlalchemy.types.Enum, "databricks")
30
36
  @compiles(sqlalchemy.types.String, "databricks")
31
37
  @compiles(sqlalchemy.types.Text, "databricks")
@@ -321,3 +327,73 @@ class TINYINT(sqlalchemy.types.TypeDecorator):
321
327
  @compiles(TINYINT, "databricks")
322
328
  def compile_tinyint(type_, compiler, **kw):
323
329
  return "TINYINT"
330
+
331
+
332
+ class DatabricksArray(UserDefinedType):
333
+ """
334
+ A custom array type that can wrap any other SQLAlchemy type.
335
+
336
+ Examples:
337
+ DatabricksArray(String) -> ARRAY<STRING>
338
+ DatabricksArray(Integer) -> ARRAY<INT>
339
+ DatabricksArray(CustomType) -> ARRAY<CUSTOM_TYPE>
340
+ """
341
+
342
+ def __init__(self, item_type):
343
+ self.item_type = item_type() if isinstance(item_type, type) else item_type
344
+
345
+ def bind_processor(self, dialect):
346
+ item_processor = self.item_type.bind_processor(dialect)
347
+ if item_processor is None:
348
+ item_processor = identity_processor
349
+
350
+ def process(value):
351
+ return [item_processor(val) for val in value]
352
+
353
+ return process
354
+
355
+
356
+ @compiles(DatabricksArray, "databricks")
357
+ def compile_databricks_array(type_, compiler, **kw):
358
+ inner = compiler.process(type_.item_type, **kw)
359
+
360
+ return f"ARRAY<{inner}>"
361
+
362
+
363
+ class DatabricksMap(UserDefinedType):
364
+ """
365
+ A custom map type that can wrap any other SQLAlchemy types for both key and value.
366
+
367
+ Examples:
368
+ DatabricksMap(String, String) -> MAP<STRING,STRING>
369
+ DatabricksMap(Integer, String) -> MAP<INT,STRING>
370
+ DatabricksMap(String, DatabricksArray(Integer)) -> MAP<STRING,ARRAY<INT>>
371
+ """
372
+
373
+ def __init__(self, key_type, value_type):
374
+ self.key_type = key_type() if isinstance(key_type, type) else key_type
375
+ self.value_type = value_type() if isinstance(value_type, type) else value_type
376
+
377
+ def bind_processor(self, dialect):
378
+ key_processor = self.key_type.bind_processor(dialect)
379
+ value_processor = self.value_type.bind_processor(dialect)
380
+
381
+ if key_processor is None:
382
+ key_processor = identity_processor
383
+ if value_processor is None:
384
+ value_processor = identity_processor
385
+
386
+ def process(value):
387
+ return {
388
+ key_processor(key): value_processor(value)
389
+ for key, value in value.items()
390
+ }
391
+
392
+ return process
393
+
394
+
395
+ @compiles(DatabricksMap, "databricks")
396
+ def compile_databricks_map(type_, compiler, **kw):
397
+ key_type = compiler.process(type_.key_type, **kw)
398
+ value_type = compiler.process(type_.value_type, **kw)
399
+ return f"MAP<{key_type},{value_type}>"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: databricks-sqlalchemy
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: Databricks SQLAlchemy plugin for Python
5
5
  License: Apache-2.0
6
6
  Author: Databricks
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
16
17
  Requires-Dist: databricks_sql_connector (>=4.0.0)
17
18
  Requires-Dist: pyarrow (>=14.0.1)
18
19
  Requires-Dist: sqlalchemy (>=2.0.21)
@@ -1,16 +1,15 @@
1
- CHANGELOG.md,sha256=Ori6lzXX6BXNIV_wJHOpyCVAKakZ9v-SF9mem6hWbpo,437
2
1
  databricks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- databricks/sqlalchemy/__init__.py,sha256=Gk3XC5OCzq7LuxMVpxK3t4q0rkflXJ8uJRJh9uusMqc,185
2
+ databricks/sqlalchemy/__init__.py,sha256=IL3_QTbL9vbdQQ09Dzrol352VXU8v3oUilpiCkjvxQw,278
4
3
  databricks/sqlalchemy/_ddl.py,sha256=c0_GwfmnrFVr4-Ls14fmdGUUFyUok_GW4Uo45hLABFc,3983
5
4
  databricks/sqlalchemy/_parse.py,sha256=aFpwcLowSDP1R7BY3G-yuEXiPFL-_VaIGvqKNDMehcQ,13049
6
- databricks/sqlalchemy/_types.py,sha256=EqC_TWWY7mDw9EM2AVZnPrw5DD6G-vBV7wiwX4tcBcM,11753
5
+ databricks/sqlalchemy/_types.py,sha256=nESbFFzf0qFYyomOOBnCAvRB710ABkPgxWMu7qc3mvw,14216
7
6
  databricks/sqlalchemy/base.py,sha256=KcjfHMH0NsceYE2NRxrePtf5T1uw9u8JHofRdbnAKS4,15619
8
7
  databricks/sqlalchemy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
8
  databricks/sqlalchemy/pytest.ini,sha256=ImutflUjkhByVNWCQ18Todj6XTvgJAQX_v7fD-gWHhU,106
10
9
  databricks/sqlalchemy/requirements.py,sha256=OobunAEwZ9y2dvSQLOmdgJciVn9xGlY9NAFfszPCTU0,9018
11
10
  databricks/sqlalchemy/setup.cfg,sha256=ImutflUjkhByVNWCQ18Todj6XTvgJAQX_v7fD-gWHhU,106
12
- databricks_sqlalchemy-2.0.6.dist-info/LICENSE,sha256=WgVm2VpfZ3CsUfPndD2NeCrEIcFA4UB-YnnW4ejxcbE,11346
13
- databricks_sqlalchemy-2.0.6.dist-info/METADATA,sha256=ygeVUTl8NOqDTSL-J_CfbRENE4T6eIWOOEVnGCD8lYU,12713
14
- databricks_sqlalchemy-2.0.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
- databricks_sqlalchemy-2.0.6.dist-info/entry_points.txt,sha256=AAjpsvZbVcoMAcWLIesoAT5FNZhBEcIhxdKknVua3jw,74
16
- databricks_sqlalchemy-2.0.6.dist-info/RECORD,,
11
+ databricks_sqlalchemy-2.0.7.dist-info/LICENSE,sha256=WgVm2VpfZ3CsUfPndD2NeCrEIcFA4UB-YnnW4ejxcbE,11346
12
+ databricks_sqlalchemy-2.0.7.dist-info/METADATA,sha256=QIT9EVR2yGQy5N5Z8uDJ9TaMw0li8OXZ1PAS-U2WB5I,12764
13
+ databricks_sqlalchemy-2.0.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
14
+ databricks_sqlalchemy-2.0.7.dist-info/entry_points.txt,sha256=AAjpsvZbVcoMAcWLIesoAT5FNZhBEcIhxdKknVua3jw,74
15
+ databricks_sqlalchemy-2.0.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
CHANGELOG.md DELETED
@@ -1,14 +0,0 @@
1
- # Release History
2
-
3
- # 2.0.6 (2025-04-29)
4
-
5
- - Relaxed pin for `pyarrow` (databricks/databricks-sqlalchemy#20 by @dhirschfeld)
6
-
7
- # 2.0.5 (2025-02-22)
8
-
9
- - Added support for double column types (databricks/databricks-sqlalchemy#19 by @up-stevesloan)
10
-
11
- # 2.0.4 (2025-01-27)
12
-
13
- - All the SQLAlchemy features from `databricks-sql-connector>=4.0.0` have been moved to this `databricks-sqlalchemy` library
14
- - Support for SQLAlchemy v2 dialect is provided