如何通过使用 python 将 MDX 查询发送到 ActivePivot 来检索 CSV 输出文件?而不是 XMLA 或 Web 服务。
2 回答
从 ActivePivot 5.4 开始,有一个 POST 端点可以从 MDX 查询中获取 CSV 内容。
http://<host>/<app>/pivot/rest/v3/cube/export/mdx/download
通过使用以下 JSON 有效负载调用:
{
"jsonMdxQuery":
{
"mdx" : "<your MDX query>",
"context" : {}
},
"separator" : ";"
}
您将收到 CSV 格式的答案内容,其中的字段由;
.
但是,请注意,您的 MDX 格式会影响 CSV 格式。为了获得良好的结果,我建议您采用以下形式的 MDX 查询:
SELECT
// Measures as columns
{[Measures].[contributors.COUNT], ...} ON COLUMNS
// Members on rows
[Currency].[Currency].[Currency].Members ON ROWS
FROM [cube]
它将生成一个 CSV,如下所示:
[Measures].[Measures];[Currency].[Currency].[Currency];VALUE
contributors.COUNT;EUR;170
pnl.SUM;EUR;-8413.812452550741
...
干杯
您可以使用 ActivePivot Web 服务或 RESTful 服务,然后编写 Python 客户端并触发 MDX 查询:
使用网络服务:http://host:port/webapp/webservices
找IQueriesService
方法executeMDX
应该有帮助
或者
使用 RESTful 服务:http://host:port/webapp/pivot/rest/v3/cube/query?_wadl
寻找
<resource path="mdx">
<method name="POST">
<request>
<representation mediaType="application/json"/>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
您将获得查询结果,遍历检索到的记录并构建您自己的 csv。
另一种选择(仍然使用 RESTful 服务)是使用以下端点 http://host:port/webapp/pivot/rest/v3/cube/export?_wadl ,它允许您直接以 CSV 格式导出查询结果。