Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_execute_mdx_with_top_skip(self):
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.tm1_subset_all(DIMENSION_NAMES[0]).head(2)) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.tm1_subset_all(DIMENSION_NAMES[1]).head(2)) \
.where(Member.of(DIMENSION_NAMES[2], "Element1")) \
.to_mdx()
cells = self.tm1.cubes.cells.execute_mdx(mdx=mdx, top=1, skip=2)
self.assertEqual(len(cells), 1)
elements = element_names_from_element_unique_names(list(cells.keys())[0])
self.assertEqual(elements, ("Element 2", "Element 1", "Element 1"))
('e1', 'e1'): 1,
('e1', 'e2'): 2,
('e1', 'e3'): 3,
}
self.tm1.cubes.cells.write_values(CUBE_RPS1_NAME, cells)
self.tm1.cubes.cells.relative_proportional_spread(
value=12,
cube=CUBE_RPS1_NAME,
unique_element_names=("[" + DIMENSION_RPS1_NAME + "].[" + DIMENSION_RPS1_NAME + "].[e2]",
"[" + DIMENSION_RPS2_NAME + "].[" + DIMENSION_RPS2_NAME + "].[c1]"),
reference_cube=CUBE_RPS1_NAME,
reference_unique_element_names=("[" + DIMENSION_RPS1_NAME + "].[" + DIMENSION_RPS1_NAME + "].[c1]",
"[" + DIMENSION_RPS2_NAME + "].[" + DIMENSION_RPS2_NAME + "].[c1]"))
mdx = MdxBuilder.from_cube(CUBE_RPS1_NAME) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_RPS1_NAME, "e2"))) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.members([
Member.of(DIMENSION_RPS2_NAME, "e1"),
Member.of(DIMENSION_RPS2_NAME, "e2"),
Member.of(DIMENSION_RPS2_NAME, "e3")])).to_mdx()
values = self.tm1.cubes.cells.execute_mdx_values(mdx)
self.assertEqual(next(values), 2)
self.assertEqual(next(values), 4)
self.assertEqual(next(values), 6)
def test_execute_view_rows_and_values_string_set(self):
mdx = MdxBuilder.from_cube(STRING_CUBE_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.tm1_subset_all(STRING_DIMENSION_NAMES[0])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.tm1_subset_all(STRING_DIMENSION_NAMES[2])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.tm1_subset_all(STRING_DIMENSION_NAMES[1])) \
.to_mdx()
view_name = "some view"
view = MDXView(cube_name=STRING_CUBE_NAME, view_name=view_name, MDX=mdx)
self.tm1.cubes.views.create(view, private=False)
elements_and_string_values = self.tm1.cubes.cells.execute_view_rows_and_values_string_set(
cube_name=STRING_CUBE_NAME,
view_name=view_name,
private=False)
self.assertEqual(
set(elements_and_string_values),
def test_clear_with_mdx_happy_case(self):
cells = {("Element17", "Element21", "Element15"): 1}
self.tm1.cells.write_values(CUBE_NAME, cells)
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[0], "Element17"))) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[1], "Element21"))) \
.where(Member.of(DIMENSION_NAMES[2], "Element15")) \
.to_mdx()
self.tm1.cells.clear_with_mdx(cube=CUBE_NAME, mdx=mdx)
value = next(self.tm1.cells.execute_mdx_values(mdx=mdx))
self.assertEqual(value, None)
def test_execute_mdx_elements_value_dict(self):
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.rows_non_empty() \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0])) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[1], DIMENSION_NAMES[1])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[2], DIMENSION_NAMES[2])) \
.to_mdx()
values = self.tm1.cubes.cells.execute_mdx_elements_value_dict(mdx)
# check type
self.assertIsInstance(values, dict)
# check coordinates
coordinates = {key for key, value in values.items()}
self.assertEqual(len(coordinates), len(self.target_coordinates))
# check values
def test_execute_mdx_dataframe(self):
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.rows_non_empty() \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0])) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[1], DIMENSION_NAMES[1])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[2], DIMENSION_NAMES[2])) \
.to_mdx()
df = self.tm1.cubes.cells.execute_mdx_dataframe(mdx)
# check type
self.assertIsInstance(df, pd.DataFrame)
# check coordinates in df are equal to target coordinates
coordinates = {
tuple(row)
for row
in df[[*DIMENSION_NAMES]].values}
def test_execute_mdx_raw_skip_contexts(self):
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[0], "Element1"))) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[1], "Element1"))) \
.add_member_to_where("[" + DIMENSION_NAMES[2] + "].[Element1]").to_mdx()
raw_response = self.tm1.cubes.cells.execute_mdx_raw(
mdx,
skip_contexts=True,
member_properties=["UniqueName"])
self.assertEqual(len(raw_response["Axes"]), 2)
for axis in raw_response["Axes"]:
dimension_on_axis = Utils.dimension_name_from_element_unique_name(
axis["Tuples"][0]["Members"][0]["UniqueName"])
self.assertNotEqual(dimension_on_axis, DIMENSION_NAMES[2])
def test_execute_mdx_rows_and_values_member_names(self):
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[0], "Element1"))) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[1], "Element1"))) \
.add_member_to_where("[" + DIMENSION_NAMES[2] + "].[Element1]").to_mdx()
data = self.tm1.cubes.cells.execute_mdx_rows_and_values(mdx, element_unique_names=False)
self.assertEqual(len(data), 1)
for row, cells in data.items():
member_name = row[0]
self.assertEqual(member_name, "Element 1")
def test_execute_mdx_values(self):
self.tm1.cells.write_values(CUBE_NAME, self.cellset)
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.columns_non_empty() \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[1], DIMENSION_NAMES[1])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[2], DIMENSION_NAMES[2])) \
.to_mdx()
cell_values = self.tm1.cubes.cells.execute_mdx_values(mdx)
self.assertIsInstance(
cell_values,
types.GeneratorType)
# Check if total value is the same. Handle None.
self.assertEqual(
self.total_value,
sum([v for v in cell_values if v]))
# Define MDX Query with calculated MEMBER
mdx = "WITH MEMBER[{}].[{}] AS 2 " \