[英]Querying assets with filter returns too small subset of assets
I'm querying assets that have empty alternateId
, but using the following code I only get around 7k assets.我正在查询具有空
alternateId
的资产,但使用以下代码我只能获得大约 7k 资产。 If I query without the filter and count the number of returned assets with empty alternateId
, it is around 36k.如果我在没有过滤器的情况下查询并计算返回的资产数量为空
alternateId
,它大约是 36k。 It's not related to paging as I'm using the same NextPageLink
paging logic in both test cases.它与分页无关,因为我在两个测试用例中使用相同的
NextPageLink
分页逻辑。
What could be the reason for this?这可能是什么原因? I'm looking into optimizing the code by not having to get all 72k assets but only the ones with empty
alternateId
, and update that after having processed the asset.我正在考虑通过不必获取所有 72k 资产而只获取具有空
alternateId
的资产来优化代码,并在处理资产后更新它。
I use Microsoft.Azure.Management.Media
v6.0.0.我使用
Microsoft.Azure.Management.Media
v6.0.0。
var assets = await client.Assets.ListAsync(
config.ResourceGroup,
config.AccountName,
new Microsoft.Rest.Azure.OData.ODataQuery<Asset>() {
Filter = "properties/alternateId eq ''"
}
);
You need to filter by properties/alternateId eq null
to get null values.您需要按
properties/alternateId eq null
进行过滤以获取 null 值。 If you want both null and empty values you can use properties/alternateId eq '' or properties/alternateId eq null
如果您同时需要 null 和空值,您可以使用
properties/alternateId eq '' or properties/alternateId eq null
Here is some sample code to test out the behavior.下面是一些示例代码来测试行为。 I added an additional filter on created date to exclude old data.
我在创建日期添加了一个额外的过滤器以排除旧数据。
var alternateNull = await Client.Assets.CreateOrUpdateAsync(ResourceGroup, MediaAccount, "alternate_null", new Asset());
var alternateEmpty = await Client.Assets.CreateOrUpdateAsync(ResourceGroup, MediaAccount, "alternate_empty", new Asset { AlternateId = "" });
var alternateSet = await Client.Assets.CreateOrUpdateAsync(ResourceGroup, MediaAccount, "alternate_set", new Asset { AlternateId = "abcd" });
var getNulls = await Client.Assets.ListAsync(
ResourceGroup,
MediaAccount,
new Microsoft.Rest.Azure.OData.ODataQuery<Asset>()
{
Filter = "properties/created gt 2022-10-07T00:00:00Z and properties/alternateId eq null"
});
Console.WriteLine("Nulls:");
Console.WriteLine(string.Join(',', getNulls.Select(s => s.Name)));
var getEmpty = await Client.Assets.ListAsync(
ResourceGroup,
MediaAccount,
new Microsoft.Rest.Azure.OData.ODataQuery<Asset>()
{
Filter = "properties/created gt 2022-10-07T00:00:00Z and properties/alternateId eq ''"
});
Console.WriteLine("Empty:");
Console.WriteLine(string.Join(',', getEmpty.Select(s => s.Name)));
var getNullOrEmpty = await Client.Assets.ListAsync(
ResourceGroup,
MediaAccount,
new Microsoft.Rest.Azure.OData.ODataQuery<Asset>()
{
Filter = "properties/created gt 2022-10-07T00:00:00Z and (properties/alternateId eq '' or properties/alternateId eq null)"
});
Console.WriteLine("Null Or Empty:");
Console.WriteLine(string.Join(',', getNullOrEmpty.Select(s => s.Name)));
var getAll = await Client.Assets.ListAsync(
ResourceGroup,
MediaAccount,
new Microsoft.Rest.Azure.OData.ODataQuery<Asset>()
{
Filter = "properties/created gt 2022-10-07T00:00:00Z"
});
Console.WriteLine("All:");
Console.WriteLine(string.Join(',', getAll.Select(s => s.Name)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.