获取“实体已经存在".将聚合写入Azure表存储时出错(使用Azure函数) [英] Getting "Entity already exists" error writing aggregates to Azure Table Storage (with Azure Function)

查看:48
本文介绍了获取“实体已经存在".将聚合写入Azure表存储时出错(使用Azure函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure函数中,我试图聚合一些数据并将聚合写入表中.

In an Azure Function, I'm trying to aggregate some data and write the aggregations into a Table.

我有一个汇总数据的查询:

I have a query that summarises data:

var query = recs
            .GroupBy(r => new { r.Category, r.Account, r.Record })
            .Select(r => new ts_webhitaggregate_account
                    {
                        PartitionKey = partition,  // Constant
                        RowKey = $"{r.Key.Category}:{r.Key.Account}:{r.Key.Record}", // Group By 
                        rawDate = intervaldate,   // Constant
                        epochDate = intervalepoch, // Constant
                        Category = r.Key.Category, // Group By 
                        Account = r.Key.Account, // Group By 
                        Record = r.Key.Record, // Group By 
                        Hits = r.Count(), // Aggregate
                        Users = r.Select(t => t.User).Distinct().Count(), // Aggregate
                        Devices = r.Select(t => t.Device).Distinct().Count() // Aggregate
                    });

然后我尝试将这些记录传递给ICollector绑定表

I then attempt to pass these records to the ICollector bound Table

foreach (ts_webhitaggregate_account a in query.ToList())
{
    webhitsAggAccount.Add(a);
}

我经常遇到实体已存在"错误,例如:

I'm frequently encountering an "Entity already exists" error like:

调用的目标已引发异常.Microsoft.WindowsAzure.Storage:82:指定的实体已经存在.

Exception has been thrown by the target of an invocation. Microsoft.WindowsAzure.Storage: 82:The specified entity already exists.

如果我正在编写与C#类似的SQL语句,我不会期望复合键重复,因为要写入的每个值都是键,常量或聚合.表中也没有任何可能引起冲突的数据.

If I was writing a comparable SQL statement to the C# I wouldn't expect duplicates of the compound key to be possible as every value being written is the key, a constant, or an aggregation. I also have no pre-existing data in the Table which could be causing the conflict.

要在查询中生成重复项,我做错了什么?

推荐答案

我相信我发现自己很愚蠢……这些情况发生在该类别的循环中,我应该每次都选择一个类别,但行键上的一个范围选择包括另一个类别,然后继续选择该类别,两次插入第二个类别.

I believe I found where I was being stupid ... these happen inside a loop for the category, and I should have been selecting a single category each time, but one range selection on the row key was including another category that then went on to be selected, twice inserted to the second category.

如有疑问,请将所有内容打印到控制台!

When in doubt, print everything to the console!

这篇关于获取“实体已经存在".将聚合写入Azure表存储时出错(使用Azure函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆