How to use the mdxpy.MdxHierarchySet.all_members function in mdxpy

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_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
def test_execute_mdx_rows_and_values_string_set_against_numeric_cells(self):
        mdx = MdxBuilder.from_cube(CUBE_NAME) \
            .add_hierarchy_set_to_row_axis(
            MdxHierarchySet.all_members(DIMENSION_NAMES[0], DIMENSION_NAMES[0]).head(10)) \
            .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)) \
            .to_mdx()

        elements_and_string_values = self.tm1.cubes.cells.execute_mdx_rows_and_values_string_set(
            mdx=mdx,
            exclude_empty_cells=False)

        self.assertEqual(
            set(elements_and_string_values),
            {'Element 1',
             'Element 2',
             'Element 3',
             'Element 4',
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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 " \
              "SELECT[{}].MEMBERS ON ROWS, " \
              "{{[{}].[{}]}} ON COLUMNS " \
github cubewise-code / tm1py / Tests / Cell.py View on Github external
def test_execute_mdx(self):
        # write cube content
        self.tm1.cubes.cells.write_values(CUBE_NAME, self.cellset)

        # MDX Query that gets full cube content with zero suppression
        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()

        data = self.tm1.cubes.cells.execute_mdx(mdx)
        # Check if total value is the same AND coordinates are the same. Handle None
        self.assertEqual(self.total_value, sum([v["Value"] for v in data.values() if v["Value"]]))

        # MDX with top
        data = self.tm1.cubes.cells.execute_mdx(mdx, top=5)
        # Check if total value is the same AND coordinates are the same. Handle None
        self.assertEqual(len(data), 5)

        # MDX Query with calculated MEMBER
        mdx = """
        WITH MEMBER[{}].[{}] AS 2 
        SELECT[{}].MEMBERS ON ROWS, 
        {{[{}].[{}]}} ON COLUMNS 
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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
        values = [float(value) for _, value in values.items()]
        self.assertEqual(self.total_value, sum(values))
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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
        values = [float(value) for _, value in values.items()]
        self.assertEqual(self.total_value, sum(values))
github cubewise-code / tm1py / Tests / Cell.py View on Github external
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}
        self.assertEqual(
            len(coordinates),
github cubewise-code / tm1py / Tests / Cell.py View on Github external
def test_execute_mdx_cellcount(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])) \
            .columns_non_empty() \
            .add_hierarchy_set_to_column_axis(MdxHierarchySet.all_members(DIMENSION_NAMES[2], DIMENSION_NAMES[2])) \
            .to_mdx()

        cell_count = self.tm1.cubes.cells.execute_mdx_cellcount(mdx)
        self.assertGreater(cell_count, 1000)