【问题标题】:Azure Data Factory Sink Destination FilterAzure 数据工厂接收器目标筛选器
【发布时间】:2021-02-19 11:26:56
【问题描述】:

如何使用 Azure 数据工厂在目标表的更新接收器操作中添加筛选器。

基本上我正在尝试实现以下查询,并且我需要在目标接收器中使用过滤器 end_date = '9999-12-31。

update testdb.test_scd2
set end_date = SourceStream.end_date
where cust_id = SourceStream.cust_id
and end_date = '9999-12-31

' ADF 脚本 - 根据 Mark 的评论更新。但它正在更新目标表中的所有数据。只需要更新一行 end_date - '9999-12-31'

source(output(
        cust_id as string,
        end_date_new as date
    ),
    allowSchemaDrift: true,
    validateSchema: false,
    ignoreNoFilesFound: false,
    wildcardPaths:['walgreen/source/test_upd.dat']) ~> FFWCustomerUpd
source(output(
        cust_id as string,
        eff_date as date,
        end_date as date,
        first_name as string,
        last_name as string,
        status as string
    ),
    allowSchemaDrift: true,
    validateSchema: false,
    ignoreNoFilesFound: false,
    isolationLevel: 'READ_UNCOMMITTED',
    format: 'table') ~> source1
Exists1 alterRow(updateIf(1==1)) ~> AlterTeradataConnectorupd
source1 filter(end_date==toDate('9999-12-31')) ~> Filter1
FFWCustomerUpd, Filter1 exists(FFWCustomerUpd@cust_id == source1@cust_id,
    negate:false,
    broadcast: 'auto')~> Exists1
AlterTeradataConnectorupd sink(input(
        cust_id as string,
        eff_date as date,
        end_date as date,
        first_name as string,
        last_name as string,
        status as string
    ),
    allowSchemaDrift: true,
    validateSchema: false,
    deletable:false,
    insertable:false,
    updateable:true,
    upsertable:false,
    keys:['cust_id'],
    format: 'table',
    mapColumn(
        cust_id,
        end_date = end_date_new
    ),
    skipDuplicateMapInputs: true,
    skipDuplicateMapOutputs: true) ~> TeradataConnectorupd

【问题讨论】:

    标签: sql azure ssis azure-data-factory


    【解决方案1】:

    在 Alter Row 中为“Update If”设置策略:end_date == 9999-12-31

    在接收器中,将您的键列设置为 cust_id

    【讨论】:

    • “Update If”是对传入行或我们正在更新的表的过滤?
    • 传入行。如果您只是尝试更新目标数据库中的行,请将源设置为与目标相同的数据集。
    • 在数据流中 - FFWCustomerUpd 是记录 cust_id = 1001 和 end_date = 2020-10-01 的 csv 文件。如果目标表 end_date = '9999-12-31',我想将目标表更新为 csv 文件文件中的 end_daate。如何指定目标接收器的 end_date 只选择 9999-12-31?
    • 在数据流中,您的流只关注过滤传入的数据。如果您需要检查目标数据中的值,您应该将另一个源添加到您的数据流中,以查询您的目标表并查找等于“9999-12-31”的日期。然后,您可以加入新数据流并设置新的结束日期。我将在下一个答案中粘贴屏幕截图示例。
    【解决方案2】:

    这是逻辑流程的伪代码大纲:

    1. 新传入源 + 目标表作为源
    2. 在底部流中,仅过滤您需要替换的日期
    3. 仅过滤在顶部流中具有该日期的 ID
    4. 将 Alter Row 设置为 true() 以进行更新,以便更新所有行。在这一点上,我们确信他们都是 9999-12-31
    5. 只设置“允许更新”写入接收器

    【讨论】:

    • Kromer - 我正在尝试做 Type 2 SCD。目标中可能有多个列具有相同的 cust_id 和不同的 end_date。上述流程将更新 cust_id = 1001 的所有记录,对吗?我们没有过滤目标接收器中的任何内容,并且键列只是 cust_id。我尝试加入 end_date,但出现以下错误。 - 由于原因,作业失败:在接收器“TeradataConnectorupd”:没有可更新的列与接收器表的架构匹配。”
    • 我上面的示例仅更新日期为“9999-12-31”的行。如果您将 cust_id 设置为接收器中的主键,如果之前的值为 9999-12-31,这会将任何 cust_id 更新为新日期。
    • 我遵循了您的代码,但它正在更新该 cust_id 的所有行。我在问题中发布了新代码。那里有什么我想念的吗?
    • 您能否在接收器转换中单击数据预览并查找从接收器出来的行。检查那里以查看是否正在更新正确的行。
    • 此外,您可以通过检查更改行转换上的数据预览来验证是否仅过滤了具有 9999-12-31 的行。
    猜你喜欢
    • 1970-01-01
    • 2020-08-22
    • 2021-12-03
    • 2022-10-24
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多