zoukankan      html  css  js  c++  java
  • SSIS: Lookup组件高级用法,生成推断成员(inferred member)

    将数据导入事实表如果无法匹配维度表的记录一般有两种处理方式。 一是将不匹配记录输出到一个表中待后续处理,然后重新导入.二是先生成维度Key,后续再完善维度key,本文指导各位使用第二种方式。

    背景

    比如下图StoreID为1的经销商不存在于我们经销商维度表中,我们现在要使用lookup组件进行匹配,并生成维度key.

    image

    操作步骤

    1. 先添加一个派生列组件,将StoreID转为字符,等会儿生成键值会用到。

    image

    image

    2. 先进行匹配一次,然后把无法匹配到的记录传到下一个Lookup 组件  Insert  Inferred Reseller

    image

    3 .注意Insert  Inferred Reseller匹配模式要选择 Partial cache

    image

    image

    StoreIDstr 与 ReselletAltemateKey(也就是我们的StoreID) 做关联.

    image

    高级选项中,我们执行一个存储来代替前面Connection里面的输出.将StoreIDstr 传入改存储.来生成推断成员,并且返回键值,具体实现请看存储代码
    image

    USE [BIHell_demo]
    GO
    /****** Object:  StoredProcedure [dbo].[Generate_ResellerKey]    Script Date: 5/20/2015 10:37:44 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER PROCEDURE [dbo].[Generate_ResellerKey]
      @Store NVARCHAR(15) -- Business key
    AS 
    SET NOCOUNT ON
    
    /* Prevent race conditions */ 
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    
    /* Ensure key does not exist */
    DECLARE @ResellerKey INT 
    SELECT @ResellerKey = ResellerKEy
    FROM dw.DimReseller 
    WHERE ResellerAlternateKey = @Store
    
    /* Generate new surrogate key for inferred member */ 
    IF @ResellerKey IS NULL BEGIN 
      
    
      INSERT [dw].[DimReseller]
               ([ResellerAlternateKey]
               ,[BusinessType]
               ,[ResellerName]
               ,[NumberEmployees]
               ,[FirstOrderYear]
               ,[LastOrderYear]
               ,[ProductLine]
               ,[AddressLine1]
               ,[AddressLine2]
               ,[City]
               ,[StateProvinceCode]
               ,[PostalCode]
               ,[AnnualSales]
               ,[BankName]
               ,[AnnualRevenue]
               ,[YearOpened]
               ,[Current]
               ,[Inferred])
         VALUES
               (@Store
               ,'Unknown'
               ,'Unknown'
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,null
               ,1
               ,1)
      SET @ResellerKey = SCOPE_IDENTITY() 
    END
    
    /* Return surrogate and business key */ 
    SELECT @ResellerKey AS ResellerKey, @Store AS ResellerAlternateKey

    5. 执行完毕以后可以看到经销商维度表新增了一行记录,并且inferred被标记为1. 后续我们可以完善这条维度记录
    image

    而事实表已经关联到ResellerKey  702

    image

  • 相关阅读:
    冲刺第一天
    Nacos微服务体系配置管理
    Nacos配置中心客户端程序
    Nacos配置中心最佳实践
    SpringCloud2020整合Nacos-Bootstrap配置不生效的解决
    18.SpringCloud Alibaba Nacos服务注册和配置中心
    17、SpringCloud Alibaba入门简介
    SpringBoot热部署
    SpringBoot请求处理-常用参数注解使用
    5、创建springcloud alibaba工程
  • 原文地址:https://www.cnblogs.com/haseo/p/4518575.html
Copyright © 2011-2022 走看看