Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get distinct PartionKeys from a Table

Currently I'm using the PartitionKey to differentiate devices that are storing data into Azure Table Services. I'd like to build a viewer that allows me to browse that data, but it would be nice to be able to structure it so I can view data "by device", or by PartitionKey. The viewer app won't have any knowledge of what devices exist, so it would be great if I could somehow get back a list of distinct PartionKeys in a given Table. Is this possible, or am I going to be relegated to creating a meta-data table into which I insert a new row for each device, then use that for querying?

like image 494
ctacke Avatar asked Oct 12 '12 15:10

ctacke


People also ask

Does partition key have to be primary key?

The Partition Column must be a Key Column in any partitioned unique index. So the answer is no, but if it's not the primary key cannot be partitioned.

How do you use distinct in Cassandra?

Use the DISTINCT keyword to return only distinct (different) values of partition keys. The FROM clause specifies the table to query. You may want to precede the table name with the name of the keyspace followed by a period (.). If you do not specify a keyspace, Cassandra queries the current keyspace.

What is partition key in Azure table?

The partition key is a unique identifier for the partition within a given table, specified by the PartitionKey property. The partition key forms the first part of an entity's primary key. The partition key may be a string value up to 1 KiB in size.


1 Answers

Create a single table to store your partitions. Partition the table by the table names you use and add an entry for each partition you create.

public class PartitionEntry : TableServiceEntity { }

tableServiceContext.AddObject("TablePartitions", new PartitionEntry
{
    PartitionKey = "<table name>",
    RowKey = "<partition key>",
});
tableServiceContext.BeginSaveChanges(SaveChangesOptions.ContinueOnError, null, null);

then just query this table to get a list of partitions. This is very manageable to me.

var tbl = tableServiceContext.CreateQuery<PartitionEntry>("TablePartitions");
return tbl.Where(i => i.PartitionKey == "<table name>")
          .Select(i => new { PartitionKey = i.RowKey, });

I bet this could be optimized.

like image 116
danatcofo Avatar answered Sep 18 '22 14:09

danatcofo