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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With