Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wrong position brackets in extract_cellset_raw (ref to 883 issue) #923

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
Expand Up @@ -2689,13 +2689,17 @@ def extract_cellset_raw_response(
else:
expand_hierarchies = ""

# top_tuples parameter is used as an optimization trick:
# if top_cells is set to N => it will be sufficient to get only the first N tuples in Axes, top_tuples does this
# if skip_cells is used => trick not applicable, all tuples must be extracted

url = "/api/v1/Cellsets('{cellset_id}')?$expand=" \
"Cube($select=Name;$expand=Dimensions($select=Name))," \
"Axes({filter_axis}$expand={hierarchies}Tuples($expand=Members({select_member_properties}" \
"{expand_elem_properties}{top_rows})))," \
"{expand_elem_properties}){top_tuples}))," \
"Cells($select={cell_properties}{top_cells}{skip_cells}{filter_cells})" \
.format(cellset_id=cellset_id,
top_rows=f";$top={top}" if top and not skip else "",
top_tuples=f";$top={top}" if top and not skip else "",
cell_properties=",".join(cell_properties),
filter_axis=filter_axis,
hierarchies=expand_hierarchies,
Expand Down Expand Up @@ -2813,12 +2817,16 @@ def extract_cellset_metadata_raw(

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

# top_tuples parameter is used as an optimization trick:
# if top_cells is set to N => it will be sufficient to get only the first N tuples in Axes, top_tuples does this
# if skip_cells is used => trick not applicable, all tuples must be extracted

url = "/api/v1/Cellsets('{cellset_id}')?$expand=" \
"Cube($select=Name;$expand=Dimensions($select=Name))," \
"Axes({filter_axis}$expand={hierarchies}Tuples($expand=Members({select_member_properties}" \
"{expand_elem_properties}{top_rows})))" \
"{expand_elem_properties}){top_tuples}))" \
.format(cellset_id=cellset_id,
top_rows=f";$top={top}" if top and not skip else "",
top_tuples=f";$top={top}" if top and not skip else "",
filter_axis=filter_axis,
hierarchies=expand_hierarchies,
select_member_properties=select_member_properties,
Expand Down
25 changes: 25 additions & 0 deletions Tests/CellService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,31 @@ def test_execute_mdx_raw_include_hierarchies(self):
self.assertEqual(self.dimension_names[axis_counter], hierarchies[0]['Name'])
self.assertEqual(self.dimension_names[axis_counter], hierarchies[0]['Dimension']['Name'])

def test_execute_mdx_raw_top(self):
# write cube content
self.tm1.cubes.cells.write_values(self.cube_name, self.cellset)

# MDX Query that gets full cube content with zero suppression
mdx = MdxBuilder.from_cube(self.cube_name) \
.rows_non_empty() \
.add_hierarchy_set_to_row_axis(
MdxHierarchySet.all_members(self.dimension_names[0], self.dimension_names[0])) \
.add_hierarchy_set_to_row_axis(
MdxHierarchySet.all_members(self.dimension_names[1], self.dimension_names[1])) \
.add_hierarchy_set_to_column_axis(
MdxHierarchySet.all_members(self.dimension_names[2], self.dimension_names[2])) \
.to_mdx()

# MDX with top
raw_response = self.tm1.cubes.cells.execute_mdx_raw(mdx, top=5)

# Check if the Axes length is equal to the "top" value
for axis in raw_response["Axes"]:
self.assertEqual(len(axis['Tuples']), 5)

# Check if the Cells length is equal to the "top" value
self.assertEqual(len(raw_response["Cells"]), 5)

def test_execute_mdx_rows_and_values_one_cell(self):
mdx = MdxBuilder.from_cube(self.cube_name) \
.add_hierarchy_set_to_axis(1, MdxHierarchySet.member(Member.of(self.dimension_names[0], "Element1"))) \
Expand Down