查询OLAP服务器

Posted

技术标签:

【中文标题】查询OLAP服务器【英文标题】:Querying OLAP server 【发布时间】:2012-04-02 22:19:30 【问题描述】:

我使用以下代码在 C# 中执行查询:

 AdomdConnection con = new AdomdConnection("Datasource=local;...");

            con.Open();
            AdomdCommand command = con.CreateCommand();
            command.CommandText = input;

            AdomdDataReader reader = command.ExecuteReader();
  while (reader.Read())
            
for(i =0; i<reader.fieldCount; i++)
      a[i]=reader.GetString(i);

return a;

但是,此代码返回层次结构中每个单元格的完整路径。即,每一行数据类似于 [AllGeography, Canada, Vancouver, Allproduct, bikes, Accessories, 297483]。 我只想检索叶子和测量值:[温哥华,附件,297483]。我该怎么办?如何指定叶子?

【问题讨论】:

【参考方案1】:

因为 MDX 查询的结果实际上是多维的,所以我觉得自己使用 ExecuteCellSet 更舒服。您可以获取整个 CellSet,然后通过坐标获取Measures。

例如(如果您在查询中有一个度量):

AdomdCommand cmd = conn.CreateCommand();
cmd.CommandText = @"SELECT 
            [Geography].[Geography].[Country].&[Canada].Children ON 0, 
            [Product].[Id] ON 1
            FROM [Cube]
            WHERE [Measures].[Your Measure]";

CellSet cs = cmd.ExecuteCellSet();

TupleCollection CanadaChildren = cs.Axes[0].Set.Tuples;
TupleCollection ProductIds = cs.Axes[1].Set.Tuples;

for (int row = 0; row < CanadaChildren.Count; row++)

    for (int col = 0; col < ProductIds.Count; col++)
    
        a[i++] = cs.Cells[col, row].Value;
    

conn.Close();

如果您有多个度量,则它将是查询中的第三个维度和单元集中的第三个坐标。

【讨论】:

以上是关于查询OLAP服务器的主要内容,如果未能解决你的问题,请参考以下文章

添加 where 条件使 MDX 查询变慢(olap4j)

Olap 立方体和 MDX 和 NON EMPTY

在网页中显示 OLAP SQL Server?

如何评估 MDX 在 OLAP 处理中的性能

猿辅导 x DorisDB:构建统一OLAP平台,全面升级数据分析能力

大数据OLAP查询引擎选型对比