def test_mdx_tuple_add_element(self): tupl = MdxTuple.of(Member.of("Dimension1", "Hierarchy1", "Element1")) tupl.add_member(Member.of("Dimension2", "Hierarchy2", "Element2")) self.assertEqual(len(tupl), 2) self.assertEqual(tupl.members[0], Member.of("Dimension1", "Hierarchy1", "Element1")) self.assertEqual(tupl.members[1], Member.of("Dimension2", "Hierarchy2", "Element2"))
def test_mdx_builder_with_calculated_member(self): mdx = MdxBuilder.from_cube(cube="Cube").with_member( CalculatedMember.avg( dimension="Period", hierarchy="Period", element="AVG 2016", cube="Cube", mdx_set=MdxHierarchySet.children(member=Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dim1", "Total Dim1"), Member.of("Dim2", "Total Dim2")))) \ .rows_non_empty() \ .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("DIM1", "DIM1")) \ .columns_non_empty() \ .add_member_tuple_to_columns(Member.of("Period", "AVG 2016")) \ .where("[Dim2].[Total Dim2]") \ .to_mdx() self.assertEqual( "WITH\r\n" "MEMBER [PERIOD].[PERIOD].[AVG2016] AS AVG({[PERIOD].[PERIOD].[2016].CHILDREN}," "[CUBE].([DIM1].[DIM1].[TOTALDIM1],[DIM2].[DIM2].[TOTALDIM2]))\r\n" "SELECT\r\n" "NON EMPTY {([PERIOD].[PERIOD].[AVG2016])} ON 0,\r\n" "NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([DIM1].[DIM1])},0)} ON 1\r\n" "FROM [CUBE]\r\n" "WHERE ([DIM2].[DIM2].[TOTALDIM2])", mdx)
def test_mdx_hierarchy_set_order(self): hierarchy_set = MdxHierarchySet.all_members("Dimension1", "Hierarchy1").order( cube="Cube", mdx_tuple=MdxTuple.of( Member.of("Dimension2", "Hierarchy2", "ElementA"), Member.of("Dimension3", "Hierarchy3", "ElementB"))) self.assertEqual( "{ORDER({[DIMENSION1].[HIERARCHY1].MEMBERS}," "[CUBE].([DIMENSION2].[HIERARCHY2].[ELEMENTA],[DIMENSION3].[HIERARCHY3].[ELEMENTB]),BASC)}", hierarchy_set.to_mdx())
def test_mdx_hierarchy_set_bottom_count(self): hierarchy_set = MdxHierarchySet \ .tm1_subset_all("Dimension") \ .bottom_count("CUBE", MdxTuple.of(Member.of("DIMENSION2", "ELEMENT2"), Member.of("DIMENSION3", "ELEMENT3")), 10) self.assertEqual( "{BOTTOMCOUNT({TM1SUBSETALL([DIMENSION].[DIMENSION])}," "10," "[CUBE].([DIMENSION2].[DIMENSION2].[ELEMENT2],[DIMENSION3].[DIMENSION3].[ELEMENT3]))}", hierarchy_set.to_mdx())
def test_mdx_hierarchy_set_bottom_count(self): hierarchy_set = MdxHierarchySet \ .tm1_subset_all("Dimension") \ .bottom_count("cube", MdxTuple.of(Member.of("dimension2", "element2"), Member.of("dimension3", "element3")), 10) self.assertEqual( "{BOTTOMCOUNT({TM1SUBSETALL([dimension].[dimension])}," "10," "[cube].([dimension2].[dimension2].[element2],[dimension3].[dimension3].[element3]))}", hierarchy_set.to_mdx())
def test_calculated_member_lookup(self): calculated_member = CalculatedMember.lookup( "Period", "Period", "VersionAttribute1", cube="}ElementAttributes_Version", mdx_tuple=MdxTuple.of(Member.of("}ElementAttributes_Version", "Attribute1"))) self.assertEqual( calculated_member.to_mdx(), "MEMBER [PERIOD].[PERIOD].[VERSIONATTRIBUTE1] AS [}ELEMENTATTRIBUTES_VERSION]." "([}ELEMENTATTRIBUTES_VERSION].[}ELEMENTATTRIBUTES_VERSION].[ATTRIBUTE1])")
def test_mdx_set_tuples(self): mdx_set = MdxSet.tuples([ MdxTuple([ Member.of("dimension1", "element1"), Member.of("dimension2", "element3") ]), MdxTuple([ Member.of("dimension1", "element2"), Member.of("dimension2", "element2") ]), MdxTuple([ Member.of("dimension1", "element3"), Member.of("dimension2", "element1") ]) ]) self.assertEqual( "{ ([dimension1].[dimension1].[element1],[dimension2].[dimension2].[element3])," "([dimension1].[dimension1].[element2],[dimension2].[dimension2].[element2])," "([dimension1].[dimension1].[element3],[dimension2].[dimension2].[element1]) }", mdx_set.to_mdx())
def test_calculated_member_sum(self): calculated_member = CalculatedMember.sum( dimension="Period", hierarchy="Period", element="SUM 2016", cube="Cube", mdx_set=MdxHierarchySet.children(Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dimension1", "Element1"), Member.of("Dimension2", "Element2"))) self.assertEqual( calculated_member.to_mdx(), "MEMBER [PERIOD].[PERIOD].[SUM2016] AS SUM({[PERIOD].[PERIOD].[2016].CHILDREN},[CUBE]." "([DIMENSION1].[DIMENSION1].[ELEMENT1],[DIMENSION2].[DIMENSION2].[ELEMENT2]))")
def test_mdx_hierarchy_set_filter_by_cell_value_string(self): hierarchy_set = MdxHierarchySet.all_members("Dimension1", "Hierarchy1").filter_by_cell_value( cube="Cube", mdx_tuple=MdxTuple.of( Member.of("Dimension2", "ElementA"), Member.of("Dimension3", "ElementB")), operator="=", value='ABC') self.assertEqual( "{FILTER({[DIMENSION1].[HIERARCHY1].MEMBERS}," "[CUBE].([DIMENSION2].[DIMENSION2].[ELEMENTA],[DIMENSION3].[DIMENSION3].[ELEMENTB])='ABC')}", hierarchy_set.to_mdx())
def test_mdx_hierarchy_set_filter_by_cell_value_string(self): hierarchy_set = MdxHierarchySet.all_members( "Dimension1", "Hierarchy1").filter_by_cell_value( cube="Cube", mdx_tuple=MdxTuple.of(Member.of("Dimension2", "ElementA"), Member.of("Dimension3", "ElementB")), operator="=", value='ABC') self.assertEqual( "{FILTER({[dimension1].[hierarchy1].MEMBERS}," "[cube].([dimension2].[dimension2].[elementa],[dimension3].[dimension3].[elementb])='ABC')}", hierarchy_set.to_mdx())
def test_mdx_build_with_multi_calculated_member(self): mdx = MdxBuilder.from_cube(cube="Cube").with_member( CalculatedMember.avg( dimension="Period", hierarchy="Period", element="AVG 2016", cube="Cube", mdx_set=MdxHierarchySet.children(member=Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dim1", "Total Dim1"), Member.of("Dim2", "Total Dim2")))) \ .with_member( CalculatedMember.sum( dimension="Period", hierarchy="Period", element="SUM 2016", cube="Cube", mdx_set=MdxHierarchySet.children(member=Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dim1", "Total Dim1"), Member.of("Dim2", "Total Dim2")))) \ .rows_non_empty() \ .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("dim1", "dim1")) \ .columns_non_empty() \ .add_hierarchy_set_to_column_axis( MdxHierarchySet.members(members=[Member.of("Period", "AVG 2016"), Member.of("Period", "SUM 2016")])) \ .where(Member.of("Dim2", "Total Dim2")) \ .to_mdx() self.assertEqual( "WITH\r\n" "MEMBER [period].[period].[avg2016] AS AVG({[period].[period].[2016].CHILDREN}," "[cube].([dim1].[dim1].[totaldim1],[dim2].[dim2].[totaldim2]))\r\n" "MEMBER [period].[period].[sum2016] AS SUM({[period].[period].[2016].CHILDREN}," "[cube].([dim1].[dim1].[totaldim1],[dim2].[dim2].[totaldim2]))\r\n" "SELECT\r\n" "NON EMPTY {[period].[period].[avg2016],[period].[period].[sum2016]} ON 0,\r\n" "NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([dim1].[dim1])},0)} ON 1\r\n" "FROM [cube]\r\n" "WHERE ([dim2].[dim2].[totaldim2])", mdx)
def test_mdx_hierarchy_set_order(self): hierarchy_set = MdxHierarchySet.all_members( "Dimension1", "Hierarchy1").order(cube="Cube", mdx_tuple=MdxTuple.of( Member.of("Dimension2", "Hierarchy2", "ElementA"), Member.of("Dimension3", "Hierarchy3", "ElementB"))) self.assertEqual( "{ORDER({[dimension1].[hierarchy1].MEMBERS}," "[cube].([dimension2].[hierarchy2].[elementa],[dimension3].[hierarchy3].[elementb]),BASC)}", hierarchy_set.to_mdx())
def test_calculated_member_lookup(self): calculated_member = CalculatedMember.lookup( "Period", "Period", "VersionAttribute1", cube="}ELEMENTATTRIBUTES_version", mdx_tuple=MdxTuple.of( Member.of("}ELEMENTATTRIBUTES_version", "Attribute1"))) self.assertEqual( calculated_member.to_mdx(), "MEMBER [period].[period].[versionattribute1] AS [}elementattributes_version]." "([}elementattributes_version].[}elementattributes_version].[attribute1])" )
def test_calculated_member_sum(self): calculated_member = CalculatedMember.sum( dimension="Period", hierarchy="Period", element="SUM 2016", cube="Cube", mdx_set=MdxHierarchySet.children(Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dimension1", "Element1"), Member.of("Dimension2", "Element2"))) self.assertEqual( calculated_member.to_mdx(), "MEMBER [period].[period].[sum2016] AS SUM({[period].[period].[2016].CHILDREN},[cube]." "([dimension1].[dimension1].[element1],[dimension2].[dimension2].[element2]))" )
def test_mdx_tuple_empty(self): tupl = MdxTuple.empty() self.assertEqual(tupl.members, OrderedSet())