Exemplo n.º 1
0
    def test_mdx_hierarchy_set_except(self):
        hierarchy_set = MdxHierarchySet.member(Member.of("DIMENSION", "ELEMENT1")). \
            except_(MdxHierarchySet.member(Member.of("DIMENSION", "ELEMENT2")))

        self.assertEqual(
            "{EXCEPT({[DIMENSION].[DIMENSION].[ELEMENT1]},{[DIMENSION].[DIMENSION].[ELEMENT2]})}",
            hierarchy_set.to_mdx())
Exemplo n.º 2
0
    def test_mdx_hierarchy_set_union(self):
        hierarchy_set = MdxHierarchySet.member(Member.of("DIMENSION", "ELEMENT1")). \
            union(MdxHierarchySet.member(Member.of("DIMENSION", "ELEMENT2")))

        self.assertEqual(
            "{UNION({[DIMENSION].[DIMENSION].[ELEMENT1]},{[DIMENSION].[DIMENSION].[ELEMENT2]})}",
            hierarchy_set.to_mdx())
Exemplo n.º 3
0
    def test_mdx_hierarchy_set_intersect(self):
        hierarchy_set = MdxHierarchySet.member(Member.of("DIMENSION", "ELEMENT1")). \
            intersect(MdxHierarchySet.member(Member.of("DIMENSION", "ELEMENT2")))

        self.assertEqual(
            "{INTERSECT({[DIMENSION].[DIMENSION].[ELEMENT1]},{[DIMENSION].[DIMENSION].[ELEMENT2]})}",
            hierarchy_set.to_mdx())
Exemplo n.º 4
0
    def test_mdx_hierarchy_set_intersect(self):
        hierarchy_set = MdxHierarchySet.member(Member.of("dimension", "element1")). \
            intersect(MdxHierarchySet.member(Member.of("dimension", "element2")))

        self.assertEqual(
            "{INTERSECT({[dimension].[dimension].[element1]},{[dimension].[dimension].[element2]})}",
            hierarchy_set.to_mdx())
Exemplo n.º 5
0
    def test_mdx_hierarchy_set_except(self):
        hierarchy_set = MdxHierarchySet.member(Member.of("dimension", "element1")). \
            except_(MdxHierarchySet.member(Member.of("dimension", "element2")))

        self.assertEqual(
            "{EXCEPT({[dimension].[dimension].[element1]},{[dimension].[dimension].[element2]})}",
            hierarchy_set.to_mdx())
Exemplo n.º 6
0
    def test_mdx_hierarchy_set_union(self):
        hierarchy_set = MdxHierarchySet.member(Member.of("dimension", "element1")). \
            union(MdxHierarchySet.member(Member.of("dimension", "element2")))

        self.assertEqual(
            "{UNION({[dimension].[dimension].[element1]},{[dimension].[dimension].[element2]})}",
            hierarchy_set.to_mdx())
Exemplo n.º 7
0
    def test_mdx_set_cross_joins(self):
        mdx_set = MdxSet.cross_joins([
            MdxHierarchySet.children(Member.of("Dimension", "element1")),
            MdxHierarchySet.member(Member.of("Dimension", "element2")),
            MdxHierarchySet.member(Member.of("Dimension", "element3"))
        ])

        self.assertEqual(
            "{{[dimension].[dimension].[element1].CHILDREN}"
            " * {[dimension].[dimension].[element2]}"
            " * {[dimension].[dimension].[element3]}}", mdx_set.to_mdx())
Exemplo n.º 8
0
    def test_mdx_set_unions_allow_duplicates(self):
        hierarchy_set = MdxSet.unions([
            MdxHierarchySet.children(Member.of("Dimension", "element1")),
            MdxHierarchySet.member(Member.of("Dimension", "element2")),
            MdxHierarchySet.member(Member.of("Dimension", "element3"))
        ], True)

        self.assertEqual(
            "{{[dimension].[dimension].[element1].CHILDREN},"
            "{[dimension].[dimension].[element2]},"
            "{[dimension].[dimension].[element3]}}", hierarchy_set.to_mdx())
Exemplo n.º 9
0
    def test_mdx_hierarchy_set_unions_no_duplicates(self):
        hierarchy_set = MdxHierarchySet.unions([
            MdxHierarchySet.children(Member.of("Dimension", "element1")),
            MdxHierarchySet.member(Member.of("Dimension", "element2")),
            MdxHierarchySet.member(Member.of("Dimension", "element3"))
        ])

        self.assertEqual(
            "{{[DIMENSION].[DIMENSION].[ELEMENT1].CHILDREN}"
            " + {[DIMENSION].[DIMENSION].[ELEMENT2]}"
            " + {[DIMENSION].[DIMENSION].[ELEMENT3]}}", hierarchy_set.to_mdx())
Exemplo n.º 10
0
    def test_mdx_builder_multi_axes(self):
        mdx = MdxBuilder.from_cube("cube") \
            .add_hierarchy_set_to_axis(0, MdxHierarchySet.member(Member.of("Dim1", "Elem1"))) \
            .add_hierarchy_set_to_axis(1, MdxHierarchySet.member(Member.of("Dim2", "Elem2"))) \
            .add_hierarchy_set_to_axis(2, MdxHierarchySet.member(Member.of("Dim3", "Elem3"))) \
            .add_hierarchy_set_to_axis(3, MdxHierarchySet.member(Member.of("Dim4", "Elem4"))) \
            .add_hierarchy_set_to_axis(4, MdxHierarchySet.member(Member.of("Dim5", "Elem5"))) \
            .to_mdx()

        self.assertEqual(
            "SELECT\r\n"
            "{[dim1].[dim1].[elem1]} ON 0,\r\n"
            "{[dim2].[dim2].[elem2]} ON 1,\r\n"
            "{[dim3].[dim3].[elem3]} ON 2,\r\n"
            "{[dim4].[dim4].[elem4]} ON 3,\r\n"
            "{[dim5].[dim5].[elem5]} ON 4\r\n"
            "FROM [cube]", mdx)
Exemplo n.º 11
0
    def test_mdx_builder_single_axes(self):
        mdx = MdxBuilder.from_cube("cube") \
            .add_hierarchy_set_to_axis(0, MdxHierarchySet.member(Member.of("Dim1", "Elem1"))) \
            .to_mdx()

        self.assertEqual(
            "SELECT\r\n"
            "{[dim1].[dim1].[elem1]} ON 0\r\n"
            "FROM [cube]", mdx)
Exemplo n.º 12
0
    def test_mdx_builder_multi_no_where(self):
        mdx = MdxBuilder.from_cube("cube") \
            .rows_non_empty() \
            .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("Dim1")) \
            .columns_non_empty() \
            .add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of("Dim2", "Elem2"))) \
            .to_mdx()

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY {[dim2].[dim2].[elem2]} ON 0,\r\n"
            "NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([dim1].[dim1])},0)} ON 1\r\n"
            "FROM [cube]", mdx)
Exemplo n.º 13
0
    def test_mdx_builder_simple(self):
        mdx = MdxBuilder.from_cube("CUBE") \
            .rows_non_empty() \
            .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("Dim1")) \
            .columns_non_empty() \
            .add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of("Dim2", "Elem2"))) \
            .where(Member.of("Dim3", "Elem3"), Member.of("Dim4", "Elem4")) \
            .to_mdx()

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY {[DIM2].[DIM2].[ELEM2]} ON 0,\r\n"
            "NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([DIM1].[DIM1])},0)} ON 1\r\n"
            "FROM [CUBE]\r\n"
            "WHERE ([DIM3].[DIM3].[ELEM3],[DIM4].[DIM4].[ELEM4])", mdx)
Exemplo n.º 14
0
    def test_mdx_builder_tm1_ignore_bad_tuples(self):
        mdx = MdxBuilder.from_cube("cube") \
            .tm1_ignore_bad_tuples() \
            .rows_non_empty() \
            .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("Dim1")) \
            .columns_non_empty() \
            .add_hierarchy_set_to_column_axis(MdxHierarchySet.member(Member.of("Dim2", "Elem2"))) \
            .where(Member.of("Dim3", "Elem3"), Member.of("Dim4", "Elem4")) \
            .to_mdx()

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY TM1IGNORE_BADTUPLES {[dim2].[dim2].[elem2]} ON 0,\r\n"
            "NON EMPTY TM1IGNORE_BADTUPLES {TM1FILTERBYLEVEL({TM1SUBSETALL([dim1].[dim1])},0)} ON 1\r\n"
            "FROM [cube]\r\n"
            "WHERE ([dim3].[dim3].[elem3],[dim4].[dim4].[elem4])", mdx)