码迷,mamicode.com
首页 > 其他好文 > 详细

SSAS动态处理分区(二)

时间:2015-06-08 13:14:56      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:

一、大致流程如下图:

技术分享

所需要用到的参数

技术分享

二、每个控件说明

1、“获取需要处理的参数”

技术分享

技术分享

SQLStatement如下:

SELECT DynamicPartitionSSAS                                                          AS DatabaseID,
       RmyyMZ                                                                        AS CubeID,
       Fact Mz Visit Table                                                           AS MeasureGroupID,
       Fact Mz Visit Table + CONVERT(VARCHAR(6), Dateadd(month, -1, Getdate()), 112) AS PartitionID
UNION
SELECT DynamicPartitionSSAS                                      AS DatabaseID,
       RmyyMZ                                                    AS CubeID,
       Fact Mz Visit Table                                       AS MeasureGroupID,
       Fact Mz Visit Table + CONVERT(VARCHAR(6), Getdate(), 112) AS PartitionID 

注:本文主要是根据当前的月份,动态处理本月和上一个月的数据

2、动态处理分区

技术分享

技术分享

3、返回需要处理的xmla语句

技术分享

技术分享

技术分享

C#代码:

/*
   Microsoft SQL Server Integration Services Script Task
   Write scripts using Microsoft Visual C# 2008.
   The ScriptMain is the entry point class of the script.
*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using Microsoft.AnalysisServices;

namespace ST_1f03ca252f334e528b0c03196047066b.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

        /*
        The execution engine calls this method when the task executes.
        To access the object model, use the Dts property. Connections, variables, events,
        and logging features are available as members of the Dts property as shown in the following examples.

        To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
        To post a log entry, call Dts.Log("This is my log text", 999, null);
        To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

        To use the connections collection use something like the following:
        ConnectionManager cm = Dts.Connections.Add("OLEDB");
        cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

        Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
        
        To open Help, press F1.
    */

        public void Main()
        {
            // TODO: Add your code here
            //??????????????

            String sDatabaseID = (String)Dts.Variables["DatabaseID"].Value;
            String sCubeID = (String)Dts.Variables["CubeID"].Value;
            String sMeasureGroupID = (String)Dts.Variables["MeasureGroupID"].Value;
            String sPartitionID = (String)Dts.Variables["PartitionID"].Value;
            String sServer = "localhost";

            ConnectionManager cm = Dts.Connections.Add("MSOLAP100");
            cm.ConnectionString = "Provider=MSOLAP.4;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=" + sDatabaseID;


            Microsoft.AnalysisServices.Server aServer = new Server();
            aServer.Connect(sServer);
            Microsoft.AnalysisServices.Database aDatabase = aServer.Databases.FindByName(sDatabaseID);
            Microsoft.AnalysisServices.Cube aCube = aDatabase.Cubes.FindByName(sCubeID);
            Microsoft.AnalysisServices.MeasureGroup aMeasureGroup = aCube.MeasureGroups.FindByName(sMeasureGroupID);

            //生成处理cube的xmla语句

            Dts.Variables["IsNetePresent"].Value = true;
            Dts.Variables["Xmla_Script"].Value = "<Batch xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">"
                + "<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\">"
                + "<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;


            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }
}

4、处理cube

技术分享

5、定时执行包任务。

SSAS动态处理分区(二)

标签:

原文地址:http://www.cnblogs.com/xymBlog/p/4560475.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!