Windows Azure 表,使用 Contains 进行查询
我正在尝试对我的 Azure 表之一实施查询,该查询应检索包含输入字符串的所有文件。
我尝试过使用 string.contains() 但这不受 Azure 支持,我也尝试过 string.startswith() 这也不支持。
我想知道是否有办法在 Azure Tables 中执行此操作。我将文件信息存储在表中,分区键是存储项目的虚拟路径。
例如,Images_Jpg_Image1.jpg 将是其中一个文件的分区键,我使用“_”,因为 Azure 不允许在分区键中使用“/”。
我希望能够将上面的分区键与
理想情况下以下字符串将返回该分区键
Images_ 进行比较 图片_Jpg 图片_ Image1.jpg
我已经设置了所有表和所有其他查询,只是这一个查询我无法弄清楚。
预先感谢您的帮助,
马特
I'm trying to implement a query for one of my Azure Tables, the query should retrieve all files that contain the input string.
I've tried using string.contains() but this isn't supported by Azure, I've also tried string.startswith() this also isn't supported.
What I'm wondering is if there is a way to do this in Azure Tables. I'm storing file information in the tables and the partition key is the virtual path of the item stored.
e.g. Images_Jpg_Image1.jpg would be a partition key for one of the files, i've used '_' because Azure won't allow '/' in partition keys.
I'd like to be able to compare the above partition key with
Ideally the following strings would return that partition key
Images_
Images_Jpg
Jpg_
Image1.jpg
I have all the tables set up and all of the other queries, its just this one query that I can't figure out.
Thanks in advance for any help,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
表存储确实支持 CompareTo 方法,可以像 StartsWith 一样使用。但根据您尝试执行的搜索类型,它可能仍然不适合您。
Table Storage does support the CompareTo method which can be used like a StartsWith. But it still might not work for you based on the types of searching you're trying to do.
我在对 Azure 表进行搜索时遇到了类似的问题,搜索名称并确保结果大小写不变。
我最终所做的实际上是将我需要的数据从 Azure 表加载到内存集合中,该集合保留在可查询集合中。然后我就能够使用 Linq to Objects 来查询并获得我想要的结果。
这不是一个优雅的方法,但如果数据收集不是很大并且相对静态,则内存中对象的大小将相对于虚拟机拥有的内存量而言相对良性。性能也快得多。
您还可以尝试将分区/行键和您尝试在内存中查询的数据,运行查询,迭代分区和行键并返回结果。不确定这是否有助于解决您的问题,但我将其作为一种可能的方法抛弃。
祝你好运!
约翰
I have run into similar issues with searches against Azure tables searching on names and making sure the results were case invariant.
What I ended up doing was actually loading the data I needed from the Azure tables to an in memory collection that gets persisted in a queryable collection. I was then able to use Linq to Objects to query and get the results I wanted.
Not an elegant approach, but if the data collection is not huge and is relativley static, the size of the object in memory will be relatively benign in compassion to how much memory the VM has. Performance was also much faster.
You could also try and just have the Partition/row key and data your are trying to query in memory, run your query, iterate the partiation and row keys and return your results. Not sure if that will help resolve your question, but I throw it out as a possible approach.
Good luck!
John
我发现使用 LINQPad 查询 Azure 表存储非常方便。查看 杰森Halley 的 博客了解更多信息和示例。
I found querying Azure Table storage using LINQPad very handy. Check out Jason Halley's blog for more info and samples.