我使用Java来查询Azure表存储服务。
我正在查询基于TimeStamp的Azure表。在执行查询之前,我将本地java日期转换为UTC。
查询抛出TableServiceException“其中一个请求输入无效。 请求ID:59445f16-0002-007e-152D-b3e24d000000 时间:2016-05-21T06:50:34.5077574Z“
当我使用Azure存储资源管理器使用相同日期和查询数据时;我可以获得所需的值,如下面的屏幕截图所示。
http://puu.sh/oZD6y/eadcc45859.png这让我想知道我做错了什么。
下面是我用来查询Azure Table的代码。 endDate的类型为日期
var {children={}, Activator={}} = this.props
以下代码用于转换本地日期
String partitionFilter = TableQuery.generateFilterCondition(PARTITION_KEY, QueryComparisons.EQUAL,
partitionKey);
String date2 = TableQuery.generateFilterCondition(TIMESTAMP, QueryComparisons.LESS_THAN_OR_EQUAL, endDate.getTime());
String finalFilter = TableQuery.combineFilters(partitionFilter, Operators.AND, date2);
CloudTable table = getTable(tableName);
TableQuery<TableServiceEntity> query = TableQuery.from(TableServiceEntity.class).where(finalFilter);
Iterable<TableServiceEntity> tableEntries = table.execute(query);
return tableEntries;
这已经浪费了我很多时间。任何帮助都将受到高度赞赏。
答案 0 :(得分:1)
(PartitionKey eq'1')和(Timestamp le 1463796341217L)
基本上您的查询存在问题。基本上Timestamp
是date/time
类型的属性,因此如果您自己编写ODATA查询,您的查询应该是这样的:
(PartitionKey eq '1') and (Timestamp le datetime'some-date-time-value')
如果您注意到,这也是您在Azure Storage Explorer中所做的事情。
查看您的代码,您在getTime()
上调用endDate
方法,这将返回自1970年1月1日00:00:00 GMT以来经过的毫秒数。您需要做的是按原样使用endDate
。然后,SDK将以Azure Table Service理解的格式转换查询。