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
/
CassandraCqlRowSchema.cs
65 lines (51 loc) · 1.68 KB
/
CassandraCqlRowSchema.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
using FluentCassandra.Apache.Cassandra;
using FluentCassandra.Types;
using System.Collections.Generic;
namespace FluentCassandra
{
public class CassandraCqlRowSchema
{
#if DEBUG
private CqlMetadata _def;
#endif
public CassandraCqlRowSchema(CqlResult result, string familyName)
{
#if DEBUG
_def = result.Schema;
#endif
var def = result.Schema;
var colNameType = CassandraType.GetCassandraType(def.Default_name_type);
var colValueType = CassandraType.GetCassandraType(def.Default_value_type);
FamilyName = familyName;
DefaultColumnNameType = colNameType;
DefaultColumnValueType = colValueType;
Columns = new List<CassandraColumnSchema>();
var colNameTypes = new Dictionary<CassandraObject, CassandraType>();
foreach (var c in def.Name_types)
{
var type = CassandraType.GetCassandraType(c.Value);
var name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(c.Key, CassandraType.BytesType);
colNameTypes.Add(name, type);
}
// columns returned
foreach (var c in def.Value_types)
{
var type = CassandraType.GetCassandraType(c.Value);
var nameType = colNameType;
var name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(c.Key, CassandraType.BytesType);
if (colNameTypes.ContainsKey(name))
nameType = colNameTypes[name];
var colSchema = new CassandraColumnSchema {
NameType = nameType,
Name = name,
ValueType = type
};
Columns.Add(colSchema);
}
}
public string FamilyName { get; set; }
public CassandraType DefaultColumnNameType { get; set; }
public CassandraType DefaultColumnValueType { get; set; }
public IList<CassandraColumnSchema> Columns { get; set; }
}
}