本文整理汇总了C#中Apache.Cassandra.ColumnParent类的典型用法代码示例。如果您正苦于以下问题:C# ColumnParent类的具体用法?C# ColumnParent怎么用?C# ColumnParent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColumnParent类属于Apache.Cassandra命名空间,在下文中一共展示了ColumnParent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
// private string columnFamily = "users";
// private string keyspace = "test";
// private string key = "testKey";
// // Insert statement
//// private byte[] key = ByteEncoderHelper.LongEncoder.ToByteArray(i);
// private byte[] key = ByteEncoderHelper.LongEncoder.ToByteArray(2);
// private ColumnParent columnParent;
// private Column column;
// private ColumnPath columnPath;
// private ICluster cluster;
//
//
//
//cluster.Execute(new ExecutionBlock(delegate(CassandraClient client) {
// client.insert(key, columnParent, column, ConsistencyLevel.ONE);
// return null;
//}), keyspace);
// // Get statement
// byte[] key = ByteEncoderHelper.LongEncoder.ToByteArray(2);
//
// ICluster cluster = AquilesHelper.RetrieveCluster("Cassandra1");
// object rtnValue = cluster.Execute(new ExecutionBlock(delegate(CassandraClient client)
// {
// return client.get(key, columnPath, ConsistencyLevel.ONE);
// }), keyspace);
public void Run()
{
string columnFamily = "TestColumnFamily";
string keyspace = "TestKeyspace";
string key = "testKey";
string columnName = "testColumn";
string columnValue = "testValue";
// Insert statement
byte[] key2 = ByteEncoderHelper.LongEncoder.ToByteArray(1);
ColumnParent columnParent = new ColumnParent();
Column column = new Column()
{
Name = ByteEncoderHelper.UTF8Encoder.ToByteArray(columnName),
Timestamp = UnixHelper.UnixTimestamp,
Value = ByteEncoderHelper.UTF8Encoder.ToByteArray(columnValue),
};
columnParent.Column_family = columnFamily;
ICluster cluster = AquilesHelper.RetrieveCluster("Cassandra1");
cluster.Execute(new ExecutionBlock(delegate(CassandraClient client)
{
client.insert(key, columnParent, column, ConsistencyLevel.ONE);
return null;
}), keyspace);
}
示例2: Main
private static void Main()
{
TTransport framedTransport = new TFramedTransport(new TSocket("localhost", 9160));
TTransport socketTransport = new TSocket("localhost", 9160);
TProtocol framedProtocol = new TBinaryProtocol(framedTransport);
TProtocol socketProtocol = new TBinaryProtocol(socketTransport);
var client = new Cassandra.Client(framedProtocol, framedProtocol); // all framed
//var client = new Cassandra.Client(socketProtocol, socketProtocol); // all socket
//var client = new Cassandra.Client(framedProtocol, socketProtocol); // in: framed out: socket
//var client = new Cassandra.Client(socketProtocol, framedProtocol); // in: socket out: framed
framedTransport.Open();
socketTransport.Open();
Console.WriteLine("Start");
client.set_keyspace("Keyspace1");
Console.WriteLine("Count Key");
var key = Encoding.ASCII.GetBytes("MyKey");
var columns = new List<byte[]>(new[] { Encoding.ASCII.GetBytes("MyColumn") });
var column_parent = new ColumnParent {
Column_family = "Standard1"
};
var predicate = new SlicePredicate {
Column_names = columns
};
client.get_count(key, column_parent, predicate, ConsistencyLevel.ALL);
Console.WriteLine("Done");
Console.Read();
}
示例3: BuildColumnParent
/// <summary>
/// Biuld Thrift ColumnParent structure using ColumnFamily and SuperColumn information
/// </summary>
/// <param name="superColumn">name for the supercolumn (null in case there is not one)</param>
/// <returns>Thrift ColumnParent</returns>
protected ColumnParent BuildColumnParent(string superColumn)
{
ColumnParent columnParent = new ColumnParent();
bool isSuperColumnMissing = String.IsNullOrEmpty(superColumn);
columnParent.Column_family = this.ColumnFamily;
if (!isSuperColumnMissing)
{
columnParent.Super_column = ByteEncoderHelper.ToByteArray(superColumn);
}
return columnParent;
}
示例4: get_count
public int get_count(byte[] key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
{
send_get_count(key, column_parent, predicate, consistency_level);
return recv_get_count();
}
示例5: Read
public void Read(TProtocol iprot)
{
TField field;
iprot.ReadStructBegin();
while (true)
{
field = iprot.ReadFieldBegin();
if (field.Type == TType.Stop) {
break;
}
switch (field.ID)
{
case 1:
if (field.Type == TType.List) {
{
Keys = new List<byte[]>();
TList _list87 = iprot.ReadListBegin();
for( int _i88 = 0; _i88 < _list87.Count; ++_i88)
{
byte[] _elem89 = null;
_elem89 = iprot.ReadBinary();
Keys.Add(_elem89);
}
iprot.ReadListEnd();
}
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 2:
if (field.Type == TType.Struct) {
Column_parent = new ColumnParent();
Column_parent.Read(iprot);
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 3:
if (field.Type == TType.Struct) {
Predicate = new SlicePredicate();
Predicate.Read(iprot);
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 4:
if (field.Type == TType.I32) {
Consistency_level = (ConsistencyLevel)iprot.ReadI32();
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
default:
TProtocolUtil.Skip(iprot, field.Type);
break;
}
iprot.ReadFieldEnd();
}
iprot.ReadStructEnd();
}
示例6: send_insert
public void send_insert(byte[] key, ColumnParent column_parent, Column column, ConsistencyLevel consistency_level)
{
oprot_.WriteMessageBegin(new TMessage("insert", TMessageType.Call, seqid_));
insert_args args = new insert_args();
args.Key = key;
args.Column_parent = column_parent;
args.Column = column;
args.Consistency_level = consistency_level;
args.Write(oprot_);
oprot_.WriteMessageEnd();
oprot_.Transport.Flush();
}
示例7: send_get_indexed_slices
public void send_get_indexed_slices(ColumnParent column_parent, IndexClause index_clause, SlicePredicate column_predicate, ConsistencyLevel consistency_level)
{
oprot_.WriteMessageBegin(new TMessage("get_indexed_slices", TMessageType.Call, seqid_));
get_indexed_slices_args args = new get_indexed_slices_args();
args.Column_parent = column_parent;
args.Index_clause = index_clause;
args.Column_predicate = column_predicate;
args.Consistency_level = consistency_level;
args.Write(oprot_);
oprot_.WriteMessageEnd();
oprot_.Transport.Flush();
}
示例8: multiget_slice
public Dictionary<byte[], List<ColumnOrSuperColumn>> multiget_slice(List<byte[]> keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)
{
send_multiget_slice(keys, column_parent, predicate, consistency_level);
return recv_multiget_slice();
}
示例9: RetrieveAllColumnsInChunks
private List<ColumnOrSuperColumn> RetrieveAllColumnsInChunks(int chunkSize, byte[] key,
ColumnParent columnParent, SlicePredicate pred, ConsistencyLevel consistencyLevel)
{
pred.Slice_range.Count = chunkSize;
List<ColumnOrSuperColumn> retColumns = new List<ColumnOrSuperColumn>();
ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
while (true)
{
object val =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
return client.get_slice(key, columnParent, pred, consistencyLevel);
}), KEYSPACE);
List<ColumnOrSuperColumn> cols = (List<ColumnOrSuperColumn>)val;
if (pred.Slice_range.Start.Length == 0)
{
//no start specified, beginning of range
retColumns.AddRange(cols);
}
else
{
//omit the first returned item since it will be the last item
//in the previous get
for (int i = 1; i < cols.Count; i++)
{
retColumns.Add(cols[i]);
}
}
//if we didnt retrieve chunkSize rows, we finished
if (cols.Count < chunkSize)
{
break;
}
//else, we need to set the new start and continue
if (cols[cols.Count - 1].Column != null)
{
pred.Slice_range.Start = cols[cols.Count - 1].Column.Name;
}
else
{
pred.Slice_range.Start = cols[cols.Count - 1].Super_column.Name;
}
}
return retColumns;
}
示例10: GetActiveGestureItemIds
private List<UUID> GetActiveGestureItemIds(UUID userId)
{
try
{
ColumnParent columnParent = new ColumnParent();
columnParent.Column_family = USERACTIVEGESTURES_CF;
SlicePredicate pred = new SlicePredicate();
SliceRange range = new SliceRange();
range.Start = new byte[0];
range.Finish = new byte[0];
range.Reversed = false;
range.Count = int.MaxValue;
pred.Slice_range = range;
ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
object retobj =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
byte[] userIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(userId.Guid);
return client.get_slice(userIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);
}), KEYSPACE);
List<ColumnOrSuperColumn> cols = (List<ColumnOrSuperColumn>)retobj;
List<UUID> ret = new List<UUID>();
foreach (ColumnOrSuperColumn col in cols)
{
ret.Add(new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Column.Name)));
}
return ret;
}
catch (Exception e)
{
throw new InventoryStorageException(e.Message, e);
}
}
示例11: FindItemParentFolderIds
/// <summary>
/// Returns a dictionary of parents with a list of items Dictionary[FolderID, List[Items]]
/// </summary>
/// <param name="itemIds"></param>
/// <returns></returns>
public Dictionary<UUID, List<UUID>> FindItemParentFolderIds(IEnumerable<UUID> itemIds)
{
ColumnParent columnParent = new ColumnParent();
columnParent.Column_family = ITEMPARENTS_CF;
SlicePredicate pred = new SlicePredicate();
pred.Column_names = new List<byte[]>();
pred.Column_names.Add(ByteEncoderHelper.UTF8Encoder.ToByteArray("parent"));
List<byte[]> allItemIdBytes = new List<byte[]>();
foreach (UUID id in itemIds)
{
allItemIdBytes.Add(ByteEncoderHelper.GuidEncoder.ToByteArray(id.Guid));
}
ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
object val =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
return client.multiget_slice(allItemIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);
}), KEYSPACE);
Dictionary<byte[], List<ColumnOrSuperColumn>> itemParentCols = (Dictionary<byte[], List<ColumnOrSuperColumn>>)val;
Dictionary<UUID, List<UUID>> retParents = new Dictionary<UUID, List<UUID>>();
foreach (KeyValuePair<byte[], List<ColumnOrSuperColumn>> kvp in itemParentCols)
{
if (kvp.Value.Count == 1)
{
Column col = kvp.Value[0].Column;
UUID parentId = new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(col.Value));
if (!retParents.ContainsKey(parentId))
{
retParents.Add(parentId, new List<UUID>());
}
retParents[parentId].Add(new UUID(ByteEncoderHelper.GuidEncoder.FromByteArray(kvp.Key)));
}
}
return retParents;
}
示例12: FindItemParentFolderId
public Guid FindItemParentFolderId(UUID itemId)
{
ColumnParent columnParent = new ColumnParent();
columnParent.Column_family = ITEMPARENTS_CF;
SlicePredicate pred = new SlicePredicate();
SliceRange range = new SliceRange();
range.Start = new byte[0];
range.Finish = new byte[0];
range.Reversed = false;
range.Count = int.MaxValue;
pred.Slice_range = range;
byte[] itemIdArray = ByteEncoderHelper.GuidEncoder.ToByteArray(itemId.Guid);
ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
object val =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
return client.get_slice(itemIdArray, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);
}), KEYSPACE);
List<ColumnOrSuperColumn> indexCols = (List<ColumnOrSuperColumn>)val;
//no index means the item doesnt exist
if (indexCols.Count == 0)
{
return Guid.Empty;
}
var indexedColsByName = this.IndexColumnsByUTF8Name(indexCols);
return ByteEncoderHelper.GuidEncoder.FromByteArray(indexedColsByName["parent"].Value);
}
示例13: RetrieveRowsInChunks
/// <summary>
/// Retrieves all the rows for the given list of keys in chunkSize chunks
/// </summary>
/// <param name="chunkSize"></param>
/// <param name="allKeys"></param>
/// <param name="colParent"></param>
/// <param name="pred"></param>
/// <param name="consistencyLevel"></param>
/// <returns></returns>
private Dictionary<byte[], List<ColumnOrSuperColumn>> RetrieveRowsInChunks(int chunkSize, List<byte[]> allKeys,
ColumnParent colParent, SlicePredicate pred, ConsistencyLevel consistencyLevel)
{
ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
if (allKeys.Count <= chunkSize)
{
object val =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
return client.multiget_slice(allKeys, colParent, pred, consistencyLevel);
}), KEYSPACE);
return (Dictionary<byte[], List<ColumnOrSuperColumn>>)val;
}
else
{
Dictionary<byte[], List<ColumnOrSuperColumn>> ret = new Dictionary<byte[], List<ColumnOrSuperColumn>>();
for (int i = 0; i < allKeys.Count; i += chunkSize)
{
int remaining = allKeys.Count - i;
List<byte[]> keys = allKeys.GetRange(i, remaining >= chunkSize ? chunkSize : remaining);
object val =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
return client.multiget_slice(keys, colParent, pred, consistencyLevel);
}), KEYSPACE);
Dictionary<byte[], List<ColumnOrSuperColumn>> chunk = (Dictionary<byte[], List<ColumnOrSuperColumn>>)val;
foreach(KeyValuePair<byte[], List<ColumnOrSuperColumn>> kvp in chunk)
{
ret.Add(kvp.Key, kvp.Value);
}
}
return ret;
}
}
示例14: GetItem
public InventoryItemBase GetItem(UUID itemId, UUID parentFolderHint)
{
//Retrieving an item requires a lookup of the parent folder followed by
//a retrieval of the item. This was a consious decision made since the
//inventory item data currently takes up the most space and a
//duplication of this data to prevent the index lookup
//would be expensive in terms of space required
try
{
Guid parentId;
if (parentFolderHint != UUID.Zero)
{
parentId = parentFolderHint.Guid;
}
else
{
parentId = FindItemParentFolderId(itemId);
}
if (parentId == Guid.Empty)
{
throw new InventoryObjectMissingException(String.Format("Item with ID {0} could not be found", itemId), "Item was not found in the index");
}
//try to retrieve the item. note that even though we have an index there is a chance we will
//not have the item data due to a race condition between index mutation and item mutation
byte[] itemIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(itemId.Guid);
byte[] folderIdBytes = ByteEncoderHelper.GuidEncoder.ToByteArray(parentId);
ColumnParent columnParent = new ColumnParent();
columnParent.Column_family = FOLDERS_CF;
columnParent.Super_column = itemIdBytes;
SlicePredicate pred = new SlicePredicate();
SliceRange range = new SliceRange();
range.Start = new byte[0];
range.Finish = new byte[0];
range.Reversed = false;
range.Count = int.MaxValue;
pred.Slice_range = range;
ICluster cluster = AquilesHelper.RetrieveCluster(_clusterName);
object itemDataObj =
cluster.Execute(new ExecutionBlock(delegate(Apache.Cassandra.Cassandra.Client client)
{
return client.get_slice(folderIdBytes, columnParent, pred, DEFAULT_CONSISTENCY_LEVEL);
}), KEYSPACE);
List<ColumnOrSuperColumn> itemCols = (List<ColumnOrSuperColumn>)itemDataObj;
if (itemCols.Count == 0)
{
throw new InventoryObjectMissingException(String.Format("Item with ID {0} could not be found", itemId), "Item was not found in its folder");
}
InventoryItemBase item = this.DecodeInventoryItem(itemCols, itemId.Guid, parentId);
return item;
}
catch (InventoryStorageException)
{
throw;
}
catch (Exception e)
{
_log.ErrorFormat("[Inworldz.Data.Inventory.Cassandra] Unable to retrieve item {0}: {1}", itemId, e);
throw new InventoryStorageException(e.Message, e);
}
}
示例15: insert
public void insert(byte[] key, ColumnParent column_parent, Column column, ConsistencyLevel consistency_level)
{
send_insert(key, column_parent, column, consistency_level);
recv_insert();
}