Question

I am trying to query the WadPerformanceCountersTable generated by Azure Diagnostics which has a PartitionKey based on tick marks accurate up to the minute. This PartitionKey is stored as a string (which I do not have any control over).

I want to be able to query against this table to get data points for every minute, every hour, every day, etc. so I don't have to pull all of the data (I just want a sampling to approximate it). I was hoping to using the modulus operator to do this, but since the PartitionKey is stored as a string and this is an Azure Table, I am having issues.

Is there any way to do this?

Non-working example:

var query =
            (from entity in ServiceContext.CreateQuery<PerformanceCountersEntity>("WADPerformanceCountersTable")
                where
                    long.Parse(entity.PartitionKey) % interval == 0 && //bad for a variety of reasons
                    String.Compare(entity.PartitionKey, partitionKeyEnd, StringComparison.Ordinal) < 0 &&
                    String.Compare(entity.PartitionKey, partitionKeyStart, StringComparison.Ordinal) > 0
                select entity)
                .AsTableServiceQuery();
Was it helpful?

Solution 2

The only way I can see to do this would be to create a process to keep the Azure table in sync with another version of itself. In this table, I would store the PartitionKey as a number instead of a string. Once done, I could use a method similar to what I wrote in my question to query the data.

However, this is a waste of resources, so I don't recommend it. (I'm not implementing it myself, either.)

OTHER TIPS

If you just want to get a single row based on two different time interval (now and N time back) you can use the following query which returns the single row as described here:

// 10 minutes span Partition Key
DateTime now = DateTime.UtcNow;

// Current Partition Key
string partitionKeyNow = string.Format("0{0}", now.Ticks.ToString());

DateTime tenMinutesSpan = now.AddMinutes(-10);
string partitionKeyTenMinutesBack = string.Format("0{0}",   tenMinutesSpan.Ticks.ToString());

//Get single row sample created last 10 mminutes
CloudTableQuery<WadPerformanceCountersTable> cloudTableQuery =
    ( 
      from entity in ServiceContext.CreateQuery<PerformanceCountersEntity>("WADPerformanceCountersTable") 
      where 
           entity.PartitionKey.CompareTo(partitionKeyNow) < 0 && 
           entity.PartitionKey.CompareTo(partitionKeyTenMinutesBack) > 0 
        select entity
    ).Take(1).AsTableServiceQuery();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top