pylegend 0.3.0__py3-none-any.whl → 0.5.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.
Files changed (124) hide show
  1. pylegend/__init__.py +16 -6
  2. pylegend/core/{databse → database}/sql_to_string/__init__.py +3 -3
  3. pylegend/core/{databse → database}/sql_to_string/db_extension.py +14 -5
  4. pylegend/core/{databse → database}/sql_to_string/generator.py +2 -2
  5. pylegend/core/language/__init__.py +12 -10
  6. pylegend/core/language/legacy_api/__init__.py +13 -0
  7. pylegend/core/language/{aggregate_specification.py → legacy_api/aggregate_specification.py} +10 -10
  8. pylegend/core/language/legacy_api/legacy_api_tds_row.py +32 -0
  9. pylegend/core/language/legendql_api/__init__.py +13 -0
  10. pylegend/core/language/legendql_api/legendql_api_custom_expressions.py +541 -0
  11. pylegend/core/language/legendql_api/legendql_api_tds_row.py +292 -0
  12. pylegend/core/language/shared/__init__.py +13 -0
  13. pylegend/core/language/{column_expressions.py → shared/column_expressions.py} +32 -31
  14. pylegend/core/language/{expression.py → shared/expression.py} +8 -0
  15. pylegend/core/language/{functions.py → shared/functions.py} +12 -3
  16. pylegend/core/language/shared/helpers.py +75 -0
  17. pylegend/core/language/{literal_expressions.py → shared/literal_expressions.py} +39 -1
  18. pylegend/core/language/{operations → shared/operations}/binary_expression.py +34 -2
  19. pylegend/core/language/{operations → shared/operations}/boolean_operation_expressions.py +34 -6
  20. pylegend/core/language/{operations → shared/operations}/collection_operation_expressions.py +146 -26
  21. pylegend/core/language/{operations → shared/operations}/date_operation_expressions.py +288 -24
  22. pylegend/core/language/{operations → shared/operations}/float_operation_expressions.py +53 -8
  23. pylegend/core/language/{operations → shared/operations}/integer_operation_expressions.py +62 -9
  24. pylegend/core/language/{operations → shared/operations}/nullary_expression.py +9 -2
  25. pylegend/core/language/{operations → shared/operations}/number_operation_expressions.py +211 -30
  26. pylegend/core/language/shared/operations/primitive_operation_expressions.py +155 -0
  27. pylegend/core/language/{operations → shared/operations}/string_operation_expressions.py +194 -21
  28. pylegend/core/language/{operations → shared/operations}/unary_expression.py +10 -2
  29. pylegend/core/language/{primitive_collection.py → shared/primitive_collection.py} +2 -2
  30. pylegend/core/language/{primitives → shared/primitives}/__init__.py +9 -9
  31. pylegend/core/language/{primitives → shared/primitives}/boolean.py +9 -5
  32. pylegend/core/language/{primitives → shared/primitives}/date.py +60 -15
  33. pylegend/core/language/{primitives → shared/primitives}/datetime.py +4 -5
  34. pylegend/core/language/{primitives → shared/primitives}/float.py +6 -6
  35. pylegend/core/language/{primitives → shared/primitives}/integer.py +6 -6
  36. pylegend/core/language/{primitives → shared/primitives}/number.py +16 -13
  37. pylegend/core/language/{primitives → shared/primitives}/primitive.py +41 -5
  38. pylegend/core/language/{primitives → shared/primitives}/strictdate.py +4 -5
  39. pylegend/core/language/{primitives → shared/primitives}/string.py +18 -19
  40. pylegend/core/language/{tds_row.py → shared/tds_row.py} +46 -16
  41. pylegend/core/request/__init__.py +7 -1
  42. pylegend/core/request/auth.py +55 -1
  43. pylegend/core/request/legend_client.py +32 -0
  44. pylegend/core/sql/metamodel_extension.py +28 -0
  45. pylegend/core/tds/abstract/__init__.py +13 -0
  46. pylegend/core/tds/abstract/frames/__init__.py +13 -0
  47. pylegend/core/tds/{legend_api/frames/legend_api_applied_function_tds_frame.py → abstract/frames/applied_function_tds_frame.py} +19 -13
  48. pylegend/core/tds/abstract/frames/base_tds_frame.py +125 -0
  49. pylegend/core/tds/{legend_api/frames/legend_api_input_tds_frame.py → abstract/frames/input_tds_frame.py} +9 -12
  50. pylegend/core/tds/{legend_api/frames/functions → abstract}/function_helpers.py +1 -1
  51. pylegend/core/tds/{legend_api/frames/functions/concatenate_function.py → legacy_api/frames/functions/legacy_api_concatenate_function.py} +25 -13
  52. pylegend/core/tds/{legend_api/frames/functions/distinct_function.py → legacy_api/frames/functions/legacy_api_distinct_function.py} +13 -8
  53. pylegend/core/tds/{legend_api/frames/functions/drop_function.py → legacy_api/frames/functions/legacy_api_drop_function.py} +13 -8
  54. pylegend/core/tds/{legend_api/frames/functions/extend_function.py → legacy_api/frames/functions/legacy_api_extend_function.py} +36 -16
  55. pylegend/core/tds/{legend_api/frames/functions/filter_function.py → legacy_api/frames/functions/legacy_api_filter_function.py} +25 -13
  56. pylegend/core/tds/{legend_api/frames/functions/group_by_function.py → legacy_api/frames/functions/legacy_api_group_by_function.py} +44 -17
  57. pylegend/core/tds/{legend_api/frames/functions/head_function.py → legacy_api/frames/functions/legacy_api_head_function.py} +13 -8
  58. 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
  59. pylegend/core/tds/{legend_api/frames/functions/join_function.py → legacy_api/frames/functions/legacy_api_join_function.py} +44 -20
  60. pylegend/core/tds/{legend_api/frames/functions/rename_columns_function.py → legacy_api/frames/functions/legacy_api_rename_columns_function.py} +20 -8
  61. pylegend/core/tds/{legend_api/frames/functions/restrict_function.py → legacy_api/frames/functions/legacy_api_restrict_function.py} +17 -8
  62. pylegend/core/tds/{legend_api/frames/functions/slice_function.py → legacy_api/frames/functions/legacy_api_slice_function.py} +13 -8
  63. pylegend/core/tds/{legend_api/frames/functions/sort_function.py → legacy_api/frames/functions/legacy_api_sort_function.py} +19 -8
  64. pylegend/core/tds/legacy_api/frames/legacy_api_applied_function_tds_frame.py +37 -0
  65. pylegend/core/tds/legacy_api/frames/legacy_api_base_tds_frame.py +204 -0
  66. pylegend/core/tds/legacy_api/frames/legacy_api_input_tds_frame.py +51 -0
  67. pylegend/core/tds/{legend_api/frames/legend_api_tds_frame.py → legacy_api/frames/legacy_api_tds_frame.py} +28 -28
  68. pylegend/core/tds/legendql_api/__init__.py +13 -0
  69. pylegend/core/tds/legendql_api/frames/__init__.py +13 -0
  70. pylegend/core/tds/legendql_api/frames/functions/__init__.py +13 -0
  71. pylegend/core/tds/legendql_api/frames/functions/legendql_api_asofjoin_function.py +156 -0
  72. pylegend/core/tds/legendql_api/frames/functions/legendql_api_concatenate_function.py +139 -0
  73. pylegend/core/tds/legendql_api/frames/functions/legendql_api_distinct_function.py +69 -0
  74. pylegend/core/tds/legendql_api/frames/functions/legendql_api_drop_function.py +74 -0
  75. pylegend/core/tds/legendql_api/frames/functions/legendql_api_extend_function.py +256 -0
  76. pylegend/core/tds/legendql_api/frames/functions/legendql_api_filter_function.py +121 -0
  77. pylegend/core/tds/legendql_api/frames/functions/legendql_api_function_helpers.py +137 -0
  78. pylegend/core/tds/legendql_api/frames/functions/legendql_api_groupby_function.py +256 -0
  79. pylegend/core/tds/legendql_api/frames/functions/legendql_api_head_function.py +74 -0
  80. pylegend/core/tds/legendql_api/frames/functions/legendql_api_join_function.py +214 -0
  81. pylegend/core/tds/legendql_api/frames/functions/legendql_api_project_function.py +169 -0
  82. pylegend/core/tds/legendql_api/frames/functions/legendql_api_rename_function.py +189 -0
  83. pylegend/core/tds/legendql_api/frames/functions/legendql_api_select_function.py +131 -0
  84. pylegend/core/tds/legendql_api/frames/functions/legendql_api_slice_function.py +82 -0
  85. pylegend/core/tds/legendql_api/frames/functions/legendql_api_sort_function.py +93 -0
  86. pylegend/core/tds/legendql_api/frames/functions/legendql_api_window_extend_function.py +283 -0
  87. pylegend/core/tds/legendql_api/frames/legendql_api_applied_function_tds_frame.py +37 -0
  88. pylegend/core/tds/legendql_api/frames/legendql_api_base_tds_frame.py +419 -0
  89. pylegend/core/tds/legendql_api/frames/legendql_api_input_tds_frame.py +50 -0
  90. pylegend/core/tds/legendql_api/frames/legendql_api_tds_frame.py +327 -0
  91. pylegend/core/tds/pandas_api/frames/functions/assign_function.py +6 -6
  92. pylegend/core/tds/pandas_api/frames/pandas_api_applied_function_tds_frame.py +4 -0
  93. pylegend/core/tds/pandas_api/frames/pandas_api_base_tds_frame.py +11 -3
  94. pylegend/core/tds/pandas_api/frames/pandas_api_tds_frame.py +2 -2
  95. pylegend/core/tds/tds_frame.py +32 -2
  96. pylegend/extensions/database/vendors/postgres/postgres_sql_to_string.py +1 -1
  97. pylegend/extensions/tds/abstract/legend_function_input_frame.py +4 -0
  98. pylegend/extensions/tds/abstract/legend_service_input_frame.py +4 -0
  99. pylegend/extensions/tds/abstract/table_spec_input_frame.py +4 -0
  100. 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
  101. 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
  102. 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
  103. pylegend/extensions/tds/legendql_api/__init__.py +13 -0
  104. pylegend/extensions/tds/legendql_api/frames/__init__.py +13 -0
  105. pylegend/extensions/tds/legendql_api/frames/legendql_api_legend_service_input_frame.py +46 -0
  106. pylegend/extensions/tds/legendql_api/frames/legendql_api_table_spec_input_frame.py +36 -0
  107. pylegend/{legend_api_tds_client.py → legacy_api_tds_client.py} +15 -15
  108. {pylegend-0.3.0.dist-info → pylegend-0.5.0.dist-info}/METADATA +7 -8
  109. pylegend-0.5.0.dist-info/NOTICE +5 -0
  110. pylegend-0.5.0.dist-info/RECORD +155 -0
  111. {pylegend-0.3.0.dist-info → pylegend-0.5.0.dist-info}/WHEEL +1 -1
  112. pylegend/core/language/operations/primitive_operation_expressions.py +0 -56
  113. pylegend/core/tds/legend_api/frames/legend_api_base_tds_frame.py +0 -294
  114. pylegend-0.3.0.dist-info/RECORD +0 -115
  115. /pylegend/core/{databse → database}/__init__.py +0 -0
  116. /pylegend/core/{databse → database}/sql_to_string/config.py +0 -0
  117. /pylegend/core/language/{operations → shared/operations}/__init__.py +0 -0
  118. /pylegend/core/tds/{legend_api → legacy_api}/__init__.py +0 -0
  119. /pylegend/core/tds/{legend_api → legacy_api}/frames/__init__.py +0 -0
  120. /pylegend/core/tds/{legend_api → legacy_api}/frames/functions/__init__.py +0 -0
  121. /pylegend/extensions/tds/{legend_api → legacy_api}/__init__.py +0 -0
  122. /pylegend/extensions/tds/{legend_api → legacy_api}/frames/__init__.py +0 -0
  123. {pylegend-0.3.0.dist-info → pylegend-0.5.0.dist-info}/LICENSE +0 -0
  124. {pylegend-0.3.0.dist-info → pylegend-0.5.0.dist-info}/LICENSE.spdx +0 -0
@@ -16,7 +16,7 @@ from pylegend._typing import (
16
16
  PyLegendList,
17
17
  PyLegendSequence,
18
18
  )
19
- from pylegend.core.tds.legend_api.frames.legend_api_applied_function_tds_frame import LegendApiAppliedFunction
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.legend_api.frames.legend_api_base_tds_frame import LegendApiBaseTdsFrame
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
- "RenameColumnsFunction"
34
+ "LegacyApiRenameColumnsFunction"
33
35
  ]
34
36
 
35
37
 
36
- class RenameColumnsFunction(LegendApiAppliedFunction):
37
- __base_frame: LegendApiBaseTdsFrame
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: LegendApiBaseTdsFrame,
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 base_frame(self) -> LegendApiBaseTdsFrame:
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["LegendApiBaseTdsFrame"]:
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.legend_api.frames.legend_api_applied_function_tds_frame import LegendApiAppliedFunction
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.legend_api.frames.legend_api_base_tds_frame import LegendApiBaseTdsFrame
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
- "RestrictFunction"
35
+ "LegacyApiRestrictFunction"
34
36
  ]
35
37
 
36
38
 
37
- class RestrictFunction(LegendApiAppliedFunction):
38
- __base_frame: LegendApiBaseTdsFrame
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: LegendApiBaseTdsFrame, column_name_list: PyLegendList[str]) -> None:
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 base_frame(self) -> LegendApiBaseTdsFrame:
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["LegendApiBaseTdsFrame"]:
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.legend_api.frames.legend_api_applied_function_tds_frame import LegendApiAppliedFunction
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.legend_api.frames.legend_api_base_tds_frame import LegendApiBaseTdsFrame
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
- "SliceFunction"
32
+ "LegacyApiSliceFunction"
32
33
  ]
33
34
 
34
35
 
35
- class SliceFunction(LegendApiAppliedFunction):
36
- __base_frame: LegendApiBaseTdsFrame
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: LegendApiBaseTdsFrame, start_row: int, end_row: int) -> None:
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 base_frame(self) -> LegendApiBaseTdsFrame:
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["LegendApiBaseTdsFrame"]:
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.legend_api.frames.legend_api_applied_function_tds_frame import LegendApiAppliedFunction
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.legend_api.frames.legend_api_base_tds_frame import LegendApiBaseTdsFrame
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
- "SortFunction"
38
+ "LegacyApiSortFunction"
37
39
  ]
38
40
 
39
41
 
40
- class SortFunction(LegendApiAppliedFunction):
41
- __base_frame: LegendApiBaseTdsFrame
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: LegendApiBaseTdsFrame,
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 base_frame(self) -> LegendApiBaseTdsFrame:
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["LegendApiBaseTdsFrame"]:
106
+ def tds_frame_parameters(self) -> PyLegendList["LegacyApiBaseTdsFrame"]:
96
107
  return []
97
108
 
98
109
  def calculate_columns(self) -> PyLegendSequence["TdsColumn"]:
@@ -0,0 +1,37 @@
1
+ # Copyright 2023 Goldman Sachs
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from abc import ABCMeta, abstractmethod
16
+ from pylegend._typing import (
17
+ PyLegendSequence,
18
+ )
19
+ from pylegend.core.tds.abstract.frames.applied_function_tds_frame import AppliedFunction, AppliedFunctionTdsFrame
20
+ from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
21
+
22
+
23
+ __all__: PyLegendSequence[str] = [
24
+ "LegacyApiAppliedFunctionTdsFrame",
25
+ "LegacyApiAppliedFunction",
26
+ ]
27
+
28
+
29
+ class LegacyApiAppliedFunction(AppliedFunction, metaclass=ABCMeta):
30
+ @abstractmethod
31
+ def tds_frame_parameters(self) -> PyLegendSequence["LegacyApiBaseTdsFrame"]:
32
+ pass # pragma: no cover
33
+
34
+
35
+ class LegacyApiAppliedFunctionTdsFrame(LegacyApiBaseTdsFrame, AppliedFunctionTdsFrame):
36
+ def __init__(self, applied_function: LegacyApiAppliedFunction):
37
+ AppliedFunctionTdsFrame.__init__(self, applied_function)
@@ -0,0 +1,204 @@
1
+ # Copyright 2023 Goldman Sachs
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from abc import ABCMeta
16
+
17
+ from pylegend._typing import (
18
+ PyLegendSequence,
19
+ PyLegendTypeVar,
20
+ PyLegendList,
21
+ PyLegendOptional,
22
+ PyLegendCallable,
23
+ PyLegendUnion,
24
+ )
25
+ from pylegend.core.language import (
26
+ LegacyApiTdsRow,
27
+ PyLegendBoolean,
28
+ PyLegendPrimitiveOrPythonPrimitive,
29
+ LegacyApiAggregateSpecification,
30
+ )
31
+ from pylegend.core.tds.abstract.frames.base_tds_frame import BaseTdsFrame
32
+ from pylegend.core.tds.legacy_api.frames.legacy_api_tds_frame import LegacyApiTdsFrame
33
+ from pylegend.core.tds.tds_column import TdsColumn
34
+
35
+ __all__: PyLegendSequence[str] = [
36
+ "LegacyApiBaseTdsFrame"
37
+ ]
38
+
39
+ R = PyLegendTypeVar('R')
40
+
41
+
42
+ class LegacyApiBaseTdsFrame(LegacyApiTdsFrame, BaseTdsFrame, metaclass=ABCMeta):
43
+
44
+ def __init__(self, columns: PyLegendSequence[TdsColumn]) -> None:
45
+ BaseTdsFrame.__init__(self, columns=columns)
46
+
47
+ def head(self, row_count: int = 5) -> "LegacyApiTdsFrame":
48
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
49
+ LegacyApiAppliedFunctionTdsFrame
50
+ )
51
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_head_function import (
52
+ LegacyApiHeadFunction
53
+ )
54
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiHeadFunction(self, row_count))
55
+
56
+ def take(self, row_count: int = 5) -> "LegacyApiTdsFrame":
57
+ return self.head(row_count=row_count)
58
+
59
+ def limit(self, row_count: int = 5) -> "LegacyApiTdsFrame":
60
+ return self.head(row_count=row_count)
61
+
62
+ def drop(self, row_count: int = 5) -> "LegacyApiTdsFrame":
63
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
64
+ LegacyApiAppliedFunctionTdsFrame
65
+ )
66
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_drop_function import (
67
+ LegacyApiDropFunction
68
+ )
69
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiDropFunction(self, row_count))
70
+
71
+ def slice(self, start_row: int, end_row_exclusive: int) -> "LegacyApiTdsFrame":
72
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
73
+ LegacyApiAppliedFunctionTdsFrame
74
+ )
75
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_slice_function import (
76
+ LegacyApiSliceFunction
77
+ )
78
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiSliceFunction(self, start_row, end_row_exclusive))
79
+
80
+ def distinct(self) -> "LegacyApiTdsFrame":
81
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
82
+ LegacyApiAppliedFunctionTdsFrame
83
+ )
84
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_distinct_function import (
85
+ LegacyApiDistinctFunction
86
+ )
87
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiDistinctFunction(self))
88
+
89
+ def restrict(self, column_name_list: PyLegendList[str]) -> "LegacyApiTdsFrame":
90
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
91
+ LegacyApiAppliedFunctionTdsFrame
92
+ )
93
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_restrict_function import (
94
+ LegacyApiRestrictFunction
95
+ )
96
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiRestrictFunction(self, column_name_list))
97
+
98
+ def sort(
99
+ self,
100
+ column_name_list: PyLegendList[str],
101
+ direction_list: PyLegendOptional[PyLegendList[str]] = None
102
+ ) -> "LegacyApiTdsFrame":
103
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
104
+ LegacyApiAppliedFunctionTdsFrame
105
+ )
106
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_sort_function import (
107
+ LegacyApiSortFunction
108
+ )
109
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiSortFunction(self, column_name_list, direction_list))
110
+
111
+ def concatenate(self, other: "LegacyApiTdsFrame") -> "LegacyApiTdsFrame":
112
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
113
+ LegacyApiAppliedFunctionTdsFrame
114
+ )
115
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_concatenate_function import (
116
+ LegacyApiConcatenateFunction
117
+ )
118
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiConcatenateFunction(self, other))
119
+
120
+ def rename_columns(
121
+ self,
122
+ column_names: PyLegendList[str],
123
+ renamed_column_names: PyLegendList[str]
124
+ ) -> "LegacyApiTdsFrame":
125
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
126
+ LegacyApiAppliedFunctionTdsFrame
127
+ )
128
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_rename_columns_function import (
129
+ LegacyApiRenameColumnsFunction
130
+ )
131
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiRenameColumnsFunction(self, column_names, renamed_column_names))
132
+
133
+ def filter(
134
+ self,
135
+ filter_function: PyLegendCallable[[LegacyApiTdsRow], PyLegendUnion[bool, PyLegendBoolean]]
136
+ ) -> "LegacyApiTdsFrame":
137
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
138
+ LegacyApiAppliedFunctionTdsFrame
139
+ )
140
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_filter_function import (
141
+ LegacyApiFilterFunction
142
+ )
143
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiFilterFunction(self, filter_function))
144
+
145
+ def extend(
146
+ self,
147
+ functions_list: PyLegendList[PyLegendCallable[[LegacyApiTdsRow], PyLegendPrimitiveOrPythonPrimitive]],
148
+ column_names_list: PyLegendList[str]
149
+ ) -> "LegacyApiTdsFrame":
150
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
151
+ LegacyApiAppliedFunctionTdsFrame
152
+ )
153
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_extend_function import (
154
+ LegacyApiExtendFunction
155
+ )
156
+ return LegacyApiAppliedFunctionTdsFrame(LegacyApiExtendFunction(self, functions_list, column_names_list))
157
+
158
+ def join(
159
+ self,
160
+ other: "LegacyApiTdsFrame",
161
+ join_condition: PyLegendCallable[[LegacyApiTdsRow, LegacyApiTdsRow], PyLegendUnion[bool, PyLegendBoolean]],
162
+ join_type: str = 'LEFT_OUTER'
163
+ ) -> "LegacyApiTdsFrame":
164
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
165
+ LegacyApiAppliedFunctionTdsFrame
166
+ )
167
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_join_function import (
168
+ LegacyApiJoinFunction
169
+ )
170
+ return LegacyApiAppliedFunctionTdsFrame(
171
+ LegacyApiJoinFunction(self, other, join_condition, join_type)
172
+ )
173
+
174
+ def join_by_columns(
175
+ self,
176
+ other: "LegacyApiTdsFrame",
177
+ self_columns: PyLegendList[str],
178
+ other_columns: PyLegendList[str],
179
+ join_type: str = 'LEFT_OUTER'
180
+ ) -> "LegacyApiTdsFrame":
181
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
182
+ LegacyApiAppliedFunctionTdsFrame
183
+ )
184
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_join_by_columns_function import (
185
+ LegacyApiJoinByColumnsFunction
186
+ )
187
+ return LegacyApiAppliedFunctionTdsFrame(
188
+ LegacyApiJoinByColumnsFunction(self, other, self_columns, other_columns, join_type)
189
+ )
190
+
191
+ def group_by(
192
+ self,
193
+ grouping_columns: PyLegendList[str],
194
+ aggregations: PyLegendList[LegacyApiAggregateSpecification],
195
+ ) -> "LegacyApiTdsFrame":
196
+ from pylegend.core.tds.legacy_api.frames.legacy_api_applied_function_tds_frame import (
197
+ LegacyApiAppliedFunctionTdsFrame
198
+ )
199
+ from pylegend.core.tds.legacy_api.frames.functions.legacy_api_group_by_function import (
200
+ LegacyApiGroupByFunction
201
+ )
202
+ return LegacyApiAppliedFunctionTdsFrame(
203
+ LegacyApiGroupByFunction(self, grouping_columns, aggregations)
204
+ )
@@ -0,0 +1,51 @@
1
+ # Copyright 2023 Goldman Sachs
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from abc import ABCMeta
16
+ from pylegend._typing import (
17
+ PyLegendSequence,
18
+ )
19
+ from pylegend.core.tds.abstract.frames.input_tds_frame import (
20
+ InputTdsFrame,
21
+ ExecutableInputTdsFrame,
22
+ NonExecutableInputTdsFrame,
23
+ )
24
+ from pylegend.core.tds.tds_column import TdsColumn
25
+ from pylegend.core.tds.legacy_api.frames.legacy_api_base_tds_frame import LegacyApiBaseTdsFrame
26
+ from pylegend.core.request.legend_client import LegendClient
27
+
28
+
29
+ __all__: PyLegendSequence[str] = [
30
+ "LegacyApiExecutableInputTdsFrame",
31
+ "LegacyApiNonExecutableInputTdsFrame",
32
+ "LegacyApiInputTdsFrame"
33
+ ]
34
+
35
+
36
+ class LegacyApiInputTdsFrame(LegacyApiBaseTdsFrame, InputTdsFrame, metaclass=ABCMeta):
37
+ def __init__(self, columns: PyLegendSequence[TdsColumn]) -> None:
38
+ LegacyApiBaseTdsFrame.__init__(self, columns=columns)
39
+ InputTdsFrame.__init__(self, columns=columns)
40
+
41
+
42
+ class LegacyApiExecutableInputTdsFrame(LegacyApiInputTdsFrame, ExecutableInputTdsFrame, metaclass=ABCMeta):
43
+ def __init__(self, legend_client: LegendClient, columns: PyLegendSequence[TdsColumn]) -> None:
44
+ LegacyApiInputTdsFrame.__init__(self, columns=columns)
45
+ ExecutableInputTdsFrame.__init__(self, legend_client=legend_client, columns=columns)
46
+
47
+
48
+ class LegacyApiNonExecutableInputTdsFrame(LegacyApiInputTdsFrame, NonExecutableInputTdsFrame, metaclass=ABCMeta):
49
+ def __init__(self, columns: PyLegendSequence[TdsColumn]) -> None:
50
+ LegacyApiInputTdsFrame.__init__(self, columns=columns)
51
+ NonExecutableInputTdsFrame.__init__(self, columns=columns)