How to use mdxpy - 10 common examples

To help you get started, we’ve selected a few mdxpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cubewise-code / tm1py / Tests / Cell.py View on Github external
def test_execute_mdx_csv_skip(self):
        mdx = MdxBuilder.from_cube(CUBE_NAME) \
            .add_hierarchy_set_to_row_axis(
            MdxHierarchySet.all_members(DIMENSION_NAMES[1], DIMENSION_NAMES[1]).head(10)) \
            .add_hierarchy_set_to_column_axis(
            MdxHierarchySet.all_members(DIMENSION_NAMES[2], DIMENSION_NAMES[2]).head(10)) \
            .add_member_to_where(Member.of(DIMENSION_NAMES[0], "Element1")) \
            .to_mdx()

        csv = self.tm1.cubes.cells.execute_mdx_csv(mdx, skip=10, skip_zeros=False)

        records = csv.split("\r\n")
        self.assertEqual(91, len(records))
github cubewise-code / tm1py / Tests / Cell.py View on Github external
def test_execute_mdx_csv_with_calculated_member(self):
        # MDX Query with calculated MEMBER
        mdx = MdxBuilder.from_cube(CUBE_NAME).with_member(CalculatedMember.lookup_attribute(
            DIMENSION_NAMES[1],
            DIMENSION_NAMES[1],
            "Calculated Member",
            DIMENSION_NAMES[0],
            "Attr3")) \
            .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0])) \
            .add_hierarchy_set_to_column_axis(
            MdxHierarchySet.member(Member.of(DIMENSION_NAMES[1], "Calculated Member"))) \
            .to_mdx()

        csv = self.tm1.cubes.cells.execute_mdx_csv(mdx)

        # check header
        header = csv.split('\r\n')[0]
        self.assertEqual(
            ",".join(DIMENSION_NAMES[0:2] + ["Value"]),
            header)

        # check coordinates
        records = csv.split('\r\n')[1:]
        coordinates = {tuple(record.split(',')[0:2])
                       for record
github cubewise-code / tm1py / Tests / Cell.py View on Github external
def test_execute_mdx_csv_with_calculated_member(self):
        # MDX Query with calculated MEMBER
        mdx = MdxBuilder.from_cube(CUBE_NAME).with_member(CalculatedMember.lookup_attribute(
            DIMENSION_NAMES[1],
            DIMENSION_NAMES[1],
            "Calculated Member",
            DIMENSION_NAMES[0],
            "Attr3")) \
            .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0])) \
            .add_hierarchy_set_to_column_axis(
            MdxHierarchySet.member(Member.of(DIMENSION_NAMES[1], "Calculated Member"))) \
            .to_mdx()

        csv = self.tm1.cubes.cells.execute_mdx_csv(mdx)

        # check header
        header = csv.split('\r\n')[0]
        self.assertEqual(
            ",".join(DIMENSION_NAMES[0:2] + ["Value"]),
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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)
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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])
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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])
github cubewise-code / tm1py / Tests / Cell.py View on Github external
def test_read_write_with_custom_encoding_fail_response_encoding(self):
        coordinates = ("d1e1", "d2e2", "d3e3")
        self.tm1.cubes.cells.write_values(STRING_CUBE_NAME, {coordinates: LATIN_1_ENCODED_TEXT}, encoding="latin-1")

        mdx = MdxBuilder.from_cube(STRING_CUBE_NAME) \
            .add_hierarchy_set_to_column_axis(
            MdxHierarchySet.member(Member.of(STRING_DIMENSION_NAMES[0], coordinates[0]))) \
            .add_hierarchy_set_to_column_axis(
            MdxHierarchySet.member(Member.of(STRING_DIMENSION_NAMES[1], coordinates[1]))) \
            .add_hierarchy_set_to_column_axis(
            MdxHierarchySet.member(Member.of(STRING_DIMENSION_NAMES[2], coordinates[2]))) \
            .to_mdx()

        values = self.tm1.cubes.cells.execute_mdx_values(mdx=mdx)

        self.assertNotEqual(LATIN_1_ENCODED_TEXT, next(values))
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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))
github cubewise-code / tm1py / Tests / Cell.py View on Github external
('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)
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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])