简体   繁体   English

用于复制活动的Azure数据工厂表达式查询

[英]Azure Data Factory Expression Query for Copy activity

I am trying to copy data from Table storage to another Table storage of a different storage account, for that, I am using Copy activity in Azure data factory. 我试图将数据从表存储复制到其他存储帐户的另一个表存储,为此,我在Azure数据工厂中使用复制活动。

I want to filter rows that are going to be copied to the sink table storage, for that Azure data factory gives an option to define a query. 我想过滤将要复制到接收器表存储的行,因为该Azure数据工厂提供了一个定义查询的选项。 I want to apply a filter on the Partition key whose datatype is String but holds numeric values. 我想对数据类型为String但保留数值的Partition键应用过滤器。 I am looking at this documentation: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops there it says that type conversion is implicit for comparison operators like "eq", "le", "ge" etc 我正在查看此文档: https : //docs.microsoft.com/zh-cn/azure/devops/pipelines/process/expressions?view=azure-devops那里说类型转换对于比较运算符(例如“ eq”)是隐式的“,” le“,” ge“等

So if my query is " PartitionKey eq 0 " it fails and gives this error: 因此,如果我的查询是“ PartitionKey eq 0 ”,它将失败并给出此错误:

A storage operation failed with the following error 'The remote server returned an error: (400) Bad Request.'.. Activity ID:edf8e608-d25e

But if I define my query as " PartitionKey eq '0' " it works. 但是,如果我将查询定义为“ PartitionKey eq '0' ”,它将起作用。

I want to fetch rows with in the certain range of numbers for that I need to cast my partition key to a numeric value, How do I do that? 我想获取具有一定范围数字的行,因为我需要将分区键转换为数字值,该怎么办?

Also the " startsWith " and " endsWith " don't work eg, this query PartitionKey startsWith '10' gives the same error as above. 另外,“ startsWith ”和“ endsWith ”也不起作用,例如,此查询PartitionKey startsWith '10'给出与上述相同的错误。

Looks like this: 看起来像这样: 在此处输入图片说明 Thanks in advance. 提前致谢。

Firstly, to make sure that your query works - you can use Storage Explorer (preview) in Azure Portal to build the query in Query Builder mode: 首先,要确保您的查询有效-您可以在Azure Portal中使用Storage Explorer(预览版)Query Builder模式下构建查询:
使用查询构建器构建的查询

and then switch to Text Editor : 然后切换到文本编辑器

在此处输入图片说明

Now, you are sure that you have got right query . 现在,您可以确定查询正确
Let's apply this query to ADF. 让我们将此查询应用于ADF。 Without dynamic content - it will be exactly the same query: 没有动态内容-这将是完全相同的查询:
在此处输入图片说明

In order to create a dynamic query - we need to add variables or parameters to define the boundary: 为了创建动态查询 -我们需要添加变量或参数来定义边界:
在此处输入图片说明

Afterward, create a dynamic content in query field, replacing query: 之后,在查询字段中创建动态内容,替换查询:

PartitionKey ge '0' and PartitionKey le '1'

with the following form using concat function: 使用concat函数的形式如下:

@concat('PartitionKey ge ''0'' and PartitionKey lt ''1''')

Notice, that I must enquote single quote (') by adding extra one (''). 注意,我必须用单引号(')加上额外的一个('')。
In the end - we need just to replace hard-coded values with previously defined parameters: 最后,我们只需要用先前定义的参数替换硬编码的值即可:

@concat('PartitionKey ge ''',pipeline().parameters.PartitionStart,''' and PartitionKey lt ''',pipeline().parameters.PartitionEnd,'''')

That's all. 就这样。 I hope that I explain how to achieve that by building dynamic content (query) in Azure Data Factory. 我希望我解释如何通过在Azure数据工厂中构建动态内容(查询)来实现这一目标。

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

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