分区表示形式(表格)

为便于操作,可以将一个表划分为不同的行子集,而将这些行子集组合在一起可形成表;这些子集中的每个子集都是表的一个分区。

分区表示形式

就 AMO 对象而言,分区表示形式与 Partition 之间存在一对一映射关系,并且不需要任何其他主要 AMO 对象。

AMO 中的分区

在使用 AMO 管理分区时,您需要找到表示表格模型表的度量值组,并以此为起点开始工作。

下面的代码段演示如何向现有表格模型表添加分区。

        private void AddPartition(
                             AMO.Cube modelCube
                          ,  AMO.DataSource newDatasource
                          ,  string mgName
                          ,  string newPartitionName
                          , string partitionSelectStatement
                          , Boolean processPartition
                     )
        {
            mgName = mgName.Trim();
            newPartitionName = newPartitionName.Trim();
            partitionSelectStatement = partitionSelectStatement.Trim();
            //Validate Input
            if (string.IsNullOrEmpty(newPartitionName) || string.IsNullOrWhiteSpace(newPartitionName))
            {
                MessageBox.Show(String.Format("Partition Name cannot be empty or blank"), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (modelCube.MeasureGroups[mgName].Partitions.ContainsName(newPartitionName))
            {
                MessageBox.Show(String.Format("Partition Name already defined. Duplicated names are not allowed"), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(partitionSelectStatement) || string.IsNullOrWhiteSpace(partitionSelectStatement))
            {
                MessageBox.Show(String.Format("Select statement cannot be empty or blank"), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Input validated
            string partitionID = newPartitionName; //Using partition name as the ID
            AMO.Partition currentPartition = new AMO.Partition(partitionID, partitionID);
            currentPartition.StorageMode = AMO.StorageMode.InMemory;
            currentPartition.ProcessingMode = AMO.ProcessingMode.Regular;
            currentPartition.Source = new AMO.QueryBinding(newDatasource.ID, partitionSelectStatement);
            modelCube.MeasureGroups[mgName].Partitions.Add(currentPartition);
            try
            {
                modelCube.Update(AMO.UpdateOptions.ExpandFull, AMO.UpdateMode.UpdateOrCreate);
                if (processPartition)
                {
                    modelCube.MeasureGroups[mgName].Partitions[partitionID].Process(AMO.ProcessType.ProcessFull);
                    MessageBox.Show(String.Format("Partition successfully processed."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            catch (AMO.AmoException amoXp)
            {
                MessageBox.Show(String.Format("AMO exception accessing the server.\nError message: {0}", amoXp.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            catch (Exception)
            {
                throw;
            }
        }

AMO2Tabular 示例

但是,为了理解如何使用 AMO 创建和操作分区表示形式,请参阅 AMO 到表格示例中的源代码。 该示例在 Codeplex 上提供。 有关该代码的重要说明:提供该代码只是为了支持本文介绍的逻辑概念,不应用于生产环境中;也不应用于除教学之外的其他用途。