繁体   English   中英

在 azure adf 管道中选择查询

[英]Select query in azure adf pipeline

如何通过从存储在 azure blob 中的文件中获取数据,在 azure adf 管道中传递选择查询。

例如:我在 blob 中的文件(测试)只有一个值

在我选择查询的 adf 管道中,我们从表中获取值。

Sqlquery:"Select * from emp where id = (需要从测试中获取值)"

有可能吗?

注意此答案指的是 Azure 数据工厂 (ADF) 的 v1

v2 支持通过设置变量活动设置变量

Re v1,我认为这不可能直接在管道内实现,因为 Azure 数据工厂并不真正支持这种方式的变量。 另一种方法是将文件从 blob 加载到运行其他查询的同一个数据库中,创建一个连接这两个的存储过程,然后使用Stored Proc Activity调用存储过程,例如:

SELECT * 
FROM emp 
WHERE id = ( SELECT id FROM yourBlobStagingTable );

希望这是有道理的。

原始答案针对 ADF 的 v1,在该版本中,此功能一次无法实现。

从 ADF 的 v2(2018 年 6 月 GA)开始,现在可以通过以下演示的方式传递参数。 所以下面的管道定义现在使这成为可能。

您想要的是 Lookup 从 blob 存储中获取值。 然后,您可以使用 @concat 字符串函数将其用作查询中的参数。 如何从 blob 中获得正确的值取决于您的设计。 您可以为此使用查找或元数据。

这是一个示例管道。

{
"name": "pipeline1",
"properties": {
    "activities": [
        {
            "name": "get_variable_from_file",
            "type": "Lookup",
            "dependsOn": [],
            "policy": {
                "timeout": "7.00:00:00",
                "retry": 0,
                "retryIntervalInSeconds": 30,
                "secureOutput": false,
                "secureInput": false
            },
            "userProperties": [],
            "typeProperties": {
                "source": {
                    "type": "DelimitedTextSource",
                    "storeSettings": {
                        "type": "AzureBlobFSReadSettings",
                        "recursive": true,
                        "enablePartitionDiscovery": false
                    },
                    "formatSettings": {
                        "type": "DelimitedTextReadSettings",
                        "skipLineCount": 1
                    }
                },
                "dataset": {
                    "referenceName": "blob_storage",
                    "type": "DatasetReference"
                },
                "firstRowOnly": true
            }
        },
        {
            "name": "use_variable_in_query",
            "type": "Copy",
            "dependsOn": [
                {
                    "activity": "get_variable_from_file",
                    "dependencyConditions": [
                        "Succeeded"
                    ]
                }
            ],
            "policy": {
                "timeout": "7.00:00:00",
                "retry": 0,
                "retryIntervalInSeconds": 30,
                "secureOutput": false,
                "secureInput": false
            },
            "userProperties": [],
            "typeProperties": {
                "source": {
                    "type": "AzurePostgreSqlSource",
                    "query": {
                        "value": "@concat('select * from schema.emp where id=',activity('get_variable_from_file').output)",
                        "type": "Expression"
                    }
                },
                "enableStaging": false
            },
            "inputs": [
                {
                    "referenceName": "postgres_database",
                    "type": "DatasetReference",
                    "parameters": {
                        "table_name": "emp"
                    }
                }
            ]
        }
    ],
    "annotations": []
}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM