简体   繁体   中英

Azure table storage Invalid input

I am using Java to Query Azure table storage service.

I am querying a Azure table based on TimeStamp. Before executing query I converted the local java date to UTC.

Query is throwing an TableServiceException "One of the request inputs is not valid. RequestId:59445f16-0002-007e-152d-b3e24d000000 Time:2016-05-21T06:50:34.5077574Z"

When I used same date and query data using Azure Storage explorer; I am able to get the desired value as shown in below screen shot.

http://puu.sh/oZD6y/eadcc45859.png This makes me wonder what am I doing wrong.

below is the code that I use to query Azure Table. endDate is of Type Date

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;

Below code is used to convert local date

    long ts = System.currentTimeMillis();
    Date localTime = new Date(ts);
    String format = "yyyy/MM/dd HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat (format);


    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date gmtTime = new Date(sdf.format(localTime));
    System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());

This already wasted my time a lot. Any help would be highly appreciated.

(PartitionKey eq '1') and (Timestamp le 1463796341217L)

Basically you have an issue with your query. Essentially Timestamp is a date/time kind of attribute so if you were writing ODATA query yourself, your query should be something like:

(PartitionKey eq '1') and (Timestamp le datetime'some-date-time-value')

If you notice, this is something you're doing in Azure Storage Explorer as well.

Looking at your code, you are calling getTime() method on endDate which will return you milliseconds elapsed since January 1, 1970, 00:00:00 GMT. What you need to do is use endDate as is. Then the SDK will convert the query in the format understood by Azure Table Service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM