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_view_rows_and_values_one_dimension_on_rows(self):
view_name = PREFIX + "MDX_View_With_One_Dim_On_Rows"
if not self.tm1.cubes.views.exists(cube_name=CUBE_NAME, view_name=view_name, private=False):
mdx = MdxBuilder.from_cube(CUBE_NAME).add_hierarchy_set_to_row_axis(MdxHierarchySet.members([
Member.of(DIMENSION_NAMES[0], "Element1"),
Member.of(DIMENSION_NAMES[0], "Element2")])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.members([
Member.of(DIMENSION_NAMES[1], "Element1"),
Member.of(DIMENSION_NAMES[1], "Element2"),
Member.of(DIMENSION_NAMES[1], "Element3")])) \
.where(Member.of(DIMENSION_NAMES[2], "Element1")) \
.to_mdx()
view = MDXView(cube_name=CUBE_NAME, view_name=view_name, MDX=mdx)
self.tm1.cubes.views.create(view, False)
data = self.tm1.cubes.cells.execute_view_rows_and_values(
cube_name=CUBE_NAME,
view_name=view_name,
private=False)
self.assertEqual(len(data), 2)
for row, cells in data.items():
dimension = Utils.dimension_name_from_element_unique_name(row[0])
self.assertEqual(dimension, DIMENSION_NAMES[0])
self.assertEqual(len(cells), 3)
def test_execute_view_rows_and_values_one_dimension_on_rows(self):
view_name = PREFIX + "MDX_View_With_One_Dim_On_Rows"
if not self.tm1.cubes.views.exists(cube_name=CUBE_NAME, view_name=view_name, private=False):
mdx = MdxBuilder.from_cube(CUBE_NAME).add_hierarchy_set_to_row_axis(MdxHierarchySet.members([
Member.of(DIMENSION_NAMES[0], "Element1"),
Member.of(DIMENSION_NAMES[0], "Element2")])) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.members([
Member.of(DIMENSION_NAMES[1], "Element1"),
Member.of(DIMENSION_NAMES[1], "Element2"),
Member.of(DIMENSION_NAMES[1], "Element3")])) \
.where(Member.of(DIMENSION_NAMES[2], "Element1")) \
.to_mdx()
view = MDXView(cube_name=CUBE_NAME, view_name=view_name, MDX=mdx)
self.tm1.cubes.views.create(view, False)
data = self.tm1.cubes.cells.execute_view_rows_and_values(
cube_name=CUBE_NAME,
view_name=view_name,
private=False)
self.assertEqual(len(data), 2)
for row, cells in data.items():
dimension = Utils.dimension_name_from_element_unique_name(row[0])
self.assertEqual(dimension, DIMENSION_NAMES[0])
def test_execute_mdx_skip_consolidated(self):
mdx = MdxBuilder.from_cube(CUBE_WITH_CONSOLIDATIONS_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.members([
Member.of(DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0], "Total_" + DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0]),
Member.of(DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0], "Element1")])) \
.add_hierarchy_set_to_column_axis(
MdxHierarchySet.member(Member.of(DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[1], "Element1"))) \
.add_member_to_where("[" + DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[2] + "].[Element1]").to_mdx()
data = self.tm1.cubes.cells.execute_mdx(mdx, skip_contexts=True, skip_consolidated_cells=True)
self.assertEqual(len(data), 1)
for coordinates, cell in data.items():
self.assertEqual(len(coordinates), 2)
self.assertEqual(
Utils.dimension_name_from_element_unique_name(coordinates[0]),
DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0])
self.assertEqual(
Utils.dimension_name_from_element_unique_name(coordinates[1]),
DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[1])
def test_execute_mdx_dataframe_pivot(self):
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0]).head(7)) \
.add_hierarchy_set_to_column_axis(
MdxHierarchySet.all_members(DIMENSION_NAMES[1], DIMENSION_NAMES[1]).head(8)) \
.where(Member.of(DIMENSION_NAMES[2], "Element1")) \
.to_mdx()
pivot = self.tm1.cubes.cells.execute_mdx_dataframe_pivot(mdx=mdx)
self.assertEqual(pivot.shape, (7, 8))
('e1', 'e2'): 2,
('e1', 'e3'): 3,
}
self.tm1.cubes.cells.write_values(CUBE_RPS2_NAME, cells)
self.tm1.cubes.cells.relative_proportional_spread(
value=12,
cube=CUBE_RPS1_NAME,
unique_element_names=("[" + DIMENSION_RPS1_NAME + "].[e2]", "[" + DIMENSION_RPS2_NAME + "].[c1]"),
reference_cube=CUBE_RPS2_NAME,
reference_unique_element_names=("[" + DIMENSION_RPS1_NAME + "].[c1]", "[" + 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_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_clear_with_mdx_all_on_axis0(self):
cells = {("Element19", "Element11", "Element31"): 1}
self.tm1.cells.write_values(CUBE_NAME, cells)
mdx = MdxBuilder.from_cube(CUBE_NAME) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[0], "Element19"))) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[1], "Element11"))) \
.add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of(DIMENSION_NAMES[2], "Element31"))) \
.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_skip_consolidated(self):
mdx = MdxBuilder.from_cube(CUBE_WITH_CONSOLIDATIONS_NAME) \
.add_hierarchy_set_to_row_axis(MdxHierarchySet.members([
Member.of(DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0], "Total_" + DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0]),
Member.of(DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0], "Element1")])) \
.add_hierarchy_set_to_column_axis(
MdxHierarchySet.member(Member.of(DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[1], "Element1"))) \
.add_member_to_where("[" + DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[2] + "].[Element1]").to_mdx()
data = self.tm1.cubes.cells.execute_mdx(mdx, skip_contexts=True, skip_consolidated_cells=True)
self.assertEqual(len(data), 1)
for coordinates, cell in data.items():
self.assertEqual(len(coordinates), 2)
self.assertEqual(
Utils.dimension_name_from_element_unique_name(coordinates[0]),
DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[0])
self.assertEqual(
Utils.dimension_name_from_element_unique_name(coordinates[1]),
DIMENSIONS_WITH_CONSOLIDATIONS_NAMES[1])