如何从 IBM TM1 中提取数据

How to pull data from IBM TM1

我已经使用 Python 的 TM1py 包在 Python 和 IBM TM1 OLAP 工具之间建立了连接。现在,当我尝试从 Python 中的 TM1 的 MDX 视图中获取数据时,我得到的只是列 headers。我阅读了 TM1py 的文档,看起来 get_native_view 函数应该只是 return 视图的一个实例,而不是视图中包含的实际数据。

from TM1py.Services import TM1Service

with TM1Service(address='hostname', port=12523,user='username', password=****, ssl=False) as tm1:

query = tm1.cubes.views.get_native_view('cube_name', 'View_name', private=True)
print(query)

有谁知道从 Python 中的 TM1 提取实际数据而不仅仅是列 headers 的方法吗?

get_native_view函数returns多维数据集视图的定义。

要使用 TM1py 将多维数据集数据从 IBM TM1 提取到 Python,您可以使用 get_view_content 函数(选项 1)或执行 MDX 查询(选项 2)。

选项 1:

from TM1py.Services import TM1Service

with TM1Service(address='localhost', port=12354, user='admin', password='apple', ssl=True) as tm1:
    content = tm1.cubes.cells.get_view_content(cube_name='Plan_BudgetPlan', view_name='Default', private=False)
    print(content)

选项 2:

from TM1py.Services import TM1Service

with TM1Service(address='localhost', port=12354, user='admin', password='apple', ssl=True) as tm1:
    mdx = "SELECT " \
          "NON EMPTY {TM1SUBSETALL( [}Clients] )} on ROWS, " \
          "NON EMPTY {TM1SUBSETALL( [}Groups] )} ON COLUMNS " \
          "FROM [}ClientGroups]"
    content = tm1.cubes.cells.execute_mdx(mdx)
    print(content)