在Informatica PowerCenter中,Slowly Changing Dimensions (SCD) 是一种处理数据仓库中随时间变化的数据的技术。SCD Type 1 是其中一种类型,它通过覆盖旧数据来处理数据的变化,即最新的数据会替换掉旧的数据,而不保留历史记录。
适用于数据变化不频繁,且不需要查看历史数据的场景,例如当前状态的数据报告。
假设我们有一个FlatFile源文件 customer_src.txt
,内容如下:
ID,Name,Address,EffectiveDate,EndDate
1,John Doe,123 Main St,2020-01-01,
2,Jane Smith,456 Elm St,2020-01-01,
维度表 customer_dim
结构如下:
CREATE TABLE customer_dim (
ID INT PRIMARY KEY,
Name VARCHAR(100),
Address VARCHAR(100),
EffectiveDate DATE,
EndDate DATE
);
customer_src.txt
。customer_dim
表。Expression Transformation
。Update Strategy
为 Overwrite
。EffectiveDate
和 EndDate
字段的处理逻辑。<Mapping>
<Source Qualifier="SRC_CUSTOMER">
<SourceDefinition>Customer_Source</SourceDefinition>
</Source>
<Target LoadOrder="1" Name="TGT_CUSTOMER_DIM">
<TargetDefinition>Customer_Dim</TargetDefinition>
</Target>
<Transformation Type="Expression" Name="EXP_SCD_TYPE1">
<InputParameters>
<InputParameter Expression="IIF(TARGET.EndDate IS NULL, TODAY(), TARGET.EndDate)" Name="EndDate" Type="DATE"/>
<InputParameter Expression="SRC.EffectiveDate" Name="EffectiveDate" Type="DATE"/>
</InputParameters>
<OutputParameters>
<OutputParameter Expression="SRC.ID" Name="ID" Type="INTEGER"/>
<OutputParameter Expression="SRC.Name" Name="Name" Type="VARCHAR(100)"/>
<OutputParameter Expression="SRC.Address" Name="Address" Type="VARCHAR(100)"/>
<OutputParameter Expression="#Parameters.EndDate" Name="EndDate" Type="DATE"/>
<OutputParameter Expression="#Parameters.EffectiveDate" Name="EffectiveDate" Type="DATE"/>
</OutputParameters>
</Transformation>
<Joiner JoinType="Left" Name="JOINER_SCD">
<Input>
<JoinCondition>SRC.ID = TGT.ID</JoinCondition>
<LeftInput>
<RefEntity>SRC_CUSTOMER</RefEntity>
</LeftInput>
<RightInput>
<RefEntity>TGT_CUSTOMER_DIM</RefEntity>
</RightInput>
</Input>
</Joiner>
<Expression Transformation="EXP_SCD_TYPE1">
<Input>
<RefEntity>JOINER_SCD</RefEntity>
</Input>
<Output>
<RefEntity>TGT_CUSTOMER_DIM</RefEntity>
</Output>
</Expression>
</Mapping>
通过以上步骤和示例代码,您可以在Informatica中实现对FlatFile目标的SCD Type 1 处理。
领取专属 10元无门槛券
手把手带您无忧上云