Skip to content

Commit e02f0c4

Browse files
vmitsenkoMariusWirtz
authored andcommitted
1. Fixed wrong position of brackets in extract_cellset_raw extract_cellset_metadata_raw
2. The name of the additional "tricky" parameter "top_rows" has been changed to "top_tuples" to avoid misunderstandings 3. A new test has been added to check execution of execute_mdx_raw with "top" parameter
1 parent bb72407 commit e02f0c4

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

TM1py/Services/CellService.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,13 +2689,17 @@ def extract_cellset_raw_response(
26892689
else:
26902690
expand_hierarchies = ""
26912691

2692+
# top_tuples parameter is used as an optimization trick:
2693+
# if top_cells is set to N => it will be sufficient to get only the first N tuples in Axes, top_tuples does this
2694+
# if skip_cells is used => trick not applicable, all tuples must be extracted
2695+
26922696
url = "/api/v1/Cellsets('{cellset_id}')?$expand=" \
26932697
"Cube($select=Name;$expand=Dimensions($select=Name))," \
26942698
"Axes({filter_axis}$expand={hierarchies}Tuples($expand=Members({select_member_properties}" \
2695-
"{expand_elem_properties}{top_rows})))," \
2699+
"{expand_elem_properties}){top_tuples}))," \
26962700
"Cells($select={cell_properties}{top_cells}{skip_cells}{filter_cells})" \
26972701
.format(cellset_id=cellset_id,
2698-
top_rows=f";$top={top}" if top and not skip else "",
2702+
top_tuples=f";$top={top}" if top and not skip else "",
26992703
cell_properties=",".join(cell_properties),
27002704
filter_axis=filter_axis,
27012705
hierarchies=expand_hierarchies,
@@ -2813,12 +2817,16 @@ def extract_cellset_metadata_raw(
28132817

28142818
filter_axis = "$filter=Ordinal ne 2;" if skip_contexts else ""
28152819

2820+
# top_tuples parameter is used as an optimization trick:
2821+
# if top_cells is set to N => it will be sufficient to get only the first N tuples in Axes, top_tuples does this
2822+
# if skip_cells is used => trick not applicable, all tuples must be extracted
2823+
28162824
url = "/api/v1/Cellsets('{cellset_id}')?$expand=" \
28172825
"Cube($select=Name;$expand=Dimensions($select=Name))," \
28182826
"Axes({filter_axis}$expand={hierarchies}Tuples($expand=Members({select_member_properties}" \
2819-
"{expand_elem_properties}{top_rows})))" \
2827+
"{expand_elem_properties}){top_tuples}))" \
28202828
.format(cellset_id=cellset_id,
2821-
top_rows=f";$top={top}" if top and not skip else "",
2829+
top_tuples=f";$top={top}" if top and not skip else "",
28222830
filter_axis=filter_axis,
28232831
hierarchies=expand_hierarchies,
28242832
select_member_properties=select_member_properties,

Tests/CellService_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,31 @@ def test_execute_mdx_raw_include_hierarchies(self):
17161716
self.assertEqual(self.dimension_names[axis_counter], hierarchies[0]['Name'])
17171717
self.assertEqual(self.dimension_names[axis_counter], hierarchies[0]['Dimension']['Name'])
17181718

1719+
def test_execute_mdx_raw_top(self):
1720+
# write cube content
1721+
self.tm1.cubes.cells.write_values(self.cube_name, self.cellset)
1722+
1723+
# MDX Query that gets full cube content with zero suppression
1724+
mdx = MdxBuilder.from_cube(self.cube_name) \
1725+
.rows_non_empty() \
1726+
.add_hierarchy_set_to_row_axis(
1727+
MdxHierarchySet.all_members(self.dimension_names[0], self.dimension_names[0])) \
1728+
.add_hierarchy_set_to_row_axis(
1729+
MdxHierarchySet.all_members(self.dimension_names[1], self.dimension_names[1])) \
1730+
.add_hierarchy_set_to_column_axis(
1731+
MdxHierarchySet.all_members(self.dimension_names[2], self.dimension_names[2])) \
1732+
.to_mdx()
1733+
1734+
# MDX with top
1735+
raw_response = self.tm1.cubes.cells.execute_mdx_raw(mdx, top=5)
1736+
1737+
# Check if the Axes length is equal to the "top" value
1738+
for axis in raw_response["Axes"]:
1739+
self.assertEqual(len(axis['Tuples']), 5)
1740+
1741+
# Check if the Cells length is equal to the "top" value
1742+
self.assertEqual(len(raw_response["Cells"]), 5)
1743+
17191744
def test_execute_mdx_rows_and_values_one_cell(self):
17201745
mdx = MdxBuilder.from_cube(self.cube_name) \
17211746
.add_hierarchy_set_to_axis(1, MdxHierarchySet.member(Member.of(self.dimension_names[0], "Element1"))) \

0 commit comments

Comments
 (0)