This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
MultiGetSuperColumnFamilySlice.cs
73 lines (58 loc) · 2.1 KB
/
MultiGetSuperColumnFamilySlice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using FluentCassandra.Types;
namespace FluentCassandra.Operations
{
public class MultiGetSuperColumnFamilySlice : QueryableColumnFamilyOperation<FluentSuperColumnFamily>
{
public List<CassandraObject> Keys { get; private set; }
public CassandraObject SuperColumnName { get; private set; }
public override IEnumerable<FluentSuperColumnFamily> Execute()
{
var schema = ColumnFamily.GetSchema();
var parent = new CassandraColumnParent {
ColumnFamily = ColumnFamily.FamilyName
};
if (SuperColumnName != null)
parent.SuperColumn = SuperColumnName;
SlicePredicate = Helper.SetSchemaForSlicePredicate(SlicePredicate, schema, SuperColumnName == null);
var output = Session.GetClient().multiget_slice(
Keys,
parent,
SlicePredicate,
Session.ReadConsistency
);
foreach (var result in output)
{
var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyValueType);
var superColumns = (IEnumerable<FluentSuperColumn>)null;
if (SuperColumnName != null)
{
var superColSchema = new CassandraColumnSchema {
NameType = schema.SuperColumnNameType,
Name = SuperColumnName,
ValueType = schema.ColumnNameType
};
var superCol = new FluentSuperColumn(superColSchema, result.Value.Select(col => Helper.ConvertColumnToFluentColumn(col.Column, schema)));
ColumnFamily.Context.Attach(superCol);
superColumns = new[] { superCol };
}
else
{
superColumns = result.Value.Select(col => Helper.ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema));
}
var familyName = ColumnFamily.FamilyName;
var r = new FluentSuperColumnFamily(key, familyName, schema, superColumns);
ColumnFamily.Context.Attach(r);
yield return r;
}
}
public MultiGetSuperColumnFamilySlice(IEnumerable<CassandraObject> keys, CassandraObject superColumnName, CassandraSlicePredicate columnSlicePredicate)
{
Keys = keys.ToList();
SuperColumnName = superColumnName;
SlicePredicate = columnSlicePredicate;
}
}
}