Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute MDX Functions raise exceptions with "WITH MEMBER" is used in MDX #593

Closed
rclapp opened this issue Aug 11, 2021 · 8 comments
Closed
Labels

Comments

@rclapp
Copy link
Collaborator

rclapp commented Aug 11, 2021

Describe the bug
Execute MDX as dataframe functions do not support WITH MEMBER AS notation in MDX. Functions return exception
File "/var/task/tm1_service/api/data_fetcher_handler.py", line 146, in _execute_future future.result() File "/var/lang/lib/python3.8/concurrent/futures/_base.py", line 437, in result return self.__get_result() File "/var/lang/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result raise self._exception File "/var/lang/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/var/task/tm1_service/api/data_fetcher_handler.py", line 156, in _fetch_and_write_query_data tm1_response = tm1_repo.execute_mdx_query(query, dtype) File "/var/task/tm1_service/repository/tm1_repository.py", line 18, in execute_mdx_query result_data_frame = self._tm1_client.cubes.cells.execute_mdx_dataframe( File "/var/task/TM1py/Utils/Utils.py", line 52, in wrapper return func(self, *args, **kwargs) File "/var/task/TM1py/Services/CellService.py", line 1066, in execute_mdx_dataframe return self.extract_cellset_dataframe(cellset_id, top=top, skip=skip, skip_zeros=skip_zeros, File "/var/task/TM1py/Utils/Utils.py", line 52, in wrapper return func(self, *args, **kwargs) File "/var/task/TM1py/Services/CellService.py", line 1756, in extract_cellset_dataframe raw_csv = self.extract_cellset_csv(cellset_id=cellset_id, top=top, skip=skip, skip_zeros=skip_zeros, File "/var/task/TM1py/Services/CellService.py", line 1727, in extract_cellset_csv return build_csv_from_cellset_dict(rows, columns, cellset_dict, line_separator=line_separator, File "/var/task/TM1py/Utils/Utils.py", line 291, in build_csv_from_cellset_dict line_items = _build_csv_line_items_from_axis_tuple( File "/var/task/TM1py/Utils/Utils.py", line 319, in _build_csv_line_items_from_axis_tuple element_name = member['Element']['Name'] if 'Element' in member and member['Element'] else member['Name'] KeyError: 'Name'

After digging through the exception I found that the error is due to how the function is getting the NAME of the Element. Query scoped members do not have an Element Name, but rather have a Member Name. Need to update the method to build a CSV from a cellset to handle this case

@rclapp rclapp added the bug label Aug 11, 2021
@zsoltmoravcsik
Copy link

zsoltmoravcsik commented Aug 12, 2021 via email

@rclapp
Copy link
Collaborator Author

rclapp commented Aug 12, 2021 via email

@MariusWirtz
Copy link
Collaborator

Hi @rclapp,

I can't reproduce the error. The below code executes fine for me.

from TM1py import TM1Service

with TM1Service(address='', port=12354, ssl=True, user='admin', password='apple') as tm1:
    mdx = """
    WITH MEMBER[d2].[e81] AS 2
    SELECT[d1].MEMBERS ON ROWS,
    {[d2].[e81]} ON COLUMNS
    FROM[c1]
    """

    df = tm1.cells.execute_mdx_dataframe(mdx=mdx)

    print(df.head())

it assumes that you have a simple cube c1 with 2 dimensions d1, d2 with simple elements e1,e2

@rclapp
Copy link
Collaborator Author

rclapp commented Aug 12, 2021 via email

@MariusWirtz
Copy link
Collaborator

I can reproduce the issue. Will try to provide a fix.

@MariusWirtz
Copy link
Collaborator

It should be addressed with 8ae5e2d

@rclapp please double check

from TM1py import TM1Service

with TM1Service(address='', port=12354, ssl=True, user='admin', password='apple') as tm1:
    mdx = """
        WITH MEMBER[d2].[e81] AS 2
        SELECT[d1].MEMBERS  PROPERTIES [d1].[Attribute Something] ON ROWS,
        {[d2].[e81]}  PROPERTIES MEMBER_NAME ON COLUMNS
        FROM[c1]
        """

    print(tm1.cells.execute_mdx_dataframe(mdx=mdx, include_attributes=True, top=100))

@rclapp
Copy link
Collaborator Author

rclapp commented Aug 12, 2021 via email

@MariusWirtz
Copy link
Collaborator

Thanks for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants