XSLT for Analysis Services : replay the partition definition

Technical Value

Sometimes you want to backup the partition definitions of your cube and be able to (re)create them later easily. In another scenario you could want to mimic the production partitions on your test cube or vice versa.

Here we show the way of generating the XMLA batch command for partition creation using a simple XSL transformation against the XMLA cube definition. We consider MSAS 2008 R2 as our environment here.

The source XMLA that contains partition definitions can be obtained by scripting out the scope of interest (AS database, cube or measure group) in SQL Management Studio or just using the build result in Visual Studio: .asdatabase file or using WriteScript() in AMO in case it fits your infrastructure.

Instead of CREATE command for partitions we generate an ALTER with the option AllowCreate=true. It is more flexible than CREATE in many situations because it ignores the existing partitions with same definition and “fixes” the deviating attributes of partition with the same ID.

Now the whole cycle looks like following:

  1. Obtain the source XMLA with partition definitions (where <Partition> elements can be found)
  2. Apply the XSL transformation using the XSLT document below
  3. Optionally change the destination <DatabaseID> values in result XMLA script
  4. Run XMLA script against the destination Cube


Here is the XSLT definition:

  1. <xsl:stylesheet version="1.0" 
  2.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  3.                 xmlns:as="http://schemas.microsoft.com/analysisservices/2003/engine" >
  4.   <xsl:output omit-xml-declaration="yes"/>
  5.   <xsl:template match="/">
  6.     <Batch Transaction="true" 
  7.            xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" >
  8.       <xsl:for-each select="//as:Partition">
  9.         <Alter ObjectExpansion="ExpandFull" AllowCreate="true" 
  10.                xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" >
  12.           <Object>
  13.             <DatabaseID>
  14.               <xsl:value-of select="ancestor::as:Database/as:ID"/>
  15.             </DatabaseID>
  16.             <CubeID>
  17.               <xsl:value-of select="ancestor::as:Cube/as:ID"/>
  18.             </CubeID>
  19.             <MeasureGroupID>
  20.               <xsl:value-of select="ancestor::as:MeasureGroup/as:ID"/>
  21.             </MeasureGroupID>
  22.             <PartitionID>
  23.               <xsl:value-of select="as:ID"/>
  24.             </PartitionID>
  25.           </Object>
  27.           <ObjectDefinition>
  28.             <Partition  xmlns:xsd="http://www.w3.org/2001/XMLSchema"    
  29.                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  30.                xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2"    
  31.                xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2"    
  32.                xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100"    
  33.                xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200"    
  34.                xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" > 
  35.              <xsl:copy-of select="child::*"/>
  36.             </Partition>
  37.           </ObjectDefinition>
  39.         </Alter>
  40.       </xsl:for-each>
  41.     </Batch>
  42.   </xsl:template>
  43. </xsl:stylesheet>
  45. Note that the transformation searches for <Partition> ignoring its hierarchical position (select=”//as:Partition”). This unbinds you from the general structure of source XMLA definition and respectively from the method you obtain it!
  47. Note also that we copy one to one all partition elements: <xsl:copy-of select="child::*"/>
  49. Here is the sample output – a batch command for partition creation which can be executed in SQL Management Studio for example:
  51. <Batch Transaction="true"
  52.        xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"
  53.        xmlns:as="http://schemas.microsoft.com/analysisservices/2003/engine" >
  54.   <Alter ObjectExpansion="ExpandFull" AllowCreate="true">
  58.     <Object>
  59.       <DatabaseID>My_DB_ID</DatabaseID>
  60.       <CubeID>My_Cube_ID</CubeID>
  61.       <MeasureGroupID>My_MG_ID</MeasureGroupID>
  62.       <PartitionID>My Fact 2012</PartitionID>
  63.     </Object>
  65.     <ObjectDefinition>
  66.       <Partition xmlns:xsd="http://www.w3.org/2001/XMLSchema "
  67.                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
  68.                  xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2 "
  69.                  xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2 "
  70.                  xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100 "
  71.                  xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200 "
  72.                  xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200 ">
  73.         <ID>My Fact 2012</ID>
  74.         <Name>My Fact 2012</Name>
  75.         <Source xsi:type="QueryBinding">
  76.           <DataSourceID>MyDS</DataSourceID>
  77.           <QueryDefinition>SELECT * from dbo.FactTable where Year=2012</QueryDefinition>
  78.         </Source>
  79.         <StorageMode>Molap</StorageMode>
  80.         <Slice>[Date].[Year].&amp;[2012]</Slice>
  81.         <ProcessingMode>Regular</ProcessingMode>
  82.         <ProactiveCaching>
  83.           <SilenceInterval>-PT1S</SilenceInterval>
  84.           <Latency>-PT1S</Latency>
  85.           <SilenceOverrideInterval>-PT1S</SilenceOverrideInterval>
  86.           <ForceRebuildInterval>-PT1S</ForceRebuildInterval>
  87.           <Source xsi:type="ProactiveCachingInheritedBinding" />
  88.         </ProactiveCaching>
  89.       </Partition>
  90.     </ObjectDefinition>
  92.    </Alter>
  93. ...
  94. </Batch>

You can run the XSL transformation in many ways: XML Notepad, SSIS Package, XML editor in Management Studio or Visual Studio. For details on using XSLT and other scenarios for MSAS see our post:

    XPath and XSLT for the metadata analysis of Analysis Services objects .

Neuen Kommentar schreiben

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.


  • Keine HTML-Tags erlaubt.
  • HTML - Zeilenumbrüche und Absätze werden automatisch erzeugt.
  • Web page addresses and email addresses turn into links automatically.
Teilen auf

Newsletter Anmeldung

Abonnieren Sie unseren Newsletter!
Lassen Sie sich regelmäßig über alle Neuigkeiten rundum ORAYLIS und die BI- & Big-Data-Branche informieren.

Jetzt anmelden