GithubHelp home page GithubHelp logo

cubewise-code / mdxpy Goto Github PK

View Code? Open in Web Editor NEW
29.0 9.0 9.0 333 KB

A simple, yet elegant MDX library for TM1

License: MIT License

Python 100.00%
tm1 tm1-rest-api tm1py planning-analytics python mdx

mdxpy's People

Contributors

cubewise-gng avatar mariuswirtz avatar matt-schlinz-jabil avatar rclapp avatar vishn90 avatar vmitsenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdxpy's Issues

OrderedSet as container for MdxTuple members not ideal

mdxpy uses the OrderedSet as a container for members in the MdxTuple class. The added benefit is that if the same member is added multiple times to a tuple, it has no effect.

However, it comes at a cost of performance. According to my profiling analysis, on large MDX queries with (~ 500k explicit tuples) building the ordered sets takes ~50 % of the execution time.
If we replace the OrderedSet with a simple list, MDX construction will take roughly half the time of what it currently takes.
We are losing the comfort that Members can not be added multiple times to a MdxTuple.

Mdx and Attribute filtering

#1 this is an awesome addition to the TM1 toolkit, so thank you, I am excited to contribute.

#2 admittedly this is a bit of a blind spot for me but I wonder what is the "best" way to do attribute filtering. I have used all 3 ways in the past, but I don't know why you would use one over the others. Do you have any insight?

{FILTER({TM1SUBSETALL([Product] )}, [Product].[Product]. [Category]="Skis")}

{FILTER({TM1SUBSETALL( [Product] )}, [Product].[Product].Properties('Category')="Skis")}

{FILTER({TM1SUBSETALL([Product] )}, [Product].[}ElementAttributes_Product].([}ElementAttributes_Product].[}ElementAttributes_Product].[Category]) ="Skis")}

Are mdxsets ready to use?

Is the current master branch ready to use? Are you planning on releasing soon? I'd like to start using the MdxSet and cross join features, but figured I'd confirm that it's ready for public use first.

Unable to add an MDX Tuple to an axis directly

Trying to add an MDX tuple to an axis directly results in an exception or invalid MDX

  1. Add using HierarchySet methods
    mdx_tuple = mdxpy.MDXTuple.of(mdxpy.Member.of('Year','2019'), mdxpy.Member.of('Period','FY Total')) query.columns_non_empty().add_hierarchy_set_to_column_axis(mdx_tuple)

to_mdx:
SELECT
NON EMPTY ([YEAR].[YEAR].[2019],[PERIOD].[PERIOD].[FYTOTAL]) ON 0,
*Note the missing {} around the tuple

  1. Add using MDX Tuple Methods

mdx_tuple = mdxpy.MDXTuple.of(mdxpy.Member.of('Year','2019'), mdxpy.Member.of('Period','FY Total')) query.columns_non_empty().add_member_tuple_to_columns(mdx_tuple)
AttributeError: 'MdxTuple' object has no attribute 'unique_name'

I think we need a new method to add a tuple to an axis directly.

[Question] How to select multiple elements within the same dimension ?

Hello,
First of all, good job for this library, it's extremely useful ! My question might be stupid but I cannot find a way to specify multiple element within the same dimension. For example
.add_hierarchy_set_to_axis(0, MdxHierarchySet.member(Member.of("Region", "US")))
will return
{[region].[region].[us]} DIMENSION PROPERTIES MEMBER_NAME ON 0

But I want wondering how to return something like
{[region].[region].[us],[region].[region].[eu]} DIMENSION PROPERTIES MEMBER_NAME ON 0

Thank you

Functionality for aggregate rollups?

I have an MDX Query that I am trying to mirror,

WITH
SET [Virtual Measure:Virtual Measure:}rollup_1] AS {[Virtual Measure].[Virtual Measure].[Value]}
MEMBER [Virtual Measure].[Virtual Measure].[}rollup_1] AS AGGREGATE({[Virtual Measure:Virtual Measure:}rollup_1]})
SELECT {[Virtual Dimension].[Version].Members} ON COLUMNS ,
{[Virtual Dimension].[Measure].Members} ON ROWS
FROM [Sales Virtual]
WHERE (
[Virtual Measure].[Virtual Measure].[}rollup_1]
)

The only issue with this is I do not know of an aggregate function within MDXPy, nor do I see the capability to mirror the "SET ..." functionality on the second line of the MDX. Maybe I am just new to the library and do not see where the solution is, but I was hoping a contributor would have an idea of how to go about this.

Thanks in advance!

Create a Set of Tuples

Hi is there a way to create A set of tuples for example using mdxpy:

SELECT   
  {([Customer].[Country].[Australia], [Product].[Product Line].[Mountain]),
   ([Customer].[Country].[USA], [[Product].[Product Line].[Road])}
ON 0   
FROM [Adventure Works]  
WHERE Measures.[Internet Sales Amount]  

regards,

Ansir

Union and Crossjoin MdxHierarchySet

Would like to request for the ability to create a MdxSet.
Which would enable to Union and Crossjoin of MdxHierarchySet.

example

{
    {[VERSION].[VERSION].[ACTUAL]} * {[YEAR].[YEAR].[2021],[YEAR].[YEAR].[2022]} ,
    {[VERSION].[VERSION].[BUDGET]} * {[YEAR].[YEAR].[2023]}
} 

CrossJoin

Hi is it possible to do crossjoin queries using this package such as:

SELECT CROSSJOIN  
   (  
  {[Customer].[Country].[Australia],[Customer].[Country].[Canada]},
  {[Product].[Product Line].[Mountain],[Product].[Product Line].[Road]}
   ) ON 0   
FROM [Adventure Works]  
WHERE Measures.[Internet Sales Amount]  

or

SELECT   
  {[Customer].[Country].[Australia],[Customer].[Country].[Canada]}*
  {[Product].[Product Line].[Mountain],[Product].[Product Line].[Road]}
ON 0   
FROM [Adventure Works]  
WHERE Measures.[Internet Sales Amount]  

so the output will be a combination of all selected dimension values.

reference to this functionally are found at the following reference to this functionally are found at the following

DESCENDANTS needs additional arguments

The DESCENDANTS function in mdxpy doesn't yet take any of the optional arguments of the DESCENDANTS MDX function.

The actual DESCENDANTS function in MDX can be parametrized as discussed in this document.
https://docs.microsoft.com/de-de/sql/mdx/descendants-mdx?view=sql-server-ver16

The additional parameters of the DESCENDANTS function need to be exposed to the descendants function in the MdxHierarchySet and the DescendantsHierarchySet class needs to be modified to deal with the arguments and construct the mdx accordingly.

class DescendantsHierarchySet(MdxHierarchySet):

    def __init__(self, member: Member):
        super(DescendantsHierarchySet, self).__init__(member.dimension, member.hierarchy)
        self.member = member

    def to_mdx(self) -> str:
        return f"{{DESCENDANTS({self.member.unique_name})}}"`

Support DIMENSION PROPERTIES in mdxpy

MDXpy should support DIMENSION PROPERTIES. They are a standard feature of MDX and are supported in TM1. Since TM1 11 they can also be used in MDX datasources for TI.

Microsoft Reference:

https://docs.microsoft.com/de-de/analysis-services/multidimensional-models/mdx/mdx-member-properties-intrinsic-member-properties?view=asallproducts-allversions

TM1 sample

SELECT 
{[plan_time].[plan_time].[Q1-2004], [plan_time].[plan_time].[Q1-2004].CHILDREN} 
DIMENSION PROPERTIES [plan_time].[Time_Swedish] on 0,
[plan_chart_of_accounts].[plan_chart_of_accounts].MEMBERS 
DIMENSION PROPERTIES MEMBER_NAME on 1
FROM [plan_BudgetPlan]
WHERE ([plan_business_unit].[plan_business_unit].[10110], [plan_department].[plan_department].[105], [plan_source].[plan_source].[input]) 
DIMENSION PROPERTIES MEMBER_NAME, [plan_business_unit].[BusinessUnit_Swedish], [plan_business_unit].[Currency], [plan_department].[Department_Swedish]

More background in IBM Planning Analytics Forum

https://community.ibm.com/community/user/businessanalytics/communities/community-home/digestviewer/viewthread?GroupId=3067&MessageKey=beac9ad9-37cf-403c-9436-5fdb8fac8f87&CommunityKey=8fde0600-e22b-4178-acf5-bf4eda43146b&tab=digestviewer&ReturnUrl=%2fcommunity%2fuser%2fbusinessanalytics%2fcommunities%2fcommunity-home%2fdigestviewer%3fcommunitykey%3d8fde0600-e22b-4178-acf5-bf4eda43146b%26tab%3ddigestviewer

Performance drawback of hierarchy reference in MemberUniqueName

When using TM1py's write_values_through_cellset function there is a noticeable difference in write speed between MDX expressions that are using the full hierarchy aware syntax and [region].[region].[ch] the short syntax [region].[ch].

It would be useful if mdxpy offered a configuration to control if the short syntax is used for Members that are created without explicit Hierarchy reference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.