pylegend 0.2.2__py3-none-any.whl → 0.4.0__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.
- pylegend/__init__.py +9 -5
- pylegend/core/{databse → database}/sql_to_string/__init__.py +3 -3
- pylegend/core/{databse → database}/sql_to_string/db_extension.py +11 -5
- pylegend/core/{databse → database}/sql_to_string/generator.py +2 -2
- pylegend/core/language/__init__.py +10 -10
- pylegend/core/language/legacy_api/__init__.py +13 -0
- pylegend/core/language/{aggregate_specification.py → legacy_api/aggregate_specification.py} +10 -10
- pylegend/core/language/legacy_api/legacy_api_tds_row.py +32 -0
- pylegend/core/language/legendql_api/__init__.py +13 -0
- pylegend/core/language/legendql_api/legendql_api_custom_expressions.py +541 -0
- pylegend/core/language/legendql_api/legendql_api_tds_row.py +292 -0
- pylegend/core/language/shared/__init__.py +13 -0
- pylegend/core/language/{column_expressions.py → shared/column_expressions.py} +32 -31
- pylegend/core/language/{expression.py → shared/expression.py} +8 -0
- pylegend/core/language/{functions.py → shared/functions.py} +3 -3
- pylegend/core/language/shared/helpers.py +75 -0
- pylegend/core/language/{literal_expressions.py → shared/literal_expressions.py} +39 -1
- pylegend/core/language/{operations → shared/operations}/binary_expression.py +34 -2
- pylegend/core/language/{operations → shared/operations}/boolean_operation_expressions.py +34 -6
- pylegend/core/language/{operations → shared/operations}/collection_operation_expressions.py +146 -26
- pylegend/core/language/{operations → shared/operations}/date_operation_expressions.py +164 -24
- pylegend/core/language/{operations → shared/operations}/float_operation_expressions.py +53 -8
- pylegend/core/language/{operations → shared/operations}/integer_operation_expressions.py +62 -9
- pylegend/core/language/{operations → shared/operations}/nullary_expression.py +9 -2
- pylegend/core/language/{operations → shared/operations}/number_operation_expressions.py +211 -30
- pylegend/core/language/{operations → shared/operations}/primitive_operation_expressions.py +42 -3
- pylegend/core/language/{operations → shared/operations}/string_operation_expressions.py +169 -21
- pylegend/core/language/{operations → shared/operations}/unary_expression.py +10 -2
- pylegend/core/language/{primitive_collection.py → shared/primitive_collection.py} +2 -2
- pylegend/core/language/{primitives → shared/primitives}/__init__.py +9 -9
- pylegend/core/language/{primitives → shared/primitives}/boolean.py +9 -5
- pylegend/core/language/{primitives → shared/primitives}/date.py +23 -15
- pylegend/core/language/{primitives → shared/primitives}/datetime.py +4 -5
- pylegend/core/language/{primitives → shared/primitives}/float.py +6 -6
- pylegend/core/language/{primitives → shared/primitives}/integer.py +6 -6
- pylegend/core/language/{primitives → shared/primitives}/number.py +16 -13
- pylegend/core/language/{primitives → shared/primitives}/primitive.py +25 -5
- pylegend/core/language/{primitives → shared/primitives}/strictdate.py +4 -5
- pylegend/core/language/{primitives → shared/primitives}/string.py +18 -19
- pylegend/core/language/{tds_row.py → shared/tds_row.py} +46 -16
- pylegend/core/request/__init__.py +8 -1
- pylegend/core/request/auth.py +89 -11
- pylegend/core/request/legend_client.py +32 -0
- pylegend/core/sql/metamodel_extension.py +16 -0
- pylegend/core/tds/abstract/__init__.py +13 -0
- pylegend/core/tds/abstract/frames/__init__.py +13 -0
- pylegend/core/tds/{legend_api/frames/legend_api_applied_function_tds_frame.py → abstract/frames/applied_function_tds_frame.py} +19 -13
- pylegend/core/tds/abstract/frames/base_tds_frame.py +125 -0
- pylegend/core/tds/{legend_api/frames/legend_api_input_tds_frame.py → abstract/frames/input_tds_frame.py} +9 -12
- pylegend/core/tds/{legend_api/frames/functions → abstract}/function_helpers.py +1 -1
- pylegend/core/tds/{legend_api/frames/functions/concatenate_function.py → legacy_api/frames/functions/legacy_api_concatenate_function.py} +25 -13
- pylegend/core/tds/{legend_api/frames/functions/distinct_function.py → legacy_api/frames/functions/legacy_api_distinct_function.py} +13 -8
- pylegend/core/tds/{legend_api/frames/functions/drop_function.py → legacy_api/frames/functions/legacy_api_drop_function.py} +13 -8
- pylegend/core/tds/{legend_api/frames/functions/extend_function.py → legacy_api/frames/functions/legacy_api_extend_function.py} +36 -16
- pylegend/core/tds/{legend_api/frames/functions/filter_function.py → legacy_api/frames/functions/legacy_api_filter_function.py} +25 -13
- pylegend/core/tds/{legend_api/frames/functions/group_by_function.py → legacy_api/frames/functions/legacy_api_group_by_function.py} +44 -17
- pylegend/core/tds/{legend_api/frames/functions/head_function.py → legacy_api/frames/functions/legacy_api_head_function.py} +13 -8
- pylegend/core/tds/{legend_api/frames/functions/join_by_columns_function.py → legacy_api/frames/functions/legacy_api_join_by_columns_function.py} +40 -13
- pylegend/core/tds/{legend_api/frames/functions/join_function.py → legacy_api/frames/functions/legacy_api_join_function.py} +44 -20
- pylegend/core/tds/{legend_api/frames/functions/rename_columns_function.py → legacy_api/frames/functions/legacy_api_rename_columns_function.py} +20 -8
- pylegend/core/tds/{legend_api/frames/functions/restrict_function.py → legacy_api/frames/functions/legacy_api_restrict_function.py} +17 -8
- pylegend/core/tds/{legend_api/frames/functions/slice_function.py → legacy_api/frames/functions/legacy_api_slice_function.py} +13 -8
- pylegend/core/tds/{legend_api/frames/functions/sort_function.py → legacy_api/frames/functions/legacy_api_sort_function.py} +19 -8
- pylegend/core/tds/legacy_api/frames/legacy_api_applied_function_tds_frame.py +37 -0
- pylegend/core/tds/legacy_api/frames/legacy_api_base_tds_frame.py +204 -0
- pylegend/core/tds/legacy_api/frames/legacy_api_input_tds_frame.py +51 -0
- pylegend/core/tds/{legend_api/frames/legend_api_tds_frame.py → legacy_api/frames/legacy_api_tds_frame.py} +28 -28
- pylegend/core/tds/legendql_api/__init__.py +13 -0
- pylegend/core/tds/legendql_api/frames/__init__.py +13 -0
- pylegend/core/tds/legendql_api/frames/functions/__init__.py +13 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_asofjoin_function.py +156 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_concatenate_function.py +139 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_distinct_function.py +69 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_drop_function.py +74 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_extend_function.py +256 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_filter_function.py +121 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_function_helpers.py +137 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_groupby_function.py +256 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_head_function.py +74 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_join_function.py +214 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_project_function.py +169 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_rename_function.py +189 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_select_function.py +131 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_slice_function.py +82 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_sort_function.py +93 -0
- pylegend/core/tds/legendql_api/frames/functions/legendql_api_window_extend_function.py +283 -0
- pylegend/core/tds/legendql_api/frames/legendql_api_applied_function_tds_frame.py +37 -0
- pylegend/core/tds/legendql_api/frames/legendql_api_base_tds_frame.py +419 -0
- pylegend/core/tds/legendql_api/frames/legendql_api_input_tds_frame.py +50 -0
- pylegend/core/tds/legendql_api/frames/legendql_api_tds_frame.py +327 -0
- pylegend/core/tds/pandas_api/frames/functions/assign_function.py +6 -6
- pylegend/core/tds/pandas_api/frames/pandas_api_applied_function_tds_frame.py +4 -0
- pylegend/core/tds/pandas_api/frames/pandas_api_base_tds_frame.py +11 -3
- pylegend/core/tds/pandas_api/frames/pandas_api_tds_frame.py +2 -2
- pylegend/core/tds/tds_frame.py +32 -2
- pylegend/extensions/database/vendors/postgres/postgres_sql_to_string.py +1 -1
- pylegend/extensions/tds/abstract/legend_function_input_frame.py +4 -0
- pylegend/extensions/tds/abstract/legend_service_input_frame.py +4 -0
- pylegend/extensions/tds/abstract/table_spec_input_frame.py +4 -0
- pylegend/extensions/tds/{legend_api/frames/legend_api_legend_function_input_frame.py → legacy_api/frames/legacy_api_legend_function_input_frame.py} +5 -5
- pylegend/extensions/tds/{legend_api/frames/legend_api_legend_service_input_frame.py → legacy_api/frames/legacy_api_legend_service_input_frame.py} +6 -6
- pylegend/extensions/tds/{legend_api/frames/legend_api_table_spec_input_frame.py → legacy_api/frames/legacy_api_table_spec_input_frame.py} +5 -5
- pylegend/extensions/tds/legendql_api/__init__.py +13 -0
- pylegend/extensions/tds/legendql_api/frames/__init__.py +13 -0
- pylegend/extensions/tds/legendql_api/frames/legendql_api_legend_service_input_frame.py +46 -0
- pylegend/extensions/tds/legendql_api/frames/legendql_api_table_spec_input_frame.py +36 -0
- pylegend/{legend_api_tds_client.py → legacy_api_tds_client.py} +15 -15
- {pylegend-0.2.2.dist-info → pylegend-0.4.0.dist-info}/METADATA +7 -8
- pylegend-0.4.0.dist-info/NOTICE +5 -0
- pylegend-0.4.0.dist-info/RECORD +155 -0
- {pylegend-0.2.2.dist-info → pylegend-0.4.0.dist-info}/WHEEL +1 -1
- pylegend/core/tds/legend_api/frames/legend_api_base_tds_frame.py +0 -294
- pylegend-0.2.2.dist-info/RECORD +0 -115
- /pylegend/core/{databse → database}/__init__.py +0 -0
- /pylegend/core/{databse → database}/sql_to_string/config.py +0 -0
- /pylegend/core/language/{operations → shared/operations}/__init__.py +0 -0
- /pylegend/core/tds/{legend_api → legacy_api}/__init__.py +0 -0
- /pylegend/core/tds/{legend_api → legacy_api}/frames/__init__.py +0 -0
- /pylegend/core/tds/{legend_api → legacy_api}/frames/functions/__init__.py +0 -0
- /pylegend/extensions/tds/{legend_api → legacy_api}/__init__.py +0 -0
- /pylegend/extensions/tds/{legend_api → legacy_api}/frames/__init__.py +0 -0
- {pylegend-0.2.2.dist-info → pylegend-0.4.0.dist-info}/LICENSE +0 -0
- {pylegend-0.2.2.dist-info → pylegend-0.4.0.dist-info}/LICENSE.spdx +0 -0
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from datetime import date, datetime
|
|
15
16
|
from pylegend._typing import (
|
|
16
17
|
PyLegendList,
|
|
17
18
|
PyLegendSequence,
|
|
18
19
|
PyLegendTuple,
|
|
19
20
|
)
|
|
20
|
-
from pylegend.core.
|
|
21
|
+
from pylegend.core.language.shared.helpers import generate_pure_lambda, escape_column_name
|
|
22
|
+
from pylegend.core.tds.abstract.function_helpers import tds_column_for_primitive
|
|
23
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
21
24
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query
|
|
22
25
|
from pylegend.core.sql.metamodel import (
|
|
23
26
|
QuerySpecification,
|
|
@@ -26,26 +29,26 @@ from pylegend.core.sql.metamodel import (
|
|
|
26
29
|
)
|
|
27
30
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
28
31
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
29
|
-
from pylegend.core.tds.
|
|
32
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
33
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
30
34
|
from pylegend.core.language import (
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
LegacyApiTdsRow,
|
|
36
|
+
LegacyApiAggregateSpecification,
|
|
33
37
|
PyLegendPrimitive,
|
|
34
38
|
create_primitive_collection,
|
|
35
39
|
convert_literal_to_literal_expression,
|
|
36
40
|
)
|
|
37
|
-
from pylegend.core.tds.legend_api.frames.functions.function_helpers import tds_column_for_primitive
|
|
38
41
|
|
|
39
42
|
|
|
40
43
|
__all__: PyLegendSequence[str] = [
|
|
41
|
-
"
|
|
44
|
+
"LegacyApiGroupByFunction"
|
|
42
45
|
]
|
|
43
46
|
|
|
44
47
|
|
|
45
|
-
class
|
|
46
|
-
__base_frame:
|
|
48
|
+
class LegacyApiGroupByFunction(LegacyApiAppliedFunction):
|
|
49
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
47
50
|
__grouping_columns: PyLegendList[str]
|
|
48
|
-
__aggregations: PyLegendList[
|
|
51
|
+
__aggregations: PyLegendList[LegacyApiAggregateSpecification]
|
|
49
52
|
|
|
50
53
|
@classmethod
|
|
51
54
|
def name(cls) -> str:
|
|
@@ -53,9 +56,9 @@ class GroupByFunction(LegendApiAppliedFunction):
|
|
|
53
56
|
|
|
54
57
|
def __init__(
|
|
55
58
|
self,
|
|
56
|
-
base_frame:
|
|
59
|
+
base_frame: LegacyApiBaseTdsFrame,
|
|
57
60
|
grouping_columns: PyLegendList[str],
|
|
58
|
-
aggregations: PyLegendList[
|
|
61
|
+
aggregations: PyLegendList[LegacyApiAggregateSpecification],
|
|
59
62
|
) -> None:
|
|
60
63
|
self.__base_frame = base_frame
|
|
61
64
|
self.__grouping_columns = grouping_columns
|
|
@@ -87,7 +90,7 @@ class GroupByFunction(LegendApiAppliedFunction):
|
|
|
87
90
|
|
|
88
91
|
new_select_items = [y[1] for y in sorted(new_cols_with_index, key=lambda x: x[0])]
|
|
89
92
|
|
|
90
|
-
tds_row =
|
|
93
|
+
tds_row = LegacyApiTdsRow.from_tds_frame("frame", self.__base_frame)
|
|
91
94
|
for agg in self.__aggregations:
|
|
92
95
|
map_result = agg.get_map_fn()(tds_row)
|
|
93
96
|
collection = create_primitive_collection(map_result)
|
|
@@ -111,10 +114,34 @@ class GroupByFunction(LegendApiAppliedFunction):
|
|
|
111
114
|
]
|
|
112
115
|
return new_query
|
|
113
116
|
|
|
114
|
-
def
|
|
117
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
118
|
+
group_strings = []
|
|
119
|
+
for col_name in self.__grouping_columns:
|
|
120
|
+
group_strings.append(escape_column_name(col_name))
|
|
121
|
+
|
|
122
|
+
agg_strings = []
|
|
123
|
+
tds_row = LegacyApiTdsRow.from_tds_frame("r", self.__base_frame)
|
|
124
|
+
for agg in self.__aggregations:
|
|
125
|
+
agg_name = escape_column_name(agg.get_name())
|
|
126
|
+
map_expr = agg.get_map_fn()(tds_row)
|
|
127
|
+
collection = create_primitive_collection(map_expr)
|
|
128
|
+
agg_expr = agg.get_aggregate_fn()(collection)
|
|
129
|
+
map_expr_string = (map_expr.to_pure_expression(config) if isinstance(map_expr, PyLegendPrimitive) else
|
|
130
|
+
convert_literal_to_literal_expression(map_expr).to_pure_expression(config))
|
|
131
|
+
agg_expr_string = agg_expr.to_pure_expression(config).replace(map_expr_string, "$c")
|
|
132
|
+
agg_strings.append(f"{agg_name}:{generate_pure_lambda('r', map_expr_string)}:"
|
|
133
|
+
f"{generate_pure_lambda('c', agg_expr_string)}")
|
|
134
|
+
|
|
135
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}" +
|
|
136
|
+
f"->groupBy({config.separator(2)}"
|
|
137
|
+
f"~[{', '.join(group_strings)}],{config.separator(2, True)}"
|
|
138
|
+
f"~[{', '.join(agg_strings)}]{config.separator(1)}"
|
|
139
|
+
f")")
|
|
140
|
+
|
|
141
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
115
142
|
return self.__base_frame
|
|
116
143
|
|
|
117
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
144
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
118
145
|
return []
|
|
119
146
|
|
|
120
147
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -125,7 +152,7 @@ class GroupByFunction(LegendApiAppliedFunction):
|
|
|
125
152
|
if base_col.get_name() == c:
|
|
126
153
|
new_columns.append(base_col.copy())
|
|
127
154
|
|
|
128
|
-
tds_row =
|
|
155
|
+
tds_row = LegacyApiTdsRow.from_tds_frame("frame", self.__base_frame)
|
|
129
156
|
for agg in self.__aggregations:
|
|
130
157
|
map_result = agg.get_map_fn()(tds_row)
|
|
131
158
|
collection = create_primitive_collection(map_result)
|
|
@@ -159,7 +186,7 @@ class GroupByFunction(LegendApiAppliedFunction):
|
|
|
159
186
|
raise ValueError("Found duplicate column names in grouping columns and aggregation columns. "
|
|
160
187
|
f"Grouping columns - {self.__grouping_columns}, Aggregation columns - {agg_cols}")
|
|
161
188
|
|
|
162
|
-
tds_row =
|
|
189
|
+
tds_row = LegacyApiTdsRow.from_tds_frame("frame", self.__base_frame)
|
|
163
190
|
index = 0
|
|
164
191
|
for agg in self.__aggregations:
|
|
165
192
|
map_fn_copy = agg.get_map_fn() # For MyPy
|
|
@@ -176,7 +203,7 @@ class GroupByFunction(LegendApiAppliedFunction):
|
|
|
176
203
|
f"Error occurred while evaluating map function. Message: {str(e)}"
|
|
177
204
|
) from e
|
|
178
205
|
|
|
179
|
-
if not isinstance(map_result, (int, float, bool, str, PyLegendPrimitive)):
|
|
206
|
+
if not isinstance(map_result, (int, float, bool, str, date, datetime, PyLegendPrimitive)):
|
|
180
207
|
raise ValueError(
|
|
181
208
|
f"AggregateSpecification at index {index} (0-indexed) incompatible. "
|
|
182
209
|
f"Map function returns non-primitive - {str(type(map_result))}"
|
|
@@ -16,7 +16,7 @@ from pylegend._typing import (
|
|
|
16
16
|
PyLegendList,
|
|
17
17
|
PyLegendSequence,
|
|
18
18
|
)
|
|
19
|
-
from pylegend.core.tds.
|
|
19
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
20
20
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query
|
|
21
21
|
from pylegend.core.sql.metamodel import (
|
|
22
22
|
QuerySpecification,
|
|
@@ -24,23 +24,24 @@ from pylegend.core.sql.metamodel import (
|
|
|
24
24
|
)
|
|
25
25
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
26
26
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
27
|
-
from pylegend.core.tds.
|
|
27
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
28
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
__all__: PyLegendSequence[str] = [
|
|
31
|
-
"
|
|
32
|
+
"LegacyApiHeadFunction"
|
|
32
33
|
]
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
class
|
|
36
|
-
__base_frame:
|
|
36
|
+
class LegacyApiHeadFunction(LegacyApiAppliedFunction):
|
|
37
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
37
38
|
__row_count: int
|
|
38
39
|
|
|
39
40
|
@classmethod
|
|
40
41
|
def name(cls) -> str:
|
|
41
42
|
return "head"
|
|
42
43
|
|
|
43
|
-
def __init__(self, base_frame:
|
|
44
|
+
def __init__(self, base_frame: LegacyApiBaseTdsFrame, row_count: int) -> None:
|
|
44
45
|
self.__base_frame = base_frame
|
|
45
46
|
self.__row_count = row_count
|
|
46
47
|
|
|
@@ -54,10 +55,14 @@ class HeadFunction(LegendApiAppliedFunction):
|
|
|
54
55
|
new_query.limit = LongLiteral(value=self.__row_count)
|
|
55
56
|
return new_query
|
|
56
57
|
|
|
57
|
-
def
|
|
58
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
59
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}"
|
|
60
|
+
f"->limit({self.__row_count})")
|
|
61
|
+
|
|
62
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
58
63
|
return self.__base_frame
|
|
59
64
|
|
|
60
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
65
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
61
66
|
return []
|
|
62
67
|
|
|
63
68
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -17,7 +17,7 @@ from pylegend._typing import (
|
|
|
17
17
|
PyLegendList,
|
|
18
18
|
PyLegendSequence,
|
|
19
19
|
)
|
|
20
|
-
from pylegend.core.tds.
|
|
20
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
21
21
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query, extract_columns_for_subquery
|
|
22
22
|
from pylegend.core.sql.metamodel import (
|
|
23
23
|
QuerySpecification,
|
|
@@ -40,18 +40,20 @@ from pylegend.core.sql.metamodel import (
|
|
|
40
40
|
)
|
|
41
41
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
42
42
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
43
|
-
from pylegend.core.tds.
|
|
44
|
-
from pylegend.core.tds.
|
|
43
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
44
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
45
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_tds_frame import LegacyApiTdsFrame
|
|
46
|
+
from pylegend.core.language.shared.helpers import generate_pure_lambda, escape_column_name
|
|
45
47
|
|
|
46
48
|
|
|
47
49
|
__all__: PyLegendSequence[str] = [
|
|
48
|
-
"
|
|
50
|
+
"LegacyApiJoinByColumnsFunction"
|
|
49
51
|
]
|
|
50
52
|
|
|
51
53
|
|
|
52
|
-
class
|
|
53
|
-
__base_frame:
|
|
54
|
-
__other_frame:
|
|
54
|
+
class LegacyApiJoinByColumnsFunction(LegacyApiAppliedFunction):
|
|
55
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
56
|
+
__other_frame: LegacyApiBaseTdsFrame
|
|
55
57
|
__column_names_self: PyLegendList[str]
|
|
56
58
|
__column_names_other: PyLegendList[str]
|
|
57
59
|
__join_type: str
|
|
@@ -62,15 +64,15 @@ class JoinByColumnsFunction(LegendApiAppliedFunction):
|
|
|
62
64
|
|
|
63
65
|
def __init__(
|
|
64
66
|
self,
|
|
65
|
-
base_frame:
|
|
66
|
-
other_frame:
|
|
67
|
+
base_frame: LegacyApiBaseTdsFrame,
|
|
68
|
+
other_frame: LegacyApiTdsFrame,
|
|
67
69
|
column_names_self: PyLegendList[str],
|
|
68
70
|
column_names_other: PyLegendList[str],
|
|
69
71
|
join_type: str
|
|
70
72
|
) -> None:
|
|
71
73
|
self.__base_frame = base_frame
|
|
72
|
-
if not isinstance(other_frame,
|
|
73
|
-
raise ValueError("Expected
|
|
74
|
+
if not isinstance(other_frame, LegacyApiBaseTdsFrame):
|
|
75
|
+
raise ValueError("Expected LegacyApiBaseTdsFrame") # pragma: no cover
|
|
74
76
|
self.__other_frame = other_frame
|
|
75
77
|
self.__column_names_self = column_names_self
|
|
76
78
|
self.__column_names_other = column_names_other
|
|
@@ -160,10 +162,35 @@ class JoinByColumnsFunction(LegendApiAppliedFunction):
|
|
|
160
162
|
wrapped_join_query = create_sub_query(join_query, config, "root")
|
|
161
163
|
return wrapped_join_query
|
|
162
164
|
|
|
163
|
-
def
|
|
165
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
166
|
+
common_join_cols = [x for x, y in zip(self.__column_names_self, self.__column_names_other) if x == y]
|
|
167
|
+
other_frame = (self.__other_frame if (len(common_join_cols) == 0) else
|
|
168
|
+
self.__other_frame.rename_columns(common_join_cols, [c + "_gen_r" for c in common_join_cols]))
|
|
169
|
+
sub_expressions = []
|
|
170
|
+
for x, y in zip(self.__column_names_self, self.__column_names_other):
|
|
171
|
+
left = "$l." + escape_column_name(x)
|
|
172
|
+
y = (y + "_gen_r") if y in common_join_cols else y
|
|
173
|
+
right = "$r." + escape_column_name(y)
|
|
174
|
+
sub_expressions.append(f"({left} == {right})")
|
|
175
|
+
|
|
176
|
+
join_expr_string = " && ".join(sub_expressions)
|
|
177
|
+
join_kind = (
|
|
178
|
+
"INNER" if self.__join_type.lower() == 'inner' else
|
|
179
|
+
"LEFT" if self.__join_type.lower() in ('left_outer', 'leftouter') else
|
|
180
|
+
"RIGHT" if self.__join_type.lower() in ('right_outer', 'rightouter') else
|
|
181
|
+
"FULL"
|
|
182
|
+
)
|
|
183
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}" +
|
|
184
|
+
f"->join({config.separator(2)}"
|
|
185
|
+
f"{other_frame.to_pure(config.push_indent(2))},{config.separator(2, True)}" # type: ignore
|
|
186
|
+
f"JoinKind.{join_kind},{config.separator(2, True)}"
|
|
187
|
+
f"{generate_pure_lambda('l, r', join_expr_string)}{config.separator(1)}"
|
|
188
|
+
f")")
|
|
189
|
+
|
|
190
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
164
191
|
return self.__base_frame
|
|
165
192
|
|
|
166
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
193
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
167
194
|
return [self.__other_frame]
|
|
168
195
|
|
|
169
196
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -18,7 +18,7 @@ from pylegend._typing import (
|
|
|
18
18
|
PyLegendUnion,
|
|
19
19
|
PyLegendCallable,
|
|
20
20
|
)
|
|
21
|
-
from pylegend.core.tds.
|
|
21
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
22
22
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query, extract_columns_for_subquery
|
|
23
23
|
from pylegend.core.sql.metamodel import (
|
|
24
24
|
QuerySpecification,
|
|
@@ -36,24 +36,28 @@ from pylegend.core.sql.metamodel import (
|
|
|
36
36
|
)
|
|
37
37
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
38
38
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
39
|
-
from pylegend.core.tds.
|
|
40
|
-
from pylegend.core.tds.
|
|
39
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
40
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
41
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_tds_frame import LegacyApiTdsFrame
|
|
41
42
|
from pylegend.core.language import (
|
|
42
43
|
PyLegendBoolean,
|
|
43
|
-
|
|
44
|
+
LegacyApiTdsRow,
|
|
44
45
|
PyLegendBooleanLiteralExpression,
|
|
46
|
+
PyLegendPrimitive,
|
|
47
|
+
convert_literal_to_literal_expression,
|
|
45
48
|
)
|
|
49
|
+
from pylegend.core.language.shared.helpers import generate_pure_lambda
|
|
46
50
|
|
|
47
51
|
|
|
48
52
|
__all__: PyLegendSequence[str] = [
|
|
49
|
-
"
|
|
53
|
+
"LegacyApiJoinFunction"
|
|
50
54
|
]
|
|
51
55
|
|
|
52
56
|
|
|
53
|
-
class
|
|
54
|
-
__base_frame:
|
|
55
|
-
__other_frame:
|
|
56
|
-
__join_condition: PyLegendCallable[[
|
|
57
|
+
class LegacyApiJoinFunction(LegacyApiAppliedFunction):
|
|
58
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
59
|
+
__other_frame: LegacyApiBaseTdsFrame
|
|
60
|
+
__join_condition: PyLegendCallable[[LegacyApiTdsRow, LegacyApiTdsRow], PyLegendUnion[bool, PyLegendBoolean]]
|
|
57
61
|
__join_type: str
|
|
58
62
|
|
|
59
63
|
@classmethod
|
|
@@ -62,14 +66,14 @@ class JoinFunction(LegendApiAppliedFunction):
|
|
|
62
66
|
|
|
63
67
|
def __init__(
|
|
64
68
|
self,
|
|
65
|
-
base_frame:
|
|
66
|
-
other_frame:
|
|
67
|
-
join_condition: PyLegendCallable[[
|
|
69
|
+
base_frame: LegacyApiBaseTdsFrame,
|
|
70
|
+
other_frame: LegacyApiTdsFrame,
|
|
71
|
+
join_condition: PyLegendCallable[[LegacyApiTdsRow, LegacyApiTdsRow], PyLegendUnion[bool, PyLegendBoolean]],
|
|
68
72
|
join_type: str
|
|
69
73
|
) -> None:
|
|
70
74
|
self.__base_frame = base_frame
|
|
71
|
-
if not isinstance(other_frame,
|
|
72
|
-
raise ValueError("Expected
|
|
75
|
+
if not isinstance(other_frame, LegacyApiBaseTdsFrame):
|
|
76
|
+
raise ValueError("Expected LegacyApiBaseTdsFrame") # pragma: no cover
|
|
73
77
|
self.__other_frame = other_frame
|
|
74
78
|
self.__join_condition = join_condition
|
|
75
79
|
self.__join_type = join_type
|
|
@@ -86,8 +90,8 @@ class JoinFunction(LegendApiAppliedFunction):
|
|
|
86
90
|
)
|
|
87
91
|
)
|
|
88
92
|
|
|
89
|
-
left_row =
|
|
90
|
-
right_row =
|
|
93
|
+
left_row = LegacyApiTdsRow.from_tds_frame('left', self.__base_frame)
|
|
94
|
+
right_row = LegacyApiTdsRow.from_tds_frame('right', self.__other_frame)
|
|
91
95
|
|
|
92
96
|
join_expr = self.__join_condition(left_row, right_row)
|
|
93
97
|
if isinstance(join_expr, bool):
|
|
@@ -142,10 +146,30 @@ class JoinFunction(LegendApiAppliedFunction):
|
|
|
142
146
|
wrapped_join_query = create_sub_query(join_query, config, "root")
|
|
143
147
|
return wrapped_join_query
|
|
144
148
|
|
|
145
|
-
def
|
|
149
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
150
|
+
left_row = LegacyApiTdsRow.from_tds_frame("l", self.__base_frame)
|
|
151
|
+
right_row = LegacyApiTdsRow.from_tds_frame("r", self.__other_frame)
|
|
152
|
+
join_expr = self.__join_condition(left_row, right_row)
|
|
153
|
+
join_expr_string = (join_expr.to_pure_expression(config.push_indent(2))
|
|
154
|
+
if isinstance(join_expr, PyLegendPrimitive) else
|
|
155
|
+
convert_literal_to_literal_expression(join_expr).to_pure_expression(config.push_indent(2)))
|
|
156
|
+
join_kind = (
|
|
157
|
+
"INNER" if self.__join_type.lower() == 'inner' else
|
|
158
|
+
"LEFT" if self.__join_type.lower() in ('left_outer', 'leftouter') else
|
|
159
|
+
"RIGHT" if self.__join_type.lower() in ('right_outer', 'rightouter') else
|
|
160
|
+
"FULL"
|
|
161
|
+
)
|
|
162
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}" +
|
|
163
|
+
f"->join({config.separator(2)}"
|
|
164
|
+
f"{self.__other_frame.to_pure(config.push_indent(2))},{config.separator(2, True)}"
|
|
165
|
+
f"JoinKind.{join_kind},{config.separator(2, True)}"
|
|
166
|
+
f"{generate_pure_lambda('l, r', join_expr_string)}{config.separator(1)}"
|
|
167
|
+
f")")
|
|
168
|
+
|
|
169
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
146
170
|
return self.__base_frame
|
|
147
171
|
|
|
148
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
172
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
149
173
|
return [self.__other_frame]
|
|
150
174
|
|
|
151
175
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -159,8 +183,8 @@ class JoinFunction(LegendApiAppliedFunction):
|
|
|
159
183
|
if not isinstance(copy, type(lambda x: 0)) or (copy.__code__.co_argcount != 2):
|
|
160
184
|
raise TypeError("Join condition function should be a lambda which takes two arguments (TDSRow, TDSRow)")
|
|
161
185
|
|
|
162
|
-
left_row =
|
|
163
|
-
right_row =
|
|
186
|
+
left_row = LegacyApiTdsRow.from_tds_frame("left", self.__base_frame)
|
|
187
|
+
right_row = LegacyApiTdsRow.from_tds_frame("right", self.__other_frame)
|
|
164
188
|
|
|
165
189
|
try:
|
|
166
190
|
result = self.__join_condition(left_row, right_row)
|
|
@@ -16,7 +16,7 @@ from pylegend._typing import (
|
|
|
16
16
|
PyLegendList,
|
|
17
17
|
PyLegendSequence,
|
|
18
18
|
)
|
|
19
|
-
from pylegend.core.tds.
|
|
19
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
20
20
|
from pylegend.core.tds.sql_query_helpers import copy_query
|
|
21
21
|
from pylegend.core.sql.metamodel import (
|
|
22
22
|
QuerySpecification,
|
|
@@ -25,16 +25,18 @@ from pylegend.core.sql.metamodel import (
|
|
|
25
25
|
)
|
|
26
26
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
27
27
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
28
|
-
from pylegend.core.tds.
|
|
28
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
29
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
30
|
+
from pylegend.core.language.shared.helpers import escape_column_name
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
__all__: PyLegendSequence[str] = [
|
|
32
|
-
"
|
|
34
|
+
"LegacyApiRenameColumnsFunction"
|
|
33
35
|
]
|
|
34
36
|
|
|
35
37
|
|
|
36
|
-
class
|
|
37
|
-
__base_frame:
|
|
38
|
+
class LegacyApiRenameColumnsFunction(LegacyApiAppliedFunction):
|
|
39
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
38
40
|
__column_names: PyLegendList[str]
|
|
39
41
|
__renamed_column_names: PyLegendList[str]
|
|
40
42
|
|
|
@@ -44,7 +46,7 @@ class RenameColumnsFunction(LegendApiAppliedFunction):
|
|
|
44
46
|
|
|
45
47
|
def __init__(
|
|
46
48
|
self,
|
|
47
|
-
base_frame:
|
|
49
|
+
base_frame: LegacyApiBaseTdsFrame,
|
|
48
50
|
column_names: PyLegendList[str],
|
|
49
51
|
renamed_column_names: PyLegendList[str]
|
|
50
52
|
) -> None:
|
|
@@ -77,10 +79,20 @@ class RenameColumnsFunction(LegendApiAppliedFunction):
|
|
|
77
79
|
new_query.select.selectItems = new_select_items
|
|
78
80
|
return new_query
|
|
79
81
|
|
|
80
|
-
def
|
|
82
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
83
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}" +
|
|
84
|
+
f"{config.separator(1)}".join([
|
|
85
|
+
f"->rename(~{x}, ~{y})"
|
|
86
|
+
for x, y in zip(
|
|
87
|
+
map(escape_column_name, self.__column_names),
|
|
88
|
+
map(escape_column_name, self.__renamed_column_names)
|
|
89
|
+
)
|
|
90
|
+
]))
|
|
91
|
+
|
|
92
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
81
93
|
return self.__base_frame
|
|
82
94
|
|
|
83
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
95
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
84
96
|
return []
|
|
85
97
|
|
|
86
98
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -17,7 +17,7 @@ from pylegend._typing import (
|
|
|
17
17
|
PyLegendSequence,
|
|
18
18
|
PyLegendTuple
|
|
19
19
|
)
|
|
20
|
-
from pylegend.core.tds.
|
|
20
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
21
21
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query
|
|
22
22
|
from pylegend.core.sql.metamodel import (
|
|
23
23
|
QuerySpecification,
|
|
@@ -26,23 +26,25 @@ from pylegend.core.sql.metamodel import (
|
|
|
26
26
|
)
|
|
27
27
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
28
28
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
29
|
-
from pylegend.core.tds.
|
|
29
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
30
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
31
|
+
from pylegend.core.language.shared.helpers import escape_column_name
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
__all__: PyLegendSequence[str] = [
|
|
33
|
-
"
|
|
35
|
+
"LegacyApiRestrictFunction"
|
|
34
36
|
]
|
|
35
37
|
|
|
36
38
|
|
|
37
|
-
class
|
|
38
|
-
__base_frame:
|
|
39
|
+
class LegacyApiRestrictFunction(LegacyApiAppliedFunction):
|
|
40
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
39
41
|
__column_name_list: PyLegendList[str]
|
|
40
42
|
|
|
41
43
|
@classmethod
|
|
42
44
|
def name(cls) -> str:
|
|
43
45
|
return "restrict"
|
|
44
46
|
|
|
45
|
-
def __init__(self, base_frame:
|
|
47
|
+
def __init__(self, base_frame: LegacyApiBaseTdsFrame, column_name_list: PyLegendList[str]) -> None:
|
|
46
48
|
self.__base_frame = base_frame
|
|
47
49
|
self.__column_name_list = column_name_list
|
|
48
50
|
|
|
@@ -74,10 +76,17 @@ class RestrictFunction(LegendApiAppliedFunction):
|
|
|
74
76
|
new_query.select.selectItems = new_select_items
|
|
75
77
|
return new_query
|
|
76
78
|
|
|
77
|
-
def
|
|
79
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
80
|
+
escaped_columns = []
|
|
81
|
+
for col_name in self.__column_name_list:
|
|
82
|
+
escaped_columns.append(escape_column_name(col_name))
|
|
83
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}" +
|
|
84
|
+
f"->select(~[{', '.join(escaped_columns)}])")
|
|
85
|
+
|
|
86
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
78
87
|
return self.__base_frame
|
|
79
88
|
|
|
80
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
89
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
81
90
|
return []
|
|
82
91
|
|
|
83
92
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -16,7 +16,7 @@ from pylegend._typing import (
|
|
|
16
16
|
PyLegendList,
|
|
17
17
|
PyLegendSequence
|
|
18
18
|
)
|
|
19
|
-
from pylegend.core.tds.
|
|
19
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
20
20
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query
|
|
21
21
|
from pylegend.core.sql.metamodel import (
|
|
22
22
|
QuerySpecification,
|
|
@@ -24,16 +24,17 @@ from pylegend.core.sql.metamodel import (
|
|
|
24
24
|
)
|
|
25
25
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
26
26
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
27
|
-
from pylegend.core.tds.
|
|
27
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
28
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
__all__: PyLegendSequence[str] = [
|
|
31
|
-
"
|
|
32
|
+
"LegacyApiSliceFunction"
|
|
32
33
|
]
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
class
|
|
36
|
-
__base_frame:
|
|
36
|
+
class LegacyApiSliceFunction(LegacyApiAppliedFunction):
|
|
37
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
37
38
|
__start_row: int
|
|
38
39
|
__end_row: int
|
|
39
40
|
|
|
@@ -41,7 +42,7 @@ class SliceFunction(LegendApiAppliedFunction):
|
|
|
41
42
|
def name(cls) -> str:
|
|
42
43
|
return "slice"
|
|
43
44
|
|
|
44
|
-
def __init__(self, base_frame:
|
|
45
|
+
def __init__(self, base_frame: LegacyApiBaseTdsFrame, start_row: int, end_row: int) -> None:
|
|
45
46
|
self.__base_frame = base_frame
|
|
46
47
|
self.__start_row = start_row
|
|
47
48
|
self.__end_row = end_row
|
|
@@ -57,10 +58,14 @@ class SliceFunction(LegendApiAppliedFunction):
|
|
|
57
58
|
new_query.limit = LongLiteral(self.__end_row - self.__start_row)
|
|
58
59
|
return new_query
|
|
59
60
|
|
|
60
|
-
def
|
|
61
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
62
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}"
|
|
63
|
+
f"->slice({self.__start_row}, {self.__end_row})")
|
|
64
|
+
|
|
65
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
61
66
|
return self.__base_frame
|
|
62
67
|
|
|
63
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
68
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
64
69
|
return []
|
|
65
70
|
|
|
66
71
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|
|
@@ -17,7 +17,7 @@ from pylegend._typing import (
|
|
|
17
17
|
PyLegendSequence,
|
|
18
18
|
PyLegendOptional,
|
|
19
19
|
)
|
|
20
|
-
from pylegend.core.tds.
|
|
20
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import LegacyApiAppliedFunction
|
|
21
21
|
from pylegend.core.tds.sql_query_helpers import copy_query, create_sub_query
|
|
22
22
|
from pylegend.core.sql.metamodel import (
|
|
23
23
|
QuerySpecification,
|
|
@@ -29,16 +29,18 @@ from pylegend.core.sql.metamodel import (
|
|
|
29
29
|
)
|
|
30
30
|
from pylegend.core.tds.tds_column import TdsColumn
|
|
31
31
|
from pylegend.core.tds.tds_frame import FrameToSqlConfig
|
|
32
|
-
from pylegend.core.tds.
|
|
32
|
+
from pylegend.core.tds.tds_frame import FrameToPureConfig
|
|
33
|
+
from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
|
|
34
|
+
from pylegend.core.language.shared.helpers import escape_column_name
|
|
33
35
|
|
|
34
36
|
|
|
35
37
|
__all__: PyLegendSequence[str] = [
|
|
36
|
-
"
|
|
38
|
+
"LegacyApiSortFunction"
|
|
37
39
|
]
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
class
|
|
41
|
-
__base_frame:
|
|
42
|
+
class LegacyApiSortFunction(LegacyApiAppliedFunction):
|
|
43
|
+
__base_frame: LegacyApiBaseTdsFrame
|
|
42
44
|
__column_name_list: PyLegendList[str]
|
|
43
45
|
__directions: PyLegendOptional[PyLegendList[str]]
|
|
44
46
|
|
|
@@ -48,7 +50,7 @@ class SortFunction(LegendApiAppliedFunction):
|
|
|
48
50
|
|
|
49
51
|
def __init__(
|
|
50
52
|
self,
|
|
51
|
-
base_frame:
|
|
53
|
+
base_frame: LegacyApiBaseTdsFrame,
|
|
52
54
|
column_name_list: PyLegendList[str],
|
|
53
55
|
directions: PyLegendOptional[PyLegendList[str]]
|
|
54
56
|
) -> None:
|
|
@@ -89,10 +91,19 @@ class SortFunction(LegendApiAppliedFunction):
|
|
|
89
91
|
]
|
|
90
92
|
return new_query
|
|
91
93
|
|
|
92
|
-
def
|
|
94
|
+
def to_pure(self, config: FrameToPureConfig) -> str:
|
|
95
|
+
direction_list = self._build_directions_list()
|
|
96
|
+
sort_infos = []
|
|
97
|
+
for col_name, direction in zip(self.__column_name_list, direction_list):
|
|
98
|
+
escaped = escape_column_name(col_name)
|
|
99
|
+
sort_infos.append(f"{'ascending' if direction.upper() == 'ASC' else 'descending'}(~{escaped})")
|
|
100
|
+
return (f"{self.__base_frame.to_pure(config)}{config.separator(1)}" +
|
|
101
|
+
f"->sort([{', '.join(sort_infos)}])")
|
|
102
|
+
|
|
103
|
+
def base_frame(self) -> LegacyApiBaseTdsFrame:
|
|
93
104
|
return self.__base_frame
|
|
94
105
|
|
|
95
|
-
def tds_frame_parameters(self) -> PyLegendList["
|
|
106
|
+
def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
|
|
96
107
|
return []
|
|
97
108
|
|
|
98
109
|
def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
|