ssis 列转换_SSIS组播转换概述

ssis 列转换

This article explores the SSIS Multicast Transformation for creating different logical copies of source data.

本文探讨了用于创建源数据的不同逻辑副本的SSIS组播转换。

介绍 (Introduction)

In the article, SSIS Conditional Split Transformation overview, we explored the Conditional Split Transformation task to split the incoming data into multiple destinations depending upon the specified condition. We use SSIS Multicast Transformation to create multiple copies of input data. Suppose we require multiple copies of the input data in TXT, CSV and SQL table format. We can use these multiple copies of the data for different transformations.

SSIS条件拆分转换概述文章中,我们探索了条件拆分转换任务,以根据指定条件将传入数据拆分为多个目标。 我们使用SSIS组播转换来创建输入数据的多个副本。 假设我们需要TXT,CSV和SQL表格式的输入数据的多个副本。 我们可以将这些数据的多个副本用于不同的转换。

Suppose you receive stock transactions for your clients in a CSV format. You upload the data in the database and do the calculations for your clients depending upon multiple scenarios. You can use SSIS Multicast Transformation to prepare similar copies of data using SSIS. We do not need any programming or development experience to do this task.

假设您以CSV格式收到客户的股票交易。 您将数据上传到数据库中,并根据多种情况为客户进行计算。 您可以使用SSIS组播转换来使用SSIS准备数据的相似副本。 我们不需要任何编程或开发经验即可完成此任务。

Let’s create an SSIS package to use the SSIS Multicast Transformation.

让我们创建一个SSIS包以使用SSIS组播转换。

环境细节 (Environment Details)

In the following image, you can see the configured SQL Server Data Tools for my system.

在下图中,您可以看到为我的系统配置SQL Server数据工具。

Visual Studio version and edition

创建用于SSIS组播转换的SSIS包 (Create an SSIS package for SSIS Multicast Transformation)

Launch SQL Server Data Tool to create an Integration project. Provide the Integration project name and specify the location to save the project.

启动SQL Server数据工具以创建一个集成项目。 提供集成项目名称,并指定保存项目的位置。

Create a SSIS package

在连接管理器中添加OLE DB源 (Add an OLE DB Source in the Connection Manager)

In the SSIS project window, we have the following areas.

在SSIS项目窗口中,我们具有以下区域。

  1. Control Flow, Data Flow, Event Handlers and Package Explorer area

    控制流,数据流,事件处理程序和包资源管理器区域
  2. We add different SSIS components in this area

    我们在此区域添加了不同的SSIS组件

    Add an OLE DB Source in the Connection Manager

  3. In the Connection Managers area, we can configure the different source and destination connections. You can also view all the connections in the package in this area

    在“连接管理器”区域中,我们可以配置不同的源连接和目标连接。 您也可以在此区域查看软件包中的所有连接

Let’s add an OLE DB Source connection to point the WideWorldImporters database in my local instance. Right-click on the Connection Managers, click on New OLE DB Connection.

让我们添加一个OLE DB Source连接以在我的本地实例中指向WideWorldImporters数据库。 右键单击“连接管理器”,然后单击“ 新建OLE DB连接”

New OLE DB Connection

It opens the OLE DB Connection Manager. Provide the details such as SQL Instance name, Authentication method (Windows or SQL authentication) and select the database name from the drop-down list.

它打开OLE DB连接管理器。 提供详细信息,例如SQL实例名称,身份验证方法(Windows或SQL身份验证),然后从下拉列表中选择数据库名称。

SQL Connection Manager

You can test the connection and click Ok. You can see the configured connection in the Connection Managers area.

您可以测试连接,然后单击“确定”。 您可以在“连接管理器”区域中看到已配置的连接。

Available connection in the connection manager

For a better understanding, right-click on this connection and rename it with an appropriate name.

为了更好地理解,请右键单击此连接,然后使用适当的名称重命名。

Rename a connection

Drag the Data Flow Task in the Control Flow area.

将数据流任务拖到“控制流”区域中。

Data Flow Task in the Control Flow area

Right-click on the Data Flow Task and click on Edit.

右键单击“数据流任务”,然后单击“编辑”。

Edit Data Flow Task

It moves to the data Flow page. In the Data Flow page, add an OLE DB Source similar to the following image.

它将移至数据流页面。 在“数据流”页面中,添加类似于下图的OLE DB源。

Add OLE DB Source

Double click on this to open the OLE DB Source editor. It automatically shows the connection we created earlier. If we want a separate connection, you can click on New and configure it. In the Data access mode, select the Table or View because my source data is in the SQL table.

双击打开OLE DB Source编辑器。 它会自动显示我们之前创建的连接。 如果我们需要单独的连接,则可以单击“新建”并进行配置。 在数据访问模式下,选择表或视图,因为我的源数据在SQL表中。

Select the table that contains the data. I selected Sales.Orders table from the WideWorldImporters database.

选择包含数据的表。 我从WideWorldImporters数据库中选择了Sales.Orders表。

Select the table or view

Click Ok and rename the OLE DB Source to Source Data.

单击确定,并将OLE DB源重命名为源数据。

Rename the OLE DB Source to Source Data

添加SSIS组播转换以配置多个目标 (Add SSIS Multicast Transformation to configure multiple destinations)

Drag the Multicast transformation to the data flow tab and join the green line from Source Data to Multicast.

将“多播”转换拖到“数据流”选项卡上,并将绿线从“源数据”连接到“多播”。

Add SSIS Multicast Transformation to configure multiple destinations

Now we want to add three destinations.

现在我们要添加三个目的地。

  • Flat File output

    平面文件输出
  • Excel file output

    Excel文件输出
  • SQL Database table

    SQL数据库表

在SSIS组播转换中添加FLAT文件输出 (Add a FLAT file output in the SSIS Multicast Transformation)

We use Flat File Destination for the TXT or CSV file formats. Drag the Flat File Destination from the SSIS Toolbox to Data Flow task and join it with the Multicast operator.

我们将平面文件目标用于TXT或CSV文件格式。 将平面文件目标从SSIS工具箱拖到数据流任务,并将其与多播运算符一起加入。

Add a FLAT file output in the SSIS Multicast Transformation

It shows the Red Cross icon on Flat File Destination because we did not configure the destination. Double click on it, and it launches the Flat File Destination Editor.

它在平面文件目标上显示红十字图标,因为我们没有配置目标。 双击它,它会启动平面文件目标编辑器。

New Flat File

Click on New, and it asks for the flat-file format. We can choose the formats below.

单击“新建”,然后要求提供平面文件格式。 我们可以选择以下格式。

  • Delimited

    定界
  • Fixed Width

    固定宽度
  • Fix Width with row delimiters

    使用行定界符修复宽度
  • Ragged Right

    衣衫Right的权利

Let’s go with the default format Delimited. In this format, the commas delimit the columns in the text file.

让我们使用默认格式Delimited。 在这种格式下,逗号分隔文本文件中的列。

Flat File Format as Delimited

Click Ok, and it opens the Flat File Destination editor. Specify the connection name and the file path. It automatically gives the format specifications such as Header Row delimiter, Text qualifier. We will go with the default values.

单击确定,它将打开平面文件目标编辑器。 指定连接名称和文件路径。 它会自动给出格式规范,例如标题行定界符,文本限定符。 我们将使用默认值。

In the Advanced page, we view the source columns and their properties for the destination flat file.

在“高级”页面中,我们查看目标平面文件的源列及其属性。

Flat File Configuration

Click on Mapping to view the mapping of input and output columns. By default, it does the mapping; however, we can change it if required.

单击映射以查看输入和输出列的映射。 默认情况下,它会进行映射。 但是,如果需要,我们可以更改它。

Mapping between source and destination

Click Ok, and we can see the Red Cross icon is not present now on Flat File Destination.

单击确定,我们可以看到“平面文件目标”上现在不存在“红十字”图标。

SSIS package configuration

在SSIS组播转换中添加Excel文件输出 (Add an Excel file output in the SSIS Multicast Transformation)

Let’s add an Excel file destination from the SSIS toolbox and join it with the Multicast Transformation.

让我们从SSIS工具箱中添加一个Excel文件目标,并将其与多播转换一起加入。

Add an Excel file output in the SSIS Multicast Transformation

Double click on Excel destination to configure it. In the Excel Destination Editor, click on New and specify the file path and name.

双击Excel目标进行配置。 在Excel目标编辑器中,单击“新建”,然后指定文件路径和名称。

Excel File path and configuration

Click Ok, and it goes to excel destination editor. Click on New to create the required columns in the excel sheet.

单击确定,然后转到excel目标编辑器。 单击新建以在excel表中创建所需的列。

Create Excel sheet

Click Ok, and you get the syntax error message.

单击确定,您会收到语法错误消息。

Syntax error

Remove the quotes, and you can create the excel sheet with the required columns.

删除引号,您可以使用所需的列创建Excel工作表。

Remove the quotes in the excel sheet

Click OK and go to Mapping to review mapping between source data and destination excel sheet.

单击“确定”,然后转到“映射”以查看源数据和目标Excel工作表之间的映射。

Review mapping

Click Ok, and we are ready with the Excel destination configuration.

单击确定,我们就可以使用Excel目标配置了。

Excel destination configuration

添加一个SQL Server目标 (Add an SQL Server Destination)

We require a SQL Server destination to get a copy of the source data. We can use OLE DB destination or SQL Server destination for this.

我们需要一个SQL Server目标来获取源数据的副本。 我们可以为此使用OLE DB目标或SQL Server目标。

Drag an OLE DB destination and join with SSIS Multicast Transformation.

拖动OLE DB目标并加入SSIS多播转换。

Add SQL Server Destination

Double click on this SQL Server Destination to configure it. It opens the SQL Destination Editor, and we can see the existing connection WideWorldImporters in this. Let’s use the same connection for the destination as well.

双击此SQL Server目标进行配置。 它将打开“ SQL Destination Editor”,我们可以在其中看到现有的连接WideWorldImporters。 让我们对目标也使用相同的连接。

SQL Destination Editor

We want to create a new table, therefore, click on the New in front of Use a table or view. It opens the script for the CREATE TABLE statement. Give an appropriate name for the table and click Ok.

我们要创建一个新表,因此,单击“使用表或视图”前面的“新建”。 它打开CREATE TABLE语句的脚本。 为表指定一个适当的名称,然后单击“确定”。

Create a new table in the SQL Destination editor

You can see the table name in the screenshot below.

您可以在下面的屏幕截图中看到表格名称。

Create a new table or view

Verify the mapping between the source data and destination table and click OK.

验证源数据和目标表之间的映射,然后单击“确定”。

Mapping between source and destination

Click Ok, and it returns to the Control flow tab of the SSIS package. We configured three destinations as per our requirement.

单击“确定”,它返回到SSIS包的“控制流”选项卡。 我们根据要求配置了三个目的地。

Complete package configuration

Press F5 or click on the Start button to execute the package. The green tick mark on each component shows the package executed successfully.

按F5或单击“开始”按钮执行程序包。 每个组件上的绿色对勾表示软件包已成功执行。

In the following screenshot, we can verify that SSIS Multicast Transformation sends the same copy of data to each destination. We have source row count 1,111 and each destination row count is 1,111.

在下面的屏幕快照中,我们可以验证SSIS组播转换是否将相同的数据副本发送到每个目标。 我们的源行数为1,111,每个目标行数为1,111。

Result of package execution

Let’s verify data in the destination files.

让我们验证目标文件中的数据。

  • Flat File Data

    平面文件数据

    Flat File Data

  • Excel Sheet Data

    Excel工作表数据

    Excel Sheet Data

  • SQL Server Data

    SQL Server资料

    SQL Server Data

派生列和SSIS组播转换 (Derived column and SSIS Multicast Transformation)

In the previous example, we use SSIS Multicast Transformation to copy the data from the source to the destination such as flat files, excel sheet and SQL tables. The use case of a multicast operator is that we can apply different transformations, aggregations, calculations on logical copies of data.

在前面的示例中,我们使用SSIS组播转换将数据从源复制到目标,例如平面文件,excel工作表和SQL表。 多播运算符的用例是,我们可以对数据的逻辑副本应用不同的转换,聚合和计算。

Suppose we want a new derived column in the SQL Server destination. We do not want derived columns in other destinations.

假设我们要在SQL Server目标中添加一个新的派生列。 我们不希望在其他目标中派生列。

Drag a derived column from the SSIS Toolbox.

从SSIS工具箱中拖动派生的列。

Derived column

We want to add a new column LoginID, and it should be the reverse of the PreferredName column. In the expression, we use the SQL REVERSE string function.

我们要添加一个新列LoginID,它应该与PreferredName列相反。 在表达式中,我们使用SQL REVERSE字符串函数。

Add a new Derived column

In the SQL Server Destination, create a new table that contains new column Loginname. Drag the green arrow from the derived column to the SQL Server destination.

在SQL Server目标中,创建一个包含新列Loginname的新表。 将绿色箭头从派生列拖到SQL Server目标。

SSIS package with Multicast and Derived column

Execute the package, and it shows successful.

执行该程序包,它显示成功。

package execution

Let’s check the SQL Server Destination table and see the data in the new column. You can see that the LoginID column contains data reverse to data in the PreferredName column.

让我们检查SQL Server Destination表,并在新列中查看数据。 您可以看到LoginID列包含的数据与PreferredName列中的数据相反。

SELECT [PreferredName], 
       [LoginID]
FROM [WideWorldImporters].[dbo].[SQLDerivedTable];

Verfiy the result set

结论 (Conclusion)

In this article, we explored the SSIS Multicast Transformation to copy the source data into multiple destinations such as flat files, excel files and the SQL Server tables. Try exploring this SSIS component to perform tasks efficiently without any complicated programming code.

在本文中,我们探索了SSIS组播转换,将源数据复制到多个目标中,例如平面文件,excel文件和SQL Server表。 尝试探索此SSIS组件以有效执行任务,而无需任何复杂的编程代码。

翻译自: https://www.sqlshack.com/ssis-multicast-transformation-overview/

ssis 列转换

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值