查询 Azure 表存储中的空值
有谁知道查询天蓝色表存储中空值的正确方法。从我读到的内容来看,这是可能的(尽管有一个错误阻止了它在开发存储上的实现)。但是,当我在实时云存储上执行此操作时,我不断收到以下错误:
请求输入之一无效。
这是我整理的 LINQ 查询的简化版本。
var query = from fooBar in fooBarSVC.CreateQuery<FooBar>("FooBars")
where fooBar.PartitionKey == kPartitionID
&& fooBar.Code == kfooBarCode
&& fooBar.Effective_Date <= kFooBarDate.ToUniversalTime()
&& (fooBar.Termination_Date > kFooBarDate.ToUniversalTime() || fooBar.Termination_Date == null)
select fooBar;
如果我运行查询而不检查 null,它工作正常。我知道一个可能的解决方案是对该查询带回的集合运行第二个查询。如果需要的话,我不介意这样做,但想知道我是否可以先让这种方法发挥作用。
有人看出我做错了什么吗?
Does anyone know the proper way to query azure table storage for a null value. From what I've read, it's possible (although there is a bug which prevents it on development storage). However, I keep getting the following error when I do so on the live cloud storage:
One of the request inputs is not valid.
This is a dumbed down version of the LINQ query that I've put together.
var query = from fooBar in fooBarSVC.CreateQuery<FooBar>("FooBars")
where fooBar.PartitionKey == kPartitionID
&& fooBar.Code == kfooBarCode
&& fooBar.Effective_Date <= kFooBarDate.ToUniversalTime()
&& (fooBar.Termination_Date > kFooBarDate.ToUniversalTime() || fooBar.Termination_Date == null)
select fooBar;
If I run the query without checking for null, it works fine. I know a possible solution would be to run a second query on the collection that this query brings back. I don't mind doing that if I need to, but would like to know if I can get this approach to work first.
Anyone see anything obvious I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
问题在于,由于天蓝色表存储没有架构,因此空列实际上不存在。这就是您的查询无效的原因。表存储中不存在空列之类的东西。如果确实需要,您可以执行诸如存储空字符串之类的操作。事实上,这里的根本问题是,Azure 表存储实际上并不是为分区键和行键以外的任何列进行查询而构建的。每次对这些非标准列之一进行查询时,您都在进行表扫描。如果您开始获取大量数据,查询超时率将会非常高。我建议为这些类型的查询设置手动索引。例如,您可以将相同的数据存储在同一个表中,但 Row 键的值不同。最终,如果您的应用程序使用率没有达到疯狂的高使用率,我只会使用 SQL Azure,因为它对于您正在执行的查询类型会更加灵活。
更新:Azure 有一个关于表存储设计的很棒的指南,我建议您阅读。 http://azure.microsoft.com/en-我们/documentation/articles/storage-table-design-guide/
The problem is that because azure table storage does not have a schema, the null column actually doesn't exist. This is why your query is not valid. there is no such thing as a null column in table storage. You could do something like store an empty string if you really have to. Really though the fundamental issue here is that Azure table storage really is not built to be queried by any columns other than partition key and row key. Every time you make a query on one of these non-standard columns you are doing a table scan. If you start to get lots of data you are going to have a very high rate of query time outs. I would suggest setting up a manual index for these types of queries. For example, you could store the same data in the same table but with different values for the Row key. Ultimately, if your are app is not getting crazy high usage I would just use SQL Azure as it will be much more flexible for the types of queries you are doing.
Update: Azure has a great guide on table storage design that I would recommend reading. http://azure.microsoft.com/en-us/documentation/articles/storage-table-design-guide/
我刚刚遇到这个问题,并发现了一个很好的小忍者技巧来实际测试空值。虽然我直接使用 Azure 存储接口,但我 90% 确信如果您也这样做,它也适用于 LINQ。
以下是我检查 Price (Int32?) 是否为 null 的方法:
我猜在您的情况下,您可以通过测试 fooBar.Termination_Date 是否小于或大于 DateTime.UtcNow 在 LINQ 中执行相同的操作。像这样的东西:
I just had this problem and found a nice little ninja-trick to actually test for nulls. Although I'm using the Azure Storage interface directly, I'm 90% sure it will work for LINQ too if you do the same.
Here's what I did to check if Price (Int32?) is null:
I'm guessing in your case you can do the same in LINQ by testing if fooBar.Termination_Date is less or greater than DateTime.UtcNow for example. Something like this:
对于名为 MyColumn 的字符串列,我可以输入:
not(MyColumn gt '')
上面的 Mike S 回答让我走上了正确的道路。
For a string column called MyColumn I was able to type:
not(MyColumn gt '')
Mike S answer above put me on the right path.
对于字符串,我们可以与空字符串进行比较。
可以是:
For strings, we can compare to empty string.
Can be:
使用 Azure 表客户端 .NET 库。查询
null
Guid 值。在示例代码中,属性的名称是MyColumn。
TableClient.CreateQueryFilter 方法将创建过滤器:
Using the Azure Tables client library for .NET. to query for
null
Guid values.In the sample code, the property's name is MyColumn.
The TableClient.CreateQueryFilter method will create the filter:
今天,我在尝试获取 Azure 表存储中已知的值时遇到了这个问题。根据上面的答案,我了解到使用“小于”实际上给了我我正在寻找的值。
换句话说,如果您尝试使用表存储查询从 Azure 表存储中获取 null 的内容(该行中不存在字段),则等效内容类似于
Looking for NULL VALUES
not (FieldName lt '')
如果您想要空值
(FieldName lt '')
使用高级查询时直接在 Azure 中使用上述文字 -- 仅供参考
I ran across this problem today while I was trying to get values that were known from Azure table storage. Based on the answers above, I learned that using "less than" actually gives me the values that I was looking for.
So in other words if you're trying to grab things that are null (field does not exist in that row) from Azure table storage, using table storage queries, then the equivalent looks like
Looking for NULL VALUES
not (FieldName lt '')
If you WANT the null values
(FieldName lt '')
The above words directly in Azure when using advanced querying -- FYI