cloe-nessy 0.3.9__py3-none-any.whl → 0.3.11.1b0__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.
- cloe_nessy/models/table.py +36 -7
- cloe_nessy/models/volume.py +35 -8
- {cloe_nessy-0.3.9.dist-info → cloe_nessy-0.3.11.1b0.dist-info}/METADATA +1 -1
- {cloe_nessy-0.3.9.dist-info → cloe_nessy-0.3.11.1b0.dist-info}/RECORD +6 -6
- {cloe_nessy-0.3.9.dist-info → cloe_nessy-0.3.11.1b0.dist-info}/WHEEL +0 -0
- {cloe_nessy-0.3.9.dist-info → cloe_nessy-0.3.11.1b0.dist-info}/top_level.txt +0 -0
cloe_nessy/models/table.py
CHANGED
|
@@ -12,6 +12,11 @@ from pydantic import (
|
|
|
12
12
|
model_validator,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
+
try:
|
|
16
|
+
from importlib.resources import files
|
|
17
|
+
except ImportError:
|
|
18
|
+
from importlib_resources import files # Python < 3.9 fallback
|
|
19
|
+
|
|
15
20
|
from ..logging import LoggerMixin
|
|
16
21
|
from ..utils.file_and_directory_handler import process_path
|
|
17
22
|
from .column import Column
|
|
@@ -234,16 +239,40 @@ class Table(TemplateLoaderMixin, ReadInstancesMixin, LoggerMixin):
|
|
|
234
239
|
|
|
235
240
|
def get_create_statement(
|
|
236
241
|
self,
|
|
237
|
-
templates: Path = Path("./src/cloe_nessy/models/templates/"),
|
|
238
|
-
template_name: str = "create_table.sql.j2",
|
|
239
242
|
replace: bool = True,
|
|
240
243
|
):
|
|
241
|
-
"""Get the create statement for the Table.
|
|
244
|
+
"""Get the create statement for the Table.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
replace: Whether to use the REPLACE statement or not.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
The rendered create statement for the Table.
|
|
251
|
+
|
|
252
|
+
Raises:
|
|
253
|
+
TemplateNotFound: If the template file is not found.
|
|
254
|
+
"""
|
|
255
|
+
# Use importlib.resources for robust template loading
|
|
242
256
|
try:
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
257
|
+
template_files = files("cloe_nessy.models") / "templates"
|
|
258
|
+
template_content = (template_files / "create_table.sql.j2").read_text()
|
|
259
|
+
|
|
260
|
+
# Create template directly from string content
|
|
261
|
+
from jinja2 import BaseLoader, Environment
|
|
262
|
+
|
|
263
|
+
env = Environment(loader=BaseLoader(), keep_trailing_newline=True)
|
|
264
|
+
template = env.from_string(template_content)
|
|
265
|
+
|
|
266
|
+
except (FileNotFoundError, AttributeError):
|
|
267
|
+
# Fallback to the old method if importlib.resources fails
|
|
268
|
+
templates = Path(__file__).parent / "templates"
|
|
269
|
+
template_name = "create_table.sql.j2"
|
|
270
|
+
try:
|
|
271
|
+
template = self.get_template(templates, template_name)
|
|
272
|
+
except TemplateNotFound as template_err:
|
|
273
|
+
self._console_logger.error(f"Template [ {template_name} ] not found.")
|
|
274
|
+
raise template_err
|
|
275
|
+
|
|
247
276
|
render = template.render(table=self, replace=replace)
|
|
248
277
|
return render
|
|
249
278
|
|
cloe_nessy/models/volume.py
CHANGED
|
@@ -4,6 +4,11 @@ from typing import Any
|
|
|
4
4
|
from jinja2 import TemplateNotFound
|
|
5
5
|
from pydantic import BaseModel, field_validator
|
|
6
6
|
|
|
7
|
+
try:
|
|
8
|
+
from importlib.resources import files
|
|
9
|
+
except ImportError:
|
|
10
|
+
from importlib_resources import files # Python < 3.9 fallback
|
|
11
|
+
|
|
7
12
|
from ..logging import LoggerMixin
|
|
8
13
|
from .mixins.template_loader_mixin import TemplateLoaderMixin
|
|
9
14
|
|
|
@@ -54,14 +59,36 @@ class Volume(TemplateLoaderMixin, LoggerMixin, BaseModel):
|
|
|
54
59
|
|
|
55
60
|
def get_create_statement(
|
|
56
61
|
self,
|
|
57
|
-
|
|
58
|
-
template_name: str = "create_volume.sql.j2",
|
|
62
|
+
if_not_exists: bool = True,
|
|
59
63
|
):
|
|
60
|
-
"""Get the create statement for the Volume.
|
|
64
|
+
"""Get the create statement for the Volume.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
if_not_exists: Whether to include the IF NOT EXISTS clause in the create statement
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
The rendered create statement as a string.
|
|
71
|
+
"""
|
|
72
|
+
# Use importlib.resources for robust template loading
|
|
61
73
|
try:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
template_files = files("cloe_nessy.models") / "templates"
|
|
75
|
+
template_content = (template_files / "create_volume.sql.j2").read_text()
|
|
76
|
+
|
|
77
|
+
# Create template directly from string content
|
|
78
|
+
from jinja2 import BaseLoader, Environment
|
|
79
|
+
|
|
80
|
+
env = Environment(loader=BaseLoader(), keep_trailing_newline=True)
|
|
81
|
+
template = env.from_string(template_content)
|
|
82
|
+
|
|
83
|
+
except (FileNotFoundError, AttributeError):
|
|
84
|
+
# Fallback to the old method if importlib.resources fails
|
|
85
|
+
template_name = "create_volume.sql.j2"
|
|
86
|
+
templates = Path(__file__).parent / "templates"
|
|
87
|
+
try:
|
|
88
|
+
template = self.get_template(templates, template_name)
|
|
89
|
+
except TemplateNotFound as template_err:
|
|
90
|
+
self._console_logger.error(f"Template [ {template_name} ] not found.")
|
|
91
|
+
raise template_err
|
|
92
|
+
|
|
93
|
+
render = template.render(volume=self, if_not_exists=if_not_exists)
|
|
67
94
|
return render
|
|
@@ -42,9 +42,9 @@ cloe_nessy/models/column.py,sha256=53fBwRnino72XKACsHZpN9QfCBqqSXyKLHZlM0huumg,1
|
|
|
42
42
|
cloe_nessy/models/constraint.py,sha256=hsFlhn4n928z81O3dl3v5bMetewPWzMjkJK3_4kASSM,178
|
|
43
43
|
cloe_nessy/models/foreign_key.py,sha256=DwRVHs9sShqqPV-NL7ow_3AmPPWX0Od26yZn_I565pU,1001
|
|
44
44
|
cloe_nessy/models/schema.py,sha256=yUrjjEhAH5zbCymE67Az_jPnVB8hGO-_UNfqzeZCD_Y,3376
|
|
45
|
-
cloe_nessy/models/table.py,sha256=
|
|
45
|
+
cloe_nessy/models/table.py,sha256=zw1Ika_dQCBNla60EGCo0PlkbLqJ1jp4orD28BLTV18,12861
|
|
46
46
|
cloe_nessy/models/types.py,sha256=XRbuJGdTNa6aXyE3IAzs_J9gVjbfkzMDLfGl-k6jI_4,223
|
|
47
|
-
cloe_nessy/models/volume.py,sha256=
|
|
47
|
+
cloe_nessy/models/volume.py,sha256=su_r0pzKf58qzkga9XJyObIb36V3_4rDWxc8fXbdS2U,3225
|
|
48
48
|
cloe_nessy/models/adapter/__init__.py,sha256=m36W_mqwB3dCYnCIt0fLOSHS4E1VU8FRGoaum4Gf95o,90
|
|
49
49
|
cloe_nessy/models/adapter/unity_catalog_adapter.py,sha256=a-14Ys-AevVYQd0xeJU1syLxjT5Wzo4uog1hFSEs76M,12651
|
|
50
50
|
cloe_nessy/models/mixins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -92,7 +92,7 @@ cloe_nessy/settings/__init__.py,sha256=ZbkneO3WaKOxon7qHFHnou7EnBOSnBFyKMDZblIEv
|
|
|
92
92
|
cloe_nessy/settings/settings.py,sha256=I4n129lrujriW-d8q4as2Kb4_kI932ModfZ5Ow_UpVM,3653
|
|
93
93
|
cloe_nessy/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
94
94
|
cloe_nessy/utils/file_and_directory_handler.py,sha256=r2EVt9xG81p6ScaJCwETC5an6pMT6WseB0jMOR-JlpU,602
|
|
95
|
-
cloe_nessy-0.3.
|
|
96
|
-
cloe_nessy-0.3.
|
|
97
|
-
cloe_nessy-0.3.
|
|
98
|
-
cloe_nessy-0.3.
|
|
95
|
+
cloe_nessy-0.3.11.1b0.dist-info/METADATA,sha256=ugc1ty-RCAN4gpYDV6l0iOldlxVnx0T61YsiSvPi4PM,3166
|
|
96
|
+
cloe_nessy-0.3.11.1b0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
97
|
+
cloe_nessy-0.3.11.1b0.dist-info/top_level.txt,sha256=Z7izn8HmQpg2wBUb-0jzaKlYKMU7Ypzuc9__9vPtW_I,11
|
|
98
|
+
cloe_nessy-0.3.11.1b0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|