pytrilogy 0.0.3.10__py3-none-any.whl → 0.0.3.11__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.
Potentially problematic release.
This version of pytrilogy might be problematic. Click here for more details.
- {pytrilogy-0.0.3.10.dist-info → pytrilogy-0.0.3.11.dist-info}/METADATA +1 -1
- {pytrilogy-0.0.3.10.dist-info → pytrilogy-0.0.3.11.dist-info}/RECORD +18 -17
- trilogy/__init__.py +1 -1
- trilogy/authoring/__init__.py +8 -1
- trilogy/core/models/environment.py +18 -3
- trilogy/core/processing/nodes/group_node.py +1 -1
- trilogy/dialect/bigquery.py +2 -3
- trilogy/dialect/duckdb.py +2 -2
- trilogy/dialect/enums.py +5 -0
- trilogy/dialect/presto.py +1 -1
- trilogy/dialect/sql_server.py +1 -1
- trilogy/executor.py +2 -34
- trilogy/parsing/parse_engine.py +35 -8
- trilogy/render.py +38 -0
- {pytrilogy-0.0.3.10.dist-info → pytrilogy-0.0.3.11.dist-info}/LICENSE.md +0 -0
- {pytrilogy-0.0.3.10.dist-info → pytrilogy-0.0.3.11.dist-info}/WHEEL +0 -0
- {pytrilogy-0.0.3.10.dist-info → pytrilogy-0.0.3.11.dist-info}/entry_points.txt +0 -0
- {pytrilogy-0.0.3.10.dist-info → pytrilogy-0.0.3.11.dist-info}/top_level.txt +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
trilogy/__init__.py,sha256=
|
|
1
|
+
trilogy/__init__.py,sha256=M6pFqPgs_BEva-ceDAVIDbK_Am1BozUgGDoN-z6dnrk,303
|
|
2
2
|
trilogy/compiler.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
trilogy/constants.py,sha256=qZ1d0hoKPPV2HHCoFwPYTVB7b6bXjpWvXd3lE-zEhy8,1494
|
|
4
4
|
trilogy/engine.py,sha256=3etkm2RSVKO0IkgPKkrcs33X5gN_fIMyqMNfChcsR1E,1318
|
|
5
|
-
trilogy/executor.py,sha256=
|
|
5
|
+
trilogy/executor.py,sha256=CU-T7hl5hQab17KkJz9XhwlyI4-7MQL-JGdTDMVsE4E,16025
|
|
6
6
|
trilogy/parser.py,sha256=o4cfk3j3yhUFoiDKq9ZX_GjBF3dKhDjXEwb63rcBkBM,293
|
|
7
7
|
trilogy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
trilogy/render.py,sha256=D6rI1RNtn0StJeSe4e18lnlc-U--cNu4lh5C_NkU_uM,1218
|
|
8
9
|
trilogy/utility.py,sha256=euQccZLKoYBz0LNg5tzLlvv2YHvXh9HArnYp1V3uXsM,763
|
|
9
|
-
trilogy/authoring/__init__.py,sha256=
|
|
10
|
+
trilogy/authoring/__init__.py,sha256=6KPn4uoPb_7t-i510M8UNXB7nrPpaKlxAXwuRbWBdLE,2115
|
|
10
11
|
trilogy/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
12
|
trilogy/core/constants.py,sha256=7XaCpZn5mQmjTobbeBn56SzPWq9eMNDfzfsRU-fP0VE,171
|
|
12
13
|
trilogy/core/enums.py,sha256=jOgUyoLGgC5-8SLBWP0jQDMxptBJbN0J48VsCa1EMYo,7111
|
|
@@ -25,7 +26,7 @@ trilogy/core/models/build.py,sha256=bO1qYvuGl6LeNGgsfS6ZHAzZBR2lBPLg-QJymp9hgkU,
|
|
|
25
26
|
trilogy/core/models/build_environment.py,sha256=8UggvlPU708GZWYPJMc_ou2r7M3TY2g69eqGvz03YX0,5528
|
|
26
27
|
trilogy/core/models/core.py,sha256=00opIUXwgJy9OF-cwI883zQpArNeh6wkTpSqUszDU78,9909
|
|
27
28
|
trilogy/core/models/datasource.py,sha256=6RjJUd2u4nYmEwFBpJlM9LbHVYDv8iHJxqiBMZqUrwI,9422
|
|
28
|
-
trilogy/core/models/environment.py,sha256=
|
|
29
|
+
trilogy/core/models/environment.py,sha256=WCVJNWUze37bxFSFWo_6Z7330OG5k0DDmb7a2Tz5gg4,26264
|
|
29
30
|
trilogy/core/models/execute.py,sha256=ABylFQgtavjjCfFkEsFdUwfMB4UBQLHjdzQ9E67QlAE,33521
|
|
30
31
|
trilogy/core/optimizations/__init__.py,sha256=EBanqTXEzf1ZEYjAneIWoIcxtMDite5-n2dQ5xcfUtg,356
|
|
31
32
|
trilogy/core/optimizations/base_optimization.py,sha256=gzDOKImoFn36k7XBD3ysEYDnbnb6vdVIztUfFQZsGnM,513
|
|
@@ -56,7 +57,7 @@ trilogy/core/processing/node_generators/select_helpers/datasource_injection.py,s
|
|
|
56
57
|
trilogy/core/processing/nodes/__init__.py,sha256=DqPG3Y8vl5-UTeox6hn1EE6iwPIJpsM-XeZALHSgLZQ,5058
|
|
57
58
|
trilogy/core/processing/nodes/base_node.py,sha256=FHrY8GsTKPuMJklOjILbhGqCt5s1nmlj62Z-molARDA,16835
|
|
58
59
|
trilogy/core/processing/nodes/filter_node.py,sha256=5VtRfKbCORx0dV-vQfgy3gOEkmmscL9f31ExvlODwvY,2461
|
|
59
|
-
trilogy/core/processing/nodes/group_node.py,sha256=
|
|
60
|
+
trilogy/core/processing/nodes/group_node.py,sha256=1caU36nHknnXS-dM6xmL9Mc7kK0wCq-IS3kL7_XYNlA,8024
|
|
60
61
|
trilogy/core/processing/nodes/merge_node.py,sha256=bEz1QU2o-fl_O-VotE5dN1GmlZPClufMvUOvL2-2Uo8,15262
|
|
61
62
|
trilogy/core/processing/nodes/select_node_v2.py,sha256=Xyfq8lU7rP7JTAd8VV0ATDNal64n4xIBgWQsOuMe_Ak,8824
|
|
62
63
|
trilogy/core/processing/nodes/union_node.py,sha256=fDFzLAUh5876X6_NM7nkhoMvHEdGJ_LpvPokpZKOhx4,1425
|
|
@@ -69,16 +70,16 @@ trilogy/core/statements/common.py,sha256=KxEmz2ySySyZ6CTPzn0fJl5NX2KOk1RPyuUSwWh
|
|
|
69
70
|
trilogy/core/statements/execute.py,sha256=cSlvpHFOqpiZ89pPZ5GDp9Hu6j6uj-5_h21FWm_L-KM,1248
|
|
70
71
|
trilogy/dialect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
71
72
|
trilogy/dialect/base.py,sha256=gEbbqll98nfhxs_JWK0h_9M9fh4nWnon2Ntlxp_s_lI,40287
|
|
72
|
-
trilogy/dialect/bigquery.py,sha256=
|
|
73
|
+
trilogy/dialect/bigquery.py,sha256=PkjFcNGZHYOe655PmJhb8a0afdFULuovqP0qQVO8m0I,2953
|
|
73
74
|
trilogy/dialect/common.py,sha256=cbTo_vamdp8pj9spSjGSH-bSZpy4FpNJ12k5vMvyT2Y,3942
|
|
74
75
|
trilogy/dialect/config.py,sha256=EGYRQIbrkeMuud5Bkds7jSD5dCJR5hEYZUYcy-lYZl4,3308
|
|
75
76
|
trilogy/dialect/dataframe.py,sha256=RUbNgReEa9g3pL6H7fP9lPTrAij5pkqedpZ99D8_5AE,1522
|
|
76
|
-
trilogy/dialect/duckdb.py,sha256=
|
|
77
|
-
trilogy/dialect/enums.py,sha256=
|
|
77
|
+
trilogy/dialect/duckdb.py,sha256=7f4qzNKXnpXA9wkU2ouarB5u2tpBC51TwLyGmN3bEG8,3693
|
|
78
|
+
trilogy/dialect/enums.py,sha256=QYIcVr5RgpYMA1Wl0nWeojVVxJxy0V2_sn8uqSFNx20,4615
|
|
78
79
|
trilogy/dialect/postgres.py,sha256=VH4EB4myjIeZTHeFU6vK00GxY9c53rCBjg2mLbdaCEE,3254
|
|
79
|
-
trilogy/dialect/presto.py,sha256=
|
|
80
|
+
trilogy/dialect/presto.py,sha256=Mw7_F8h19mWfuZHkHQJizQWbpu1lIHe6t2PA0r88gsY,3392
|
|
80
81
|
trilogy/dialect/snowflake.py,sha256=wmao9p26jX5yIX5SC8sRAZTXkPGTvq6ixO693QTfhz8,2989
|
|
81
|
-
trilogy/dialect/sql_server.py,sha256=
|
|
82
|
+
trilogy/dialect/sql_server.py,sha256=z2Vg7Qvw83rbGiEFIvHHLqVWJTWiz2xs76kpQj4HdTU,3131
|
|
82
83
|
trilogy/hooks/__init__.py,sha256=T3SF3phuUDPLXKGRVE_Lf9mzuwoXWyaLolncR_1kY30,144
|
|
83
84
|
trilogy/hooks/base_hook.py,sha256=I_l-NBMNC7hKTDx1JgHZPVOOCvLQ36m2oIGaR5EUMXY,1180
|
|
84
85
|
trilogy/hooks/graph_hook.py,sha256=c-vC-IXoJ_jDmKQjxQyIxyXPOuUcLIURB573gCsAfzQ,2940
|
|
@@ -89,14 +90,14 @@ trilogy/parsing/common.py,sha256=IgZ2K3LzJ0usLIwxRCRmS-4luP6uwmM-f1oqGNyGbm0,213
|
|
|
89
90
|
trilogy/parsing/config.py,sha256=Z-DaefdKhPDmSXLgg5V4pebhSB0h590vI0_VtHnlukI,111
|
|
90
91
|
trilogy/parsing/exceptions.py,sha256=92E5i2frv5hj9wxObJZsZqj5T6bglvPzvdvco_vW1Zk,38
|
|
91
92
|
trilogy/parsing/helpers.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
92
|
-
trilogy/parsing/parse_engine.py,sha256=
|
|
93
|
+
trilogy/parsing/parse_engine.py,sha256=YjYe4cAxek3CceewGI1It-XEO_ZygCxY9IQzcJw0Y0Y,57555
|
|
93
94
|
trilogy/parsing/render.py,sha256=o_XuQWhcwx1lD9eGVqkqZEwkmQK0HdmWWokGBtdeH4I,17837
|
|
94
95
|
trilogy/parsing/trilogy.lark,sha256=zehaPaYKuJZQ335sgCjH8Q6u_hy5A6A02XcdwziZdWE,12817
|
|
95
96
|
trilogy/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
96
97
|
trilogy/scripts/trilogy.py,sha256=1L0XrH4mVHRt1C9T1HnaDv2_kYEfbWTb5_-cBBke79w,3774
|
|
97
|
-
pytrilogy-0.0.3.
|
|
98
|
-
pytrilogy-0.0.3.
|
|
99
|
-
pytrilogy-0.0.3.
|
|
100
|
-
pytrilogy-0.0.3.
|
|
101
|
-
pytrilogy-0.0.3.
|
|
102
|
-
pytrilogy-0.0.3.
|
|
98
|
+
pytrilogy-0.0.3.11.dist-info/LICENSE.md,sha256=5ZRvtTyCCFwz1THxDTjAu3Lidds9WjPvvzgVwPSYNDo,1042
|
|
99
|
+
pytrilogy-0.0.3.11.dist-info/METADATA,sha256=xvuxEQpZ1puSOIBOM0_U1luF8pheKHrLQnTP3YDj-jA,8984
|
|
100
|
+
pytrilogy-0.0.3.11.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
101
|
+
pytrilogy-0.0.3.11.dist-info/entry_points.txt,sha256=0petKryjvvtEfTlbZC1AuMFumH_WQ9v8A19LvoS6G6c,54
|
|
102
|
+
pytrilogy-0.0.3.11.dist-info/top_level.txt,sha256=cAy__NW_eMAa_yT9UnUNlZLFfxcg6eimUAZ184cdNiE,8
|
|
103
|
+
pytrilogy-0.0.3.11.dist-info/RECORD,,
|
trilogy/__init__.py
CHANGED
trilogy/authoring/__init__.py
CHANGED
|
@@ -33,7 +33,13 @@ from trilogy.core.models.author import (
|
|
|
33
33
|
WindowOrder,
|
|
34
34
|
WindowType,
|
|
35
35
|
)
|
|
36
|
-
from trilogy.core.models.core import
|
|
36
|
+
from trilogy.core.models.core import (
|
|
37
|
+
DataType,
|
|
38
|
+
ListType,
|
|
39
|
+
ListWrapper,
|
|
40
|
+
MapType,
|
|
41
|
+
StructType,
|
|
42
|
+
)
|
|
37
43
|
from trilogy.core.models.environment import Environment
|
|
38
44
|
from trilogy.core.statements.author import (
|
|
39
45
|
ConceptDeclarationStatement,
|
|
@@ -63,6 +69,7 @@ __all__ = [
|
|
|
63
69
|
"DataType",
|
|
64
70
|
"StructType",
|
|
65
71
|
"ListType",
|
|
72
|
+
"MapType",
|
|
66
73
|
"ListWrapper",
|
|
67
74
|
"FunctionType",
|
|
68
75
|
"FunctionFactory",
|
|
@@ -60,8 +60,23 @@ class Import:
|
|
|
60
60
|
path: Path
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
class BaseImportResolver(BaseModel):
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class FileSystemImportResolver(BaseImportResolver):
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class DictImportResolver(BaseImportResolver):
|
|
72
|
+
content: Dict[str, str]
|
|
73
|
+
|
|
74
|
+
|
|
63
75
|
class EnvironmentOptions(BaseModel):
|
|
64
76
|
allow_duplicate_declaration: bool = True
|
|
77
|
+
import_resolver: BaseImportResolver = Field(
|
|
78
|
+
default_factory=FileSystemImportResolver
|
|
79
|
+
)
|
|
65
80
|
|
|
66
81
|
|
|
67
82
|
class EnvironmentConceptDict(dict):
|
|
@@ -199,7 +214,7 @@ class Environment(BaseModel):
|
|
|
199
214
|
)
|
|
200
215
|
namespace: str = DEFAULT_NAMESPACE
|
|
201
216
|
working_path: str | Path = Field(default_factory=lambda: os.getcwd())
|
|
202
|
-
|
|
217
|
+
config: EnvironmentOptions = Field(default_factory=EnvironmentOptions)
|
|
203
218
|
version: str = Field(default_factory=get_version)
|
|
204
219
|
cte_name_map: Dict[str, str] = Field(default_factory=dict)
|
|
205
220
|
materialized_concepts: set[str] = Field(default_factory=set)
|
|
@@ -234,7 +249,7 @@ class Environment(BaseModel):
|
|
|
234
249
|
imports=dict(self.imports),
|
|
235
250
|
namespace=self.namespace,
|
|
236
251
|
working_path=self.working_path,
|
|
237
|
-
environment_config=self.
|
|
252
|
+
environment_config=self.config,
|
|
238
253
|
version=self.version,
|
|
239
254
|
cte_name_map=dict(self.cte_name_map),
|
|
240
255
|
materialized_concepts=set(self.materialized_concepts),
|
|
@@ -342,7 +357,7 @@ class Environment(BaseModel):
|
|
|
342
357
|
|
|
343
358
|
return None
|
|
344
359
|
|
|
345
|
-
if existing and self.
|
|
360
|
+
if existing and self.config.allow_duplicate_declaration:
|
|
346
361
|
if existing.metadata.concept_source == ConceptSource.PERSIST_STATEMENT:
|
|
347
362
|
return handle_persist()
|
|
348
363
|
return
|
|
@@ -92,7 +92,7 @@ class GroupNode(StrategyNode):
|
|
|
92
92
|
comp_grain += source.grain
|
|
93
93
|
for x in source.output_concepts:
|
|
94
94
|
concept_map[x.address] = x
|
|
95
|
-
lookups = [
|
|
95
|
+
lookups: list[BuildConcept | str] = [
|
|
96
96
|
concept_map[x] if x in concept_map else x for x in comp_grain.components
|
|
97
97
|
]
|
|
98
98
|
comp_grain = BuildGrain.from_concepts(lookups, environment=environment)
|
trilogy/dialect/bigquery.py
CHANGED
|
@@ -42,10 +42,9 @@ CREATE OR REPLACE TABLE {{ output.address.location }} AS
|
|
|
42
42
|
{% endif %}{%- if ctes %}
|
|
43
43
|
WITH {% for cte in ctes %}
|
|
44
44
|
{{cte.name}} as ({{cte.statement}}){% if not loop.last %},{% endif %}{% endfor %}{% endif %}
|
|
45
|
-
{%- if full_select
|
|
45
|
+
{%- if full_select -%}
|
|
46
46
|
{{full_select}}
|
|
47
|
-
{
|
|
48
|
-
|
|
47
|
+
{%- else -%}
|
|
49
48
|
SELECT
|
|
50
49
|
{%- for select in select_columns %}
|
|
51
50
|
{{ select }}{% if not loop.last %},{% endif %}{% endfor %}
|
trilogy/dialect/duckdb.py
CHANGED
|
@@ -57,8 +57,8 @@ CREATE OR REPLACE TABLE {{ output.address.location }} AS
|
|
|
57
57
|
WITH {% for cte in ctes %}
|
|
58
58
|
{{cte.name}} as ({{cte.statement}}){% if not loop.last %},{% endif %}{% endfor %}{% endif %}
|
|
59
59
|
{%- if full_select -%}{{full_select}}
|
|
60
|
-
{%- else -%}{%- if comment
|
|
61
|
-
-- {{ comment }}{
|
|
60
|
+
{%- else -%}{%- if comment -%}
|
|
61
|
+
-- {{ comment }}{%- endif -%}
|
|
62
62
|
SELECT
|
|
63
63
|
{%- for select in select_columns %}
|
|
64
64
|
{{ select }}{% if not loop.last %},{% endif %}{% endfor %}
|
trilogy/dialect/enums.py
CHANGED
|
@@ -41,6 +41,11 @@ class Dialects(Enum):
|
|
|
41
41
|
return cls.DUCK_DB
|
|
42
42
|
return super()._missing_(value)
|
|
43
43
|
|
|
44
|
+
def default_renderer(self, conf=None, _engine_factory: Callable = default_factory):
|
|
45
|
+
from trilogy.render import get_dialect_generator
|
|
46
|
+
|
|
47
|
+
return get_dialect_generator(self)
|
|
48
|
+
|
|
44
49
|
def default_engine(self, conf=None, _engine_factory: Callable = default_factory):
|
|
45
50
|
if self == Dialects.BIGQUERY:
|
|
46
51
|
from google.auth import default
|
trilogy/dialect/presto.py
CHANGED
|
@@ -50,7 +50,7 @@ WITH {% for cte in ctes %}
|
|
|
50
50
|
{{cte.name}} as ({{cte.statement}}){% if not loop.last %},{% endif %}{% endfor %}{% endif %}
|
|
51
51
|
{%- if full_select -%}
|
|
52
52
|
{{full_select}}
|
|
53
|
-
{%- else
|
|
53
|
+
{%- else -%}
|
|
54
54
|
SELECT
|
|
55
55
|
{%- for select in select_columns %}
|
|
56
56
|
{{ select }}{% if not loop.last %},{% endif %}{% endfor %}
|
trilogy/dialect/sql_server.py
CHANGED
|
@@ -42,7 +42,7 @@ WITH {% for cte in ctes %}
|
|
|
42
42
|
{{cte.name}} as ({{cte.statement}}){% if not loop.last %},{% endif %}{% endfor %}{% endif %}
|
|
43
43
|
{%- if full_select -%}{{full_select}}
|
|
44
44
|
{%- else -%}{%- if comment %}
|
|
45
|
-
-- {{ comment }}{
|
|
45
|
+
-- {{ comment }}{%- endif -%}
|
|
46
46
|
SELECT
|
|
47
47
|
{%- if limit is not none %}
|
|
48
48
|
TOP {{ limit }}{% endif %}
|
trilogy/executor.py
CHANGED
|
@@ -36,6 +36,7 @@ from trilogy.dialect.enums import Dialects
|
|
|
36
36
|
from trilogy.engine import ExecutionEngine
|
|
37
37
|
from trilogy.hooks.base_hook import BaseHook
|
|
38
38
|
from trilogy.parser import parse_text
|
|
39
|
+
from trilogy.render import get_dialect_generator
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
class ResultProtocol(Protocol):
|
|
@@ -82,40 +83,7 @@ class Executor(object):
|
|
|
82
83
|
self.generator: BaseDialect
|
|
83
84
|
self.logger = logger
|
|
84
85
|
self.hooks = hooks
|
|
85
|
-
|
|
86
|
-
from trilogy.dialect.bigquery import BigqueryDialect
|
|
87
|
-
|
|
88
|
-
self.generator = BigqueryDialect()
|
|
89
|
-
elif self.dialect == Dialects.SQL_SERVER:
|
|
90
|
-
from trilogy.dialect.sql_server import SqlServerDialect
|
|
91
|
-
|
|
92
|
-
self.generator = SqlServerDialect()
|
|
93
|
-
elif self.dialect == Dialects.DUCK_DB:
|
|
94
|
-
from trilogy.dialect.duckdb import DuckDBDialect
|
|
95
|
-
|
|
96
|
-
self.generator = DuckDBDialect()
|
|
97
|
-
elif self.dialect == Dialects.PRESTO:
|
|
98
|
-
from trilogy.dialect.presto import PrestoDialect
|
|
99
|
-
|
|
100
|
-
self.generator = PrestoDialect()
|
|
101
|
-
elif self.dialect == Dialects.TRINO:
|
|
102
|
-
from trilogy.dialect.presto import TrinoDialect
|
|
103
|
-
|
|
104
|
-
self.generator = TrinoDialect()
|
|
105
|
-
elif self.dialect == Dialects.POSTGRES:
|
|
106
|
-
from trilogy.dialect.postgres import PostgresDialect
|
|
107
|
-
|
|
108
|
-
self.generator = PostgresDialect()
|
|
109
|
-
elif self.dialect == Dialects.SNOWFLAKE:
|
|
110
|
-
from trilogy.dialect.snowflake import SnowflakeDialect
|
|
111
|
-
|
|
112
|
-
self.generator = SnowflakeDialect()
|
|
113
|
-
elif self.dialect == Dialects.DATAFRAME:
|
|
114
|
-
from trilogy.dialect.dataframe import DataframeDialect
|
|
115
|
-
|
|
116
|
-
self.generator = DataframeDialect()
|
|
117
|
-
else:
|
|
118
|
-
raise ValueError(f"Unsupported dialect {self.dialect}")
|
|
86
|
+
self.generator = get_dialect_generator(self.dialect)
|
|
119
87
|
self.connection = self.engine.connect()
|
|
120
88
|
# TODO: make generic
|
|
121
89
|
if self.dialect == Dialects.DATAFRAME:
|
trilogy/parsing/parse_engine.py
CHANGED
|
@@ -97,7 +97,12 @@ from trilogy.core.models.datasource import (
|
|
|
97
97
|
Query,
|
|
98
98
|
RawColumnExpr,
|
|
99
99
|
)
|
|
100
|
-
from trilogy.core.models.environment import
|
|
100
|
+
from trilogy.core.models.environment import (
|
|
101
|
+
DictImportResolver,
|
|
102
|
+
Environment,
|
|
103
|
+
FileSystemImportResolver,
|
|
104
|
+
Import,
|
|
105
|
+
)
|
|
101
106
|
from trilogy.core.statements.author import (
|
|
102
107
|
ConceptDeclarationStatement,
|
|
103
108
|
ConceptDerivationStatement,
|
|
@@ -223,7 +228,7 @@ class ParseToObjects(Transformer):
|
|
|
223
228
|
self,
|
|
224
229
|
environment: Environment,
|
|
225
230
|
parse_address: str | None = None,
|
|
226
|
-
token_address: Path | None = None,
|
|
231
|
+
token_address: Path | str | None = None,
|
|
227
232
|
parsed: dict[str, "ParseToObjects"] | None = None,
|
|
228
233
|
tokens: dict[Path | str, ParseTree] | None = None,
|
|
229
234
|
text_lookup: dict[Path | str, str] | None = None,
|
|
@@ -854,8 +859,22 @@ class ParseToObjects(Transformer):
|
|
|
854
859
|
)
|
|
855
860
|
|
|
856
861
|
def resolve_import_address(self, address) -> str:
|
|
857
|
-
|
|
858
|
-
|
|
862
|
+
if isinstance(
|
|
863
|
+
self.environment.config.import_resolver, FileSystemImportResolver
|
|
864
|
+
):
|
|
865
|
+
with open(address, "r", encoding="utf-8") as f:
|
|
866
|
+
text = f.read()
|
|
867
|
+
elif isinstance(self.environment.config.import_resolver, DictImportResolver):
|
|
868
|
+
lookup = address
|
|
869
|
+
if lookup not in self.environment.config.import_resolver.content:
|
|
870
|
+
raise ImportError(
|
|
871
|
+
f"Unable to import file {lookup}, not found in import resolver"
|
|
872
|
+
)
|
|
873
|
+
text = self.environment.config.import_resolver.content[lookup]
|
|
874
|
+
else:
|
|
875
|
+
raise ImportError(
|
|
876
|
+
f"Unable to import file {address}, resolver type {type(self.environment.config.import_resolver)} not supported"
|
|
877
|
+
)
|
|
859
878
|
return text
|
|
860
879
|
|
|
861
880
|
def import_statement(self, args: list[str]) -> ImportStatement:
|
|
@@ -867,10 +886,17 @@ class ParseToObjects(Transformer):
|
|
|
867
886
|
cache_key = args[0]
|
|
868
887
|
path = args[0].split(".")
|
|
869
888
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
889
|
+
if isinstance(
|
|
890
|
+
self.environment.config.import_resolver, FileSystemImportResolver
|
|
891
|
+
):
|
|
892
|
+
target = join(self.environment.working_path, *path) + ".preql"
|
|
893
|
+
# tokens + text are cached by path
|
|
894
|
+
token_lookup: Path | str = Path(target)
|
|
895
|
+
elif isinstance(self.environment.config.import_resolver, DictImportResolver):
|
|
896
|
+
target = ".".join(path)
|
|
897
|
+
token_lookup = target
|
|
898
|
+
else:
|
|
899
|
+
raise NotImplementedError
|
|
874
900
|
|
|
875
901
|
# parser + env has to be cached by prior import path + current key
|
|
876
902
|
key_path = self.import_keys + [cache_key]
|
|
@@ -901,6 +927,7 @@ class ParseToObjects(Transformer):
|
|
|
901
927
|
new_env = Environment(
|
|
902
928
|
working_path=dirname(target),
|
|
903
929
|
env_file_path=token_lookup,
|
|
930
|
+
config=self.environment.config,
|
|
904
931
|
)
|
|
905
932
|
new_env.concepts.fail_on_missing = False
|
|
906
933
|
self.parsed[self.parse_address] = self
|
trilogy/render.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from trilogy.dialect.enums import Dialects
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_dialect_generator(dialect: Dialects):
|
|
5
|
+
if dialect == Dialects.BIGQUERY:
|
|
6
|
+
from trilogy.dialect.bigquery import BigqueryDialect
|
|
7
|
+
|
|
8
|
+
return BigqueryDialect()
|
|
9
|
+
elif dialect == Dialects.SQL_SERVER:
|
|
10
|
+
from trilogy.dialect.sql_server import SqlServerDialect
|
|
11
|
+
|
|
12
|
+
return SqlServerDialect()
|
|
13
|
+
elif dialect == Dialects.DUCK_DB:
|
|
14
|
+
from trilogy.dialect.duckdb import DuckDBDialect
|
|
15
|
+
|
|
16
|
+
return DuckDBDialect()
|
|
17
|
+
elif dialect == Dialects.PRESTO:
|
|
18
|
+
from trilogy.dialect.presto import PrestoDialect
|
|
19
|
+
|
|
20
|
+
return PrestoDialect()
|
|
21
|
+
elif dialect == Dialects.TRINO:
|
|
22
|
+
from trilogy.dialect.presto import TrinoDialect
|
|
23
|
+
|
|
24
|
+
return TrinoDialect()
|
|
25
|
+
elif dialect == Dialects.POSTGRES:
|
|
26
|
+
from trilogy.dialect.postgres import PostgresDialect
|
|
27
|
+
|
|
28
|
+
return PostgresDialect()
|
|
29
|
+
elif dialect == Dialects.SNOWFLAKE:
|
|
30
|
+
from trilogy.dialect.snowflake import SnowflakeDialect
|
|
31
|
+
|
|
32
|
+
return SnowflakeDialect()
|
|
33
|
+
elif dialect == Dialects.DATAFRAME:
|
|
34
|
+
from trilogy.dialect.dataframe import DataframeDialect
|
|
35
|
+
|
|
36
|
+
return DataframeDialect()
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError(f"Unsupported dialect {dialect}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|