Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timestamp query in Azure

I am really stuck in my query filter on Azure table storage. May I know how to query with timestamp please? When I query for partition key to 1005 alone, I am getting the complete table which I don't want. When I added "and" condition with timestamp (tried with lots of formats but it is not returning anything. Code snippet below :

var lowerlimit = DateTime.Today.AddDays(-52).ToString("yyyy-MM-dd");

string dateRangeFilter = TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "1005"),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("TimeStamp", QueryComparisons.GreaterThanOrEqual, lowerlimit));
like image 282
Kumar Avatar asked Jun 26 '13 16:06

Kumar


3 Answers

I am able to use the Timestamp with Microsoft.WindowsAzure.Storage version 4.0.1.0. Just and example

var query = TableQuery.CombineFilters(
            TableQuery.GenerateFilterCondition("Level", QueryComparisons.Equal, "ERROR"), 
            TableOperators.And, 
            TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, DateTimeOffset.Now.AddDays(-20).Date));

var query2 = TableQuery.CombineFilters(query,
            TableOperators.And, 
            TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, DateTimeOffset.Now));

var exQuery = new TableQuery<LogEntry>().Where(query2);

CloudTableClient tableClient = _storageAccount.CreateCloudTableClient();

CloudTable table = tableClient.GetTableReference(_tableName);
var results = table.ExecuteQuery(exQuery).Select(ent => (T) ent).ToList();
like image 114
Jonathas Sucupira Avatar answered Nov 16 '22 21:11

Jonathas Sucupira


Timestamp can be used to query rows in Azure Table Storage.

However, you will need to use TableQuery.GenerateFilterConditionForDate instead of TableQuery.GenerateFilterCondition. For any DateTime column, TableQuery.GenerateFilterConditionForDate must be used.

From your code sample, change GenerateFilterCondition to GenerateFilterConditionForDate for Timestamp filter:

var lowerlimit = DateTime.Today.AddDays(-52).ToString("yyyy-MM-dd");

string dateRangeFilter = TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "1005"),
    TableOperators.And,
    TableQuery.GenerateFilterConditionForDate("TimeStamp", QueryComparisons.GreaterThanOrEqual, lowerlimit));
like image 8
stack247 Avatar answered Nov 16 '22 21:11

stack247


Property names are case-sensitive. It should be Timestamp and not TimeStamp.

like image 7
Iouri Simernitski - MSFT Avatar answered Nov 16 '22 21:11

Iouri Simernitski - MSFT