Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Partition Representation (Tabular)


Applies To: SQL Server 2016 Preview

For operational purposes, a table can be divided in different subsets of rows that when combined together form the table; each of those subsets is a partition of the table.

In terms of AMO objects a partition representation has a one to one mapping relationship with Partition and no other main AMO objects are required

When using AMO to manage a partition in a you need to find the measure group that represents the Tabular Model table and work from there.

The following code snippet shows how to add a partition to an existing tabular model table.

        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);

            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);

            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);

            //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.Update(AMO.UpdateOptions.ExpandFull, AMO.UpdateMode.UpdateOrCreate);
                if (processPartition)
                    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);
            catch (Exception)

However, to have an understanding on how to use AMO to create and manipulate partition representations see the source code of the AMO to Tabular sample. The sample is available at Codeplex. An important note about the code: the code is provided only as a support to the logical concepts explained here and should not be used in a production environment; nor should it be used for other purpose other than the pedagogical one.

Community Additions

© 2015 Microsoft