SSIS處理CUbe-動態

場景:由SSIS動態生成的分區,在使用SSIS動態執行這些分區!html

  

 

 1、咱們知道執行某個分區的時候,實際上是由腳本去調用和配置的:java

腳本的內容:oracle

<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
  <ErrorConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
    <KeyErrorLimit>-1</KeyErrorLimit>
    <KeyNotFound>IgnoreError</KeyNotFound>
  </ErrorConfiguration>
  <Parallel>
    <Process xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
      <Object>
        <DatabaseID>Drug_SSAS</DatabaseID>
        <CubeID>Drug DW</CubeID>
        <MeasureGroupID>Fact OP Fee Detail</MeasureGroupID>
        <PartitionID>Fact OP Fee Detail 201702</PartitionID>
      </Object>
      <Type>ProcessData</Type>
      <WriteBackTableCreation>UseExisting</WriteBackTableCreation>
    </Process>
  </Parallel>
</Batch>
View Code

咱們只須要將腳本內的值,動態的賦值,便可按照咱們的配置進行執行分區或者度量值組。ide

2、使用SSIS執行指定的分區(當前時間的前2個月的分區):this

 

最終效果spa

 

參數準備:3d

2.1 、執行SQL任務:主要是將執行cube所需的參數構造並傳遞出去:code

SELECT 'Drug_SSAS'                                                         AS DatabaseID, 'Drug DW'                                                                       AS CubeID, 'Fact OP Fee Detail '                                                          AS MeasureGroupID, 'Fact OP Fee Detail ' + CONVERT(VARCHAR(6), Dateadd(month, -1, Getdate()), 112) AS PartitionID UNION

SELECT 'Drug_SSAS'                                      AS DatabaseID, 'Drug DW'                                                   AS CubeID, 'Fact OP Fee Detail '                                       AS MeasureGroupID, 'Fact OP Fee Detail ' + CONVERT(VARCHAR(6), Getdate(), 112) AS PartitionID
View Code

語句執行結果:orm

 

2.2 、Foreach 循環容器遍歷SQL任務的結果集:     xml

2.3 、執行腳本任務,處理Foreach 循環容器的每條結果:   

點擊「編輯腳本」:

#region Namespaces
using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; using System.Windows.Forms; #endregion

namespace ST_679fffc011334d1cb4eae175a9221ba1 { [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute] public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase { public void Main() { // TODO: Add your code here
 String sDatabaseID = Dts.Variables["User::DatabaseID"].Value.ToString(); String sCubeID = Dts.Variables["User::CubeID"].Value.ToString(); String sMeasureGroupID = Dts.Variables["User::MeasureGroupID"].Value.ToString().Trim(); String sPartitionID = Dts.Variables["User::PartitionID"].Value.ToString().Trim(); Dts.Variables["User::Xmla_Script"].Value = 
                    "<Batch xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">"
                    + "<ErrorConfiguration xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ddl2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2\" xmlns:ddl2_2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2/2\" xmlns:ddl100_100=\"http://schemas.microsoft.com/analysisservices/2008/engine/100/100\" xmlns:ddl200=\"http://schemas.microsoft.com/analysisservices/2010/engine/200\" xmlns:ddl200_200=\"http://schemas.microsoft.com/analysisservices/2010/engine/200/200\" xmlns:ddl300=\"http://schemas.microsoft.com/analysisservices/2011/engine/300\" xmlns:ddl300_300=\"http://schemas.microsoft.com/analysisservices/2011/engine/300/300\">"
                    + "<KeyErrorLimit>-1</KeyErrorLimit>"
                    + "<KeyNotFound>IgnoreError</KeyNotFound>"
                    + "<NullKeyNotAllowed>IgnoreError</NullKeyNotAllowed>"
                    + "</ErrorConfiguration>"
                    + "<Parallel>"
                    + "<Process xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ddl2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2\" xmlns:ddl2_2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2/2\" xmlns:ddl100_100=\"http://schemas.microsoft.com/analysisservices/2008/engine/100/100\" xmlns:ddl200=\"http://schemas.microsoft.com/analysisservices/2010/engine/200\" xmlns:ddl200_200=\"http://schemas.microsoft.com/analysisservices/2010/engine/200/200\" xmlns:ddl300=\"http://schemas.microsoft.com/analysisservices/2011/engine/300\" xmlns:ddl300_300=\"http://schemas.microsoft.com/analysisservices/2011/engine/300/300\">"
                    + "<Object>"
                    + "<DatabaseID>" + sDatabaseID + "</DatabaseID>"
                    + "<CubeID>"+sCubeID+"</CubeID>"
                    + "<MeasureGroupID>" + sMeasureGroupID + "</MeasureGroupID>"
                    + "<PartitionID>" + sPartitionID + "</PartitionID>"
                    + "</Object>"
                    + "<Type>ProcessFull</Type>"
                    + "<WriteBackTableCreation>UseExisting</WriteBackTableCreation>"
                    + "</Process>"
                    + "</Parallel>"
                    + "</Batch>"; Dts.TaskResult = (int)ScriptResults.Success; } #region ScriptResults declaration
        /// <summary>
        /// This enum provides a convenient shorthand within the scope of this class for setting the /// result of the script. /// 
        /// This code was generated automatically. /// </summary>
        enum ScriptResults { Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure }; #endregion } }
View Code

2.4 、咱們知道腳本中是有參數傳出來的,使用Analysis Services 執行 DDL 任務接受參數,執行cube處理:    

2.5 、執行SSIS任務:   

相關文章
相關標籤/搜索