Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 426 lines (358 sloc) 12.802 kb
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
a307b8e Nick Berardi fixed compression for CQL queries, it turns out that it is actually ZLIB
nberardi authored
4 using System.Net;
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
5 using Apache.Cassandra;
210341a Nick Berardi started to import in the client objects, still needs more tests
nberardi authored
6 using FluentCassandra.Types;
a307b8e Nick Berardi fixed compression for CQL queries, it turns out that it is actually ZLIB
nberardi authored
7 using System.IO;
8 using System.IO.Compression;
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
9
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
10 namespace FluentCassandra.Operations
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
11 {
5df6f7f Nick Berardi changed from .NET ticks to the Unix Epoch to be compatible with other ca...
nberardi authored
12 internal static class Helper
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
13 {
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
14 public static List<byte[]> ToByteArrayList(List<CassandraObject> list)
e06a0b5 Nick Berardi everything compiles
nberardi authored
15 {
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
16 return list.Select(x => x.TryToBigEndian()).ToList();
17 }
18
19 public static KeyRange CreateKeyRange(CassandraKeyRange range)
20 {
1e57fcf Nick Berardi refactored the cassandra slice query to be more inteligent and require d...
nberardi authored
21 if (range.StartKey == null && range.EndKey == null && range.StartToken == null && range.EndToken == null)
22 range = new CassandraKeyRange("", "", null, null, range.Count);
23
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
24 return new KeyRange {
25 Start_key = range.StartKey.TryToBigEndian(),
26 End_key = range.EndKey.TryToBigEndian(),
27 Start_token = range.StartToken,
28 End_token = range.EndToken,
29 Count = range.Count
30 };
31 }
32
33 public static IndexClause CreateIndexClause(CassandraIndexClause index)
34 {
35 return new IndexClause {
36 Start_key = index.StartKey.TryToBigEndian(),
37 Count = index.Count,
38 Expressions = index.CompiledExpressions
39 };
40 }
41
42 public static ColumnParent CreateColumnParent(CassandraColumnParent parent)
43 {
44 return new ColumnParent {
45 Column_family = parent.ColumnFamily,
46 Super_column = parent.SuperColumn.TryToBigEndian()
47 };
48 }
49
50 public static ColumnPath CreateColumnPath(CassandraColumnPath path)
51 {
52 return new ColumnPath {
53 Column = path.Column.TryToBigEndian(),
54 Column_family = path.ColumnFamily,
55 Super_column = path.SuperColumn.TryToBigEndian()
56 };
57 }
58
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
59 public static CassandraSlicePredicate SetSchemaForSlicePredicate(CassandraSlicePredicate predicate, CassandraColumnFamilySchema schema, bool forSuperColumn = false)
60 {
61 CassandraType columnType = forSuperColumn ? schema.SuperColumnNameType : schema.ColumnNameType;
62
63 if (predicate is CassandraRangeSlicePredicate)
64 {
65 var x = (CassandraRangeSlicePredicate)predicate;
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
66 var start = CassandraObject.GetCassandraObjectFromObject(x.Start, columnType);
67 var finish = CassandraObject.GetCassandraObjectFromObject(x.Finish, columnType);
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
68
69 return new CassandraRangeSlicePredicate(start, finish, x.Reversed, x.Count);
70 }
71 else if (predicate is CassandraColumnSlicePredicate)
72 {
73 var x = (CassandraColumnSlicePredicate)predicate;
74 var cols = x.Columns.ToList();
75
76 for (int i = 0; i < cols.Count; i++)
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
77 cols[i] = CassandraObject.GetCassandraObjectFromObject(cols[i], columnType);
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
78
79 return new CassandraColumnSlicePredicate(cols);
80 }
81
82 return null;
83 }
84
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
85 public static SlicePredicate CreateSlicePredicate(CassandraSlicePredicate predicate)
86 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
87 if (predicate is CassandraRangeSlicePredicate)
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
88 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
89 var x = (CassandraRangeSlicePredicate)predicate;
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
90 return new SlicePredicate {
91 Slice_range = new SliceRange {
92 Start = x.Start.TryToBigEndian() ?? new byte[0],
93 Finish = x.Finish.TryToBigEndian() ?? new byte[0],
94 Reversed = x.Reversed,
95 Count = x.Count
96 }
97 };
98 }
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
99 else if (predicate is CassandraColumnSlicePredicate)
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
100 {
2f86912 Nick Berardi all tests now compile, so the new genericless types have been provided b...
nberardi authored
101 var x = (CassandraColumnSlicePredicate)predicate;
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
102 return new SlicePredicate {
103 Column_names = x.Columns.Select(o => o.TryToBigEndian()).ToList()
104 };
105 }
106
107 return null;
108 }
109
110 public static Column CreateColumn(CassandraColumn column)
111 {
dc0875f Nick Berardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
112 var ccol = new Column {
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
113 Name = column.Name.TryToBigEndian(),
114 Value = column.Value.TryToBigEndian(),
27b16f3 Nick Berardi a fix for issue #44
nberardi authored
115 Timestamp = column.Timestamp.ToCassandraTimestamp()
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
116 };
dc0875f Nick Berardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
117
118 if (column.Ttl.HasValue && column.Ttl.Value > 0)
119 ccol.Ttl = column.Ttl.Value;
120
121 return ccol;
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
122 }
123
124 public static CounterColumn CreateCounterColumn(CassandraCounterColumn column)
125 {
126 return new CounterColumn {
127 Name = column.Name.TryToBigEndian(),
128 Value = column.Value
129 };
130 }
131
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
132 public static byte[] TryToBigEndian(this CassandraObject value)
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
133 {
134 if (value == null)
135 return null;
136
137 return value.ToBigEndian();
e06a0b5 Nick Berardi everything compiles
nberardi authored
138 }
139
1c343e3 Nick Berardi fixed issue #53 where schema wasn't being passed in to the column creati...
nberardi authored
140 public static IFluentBaseColumn ConvertToFluentBaseColumn(ColumnOrSuperColumn col, CassandraColumnFamilySchema schema)
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
141 {
142 if (col.Super_column != null)
10617e5 Nick Berardi all tests now pass
nberardi authored
143 return ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema);
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
144 else if (col.Column != null)
10617e5 Nick Berardi all tests now pass
nberardi authored
145 return ConvertColumnToFluentColumn(col.Column, schema);
3fe5603 Nick Berardi basic support DynamicCompositeType and CompositeType
nberardi authored
146 else if (col.Counter_super_column != null)
ac522e7 Nick Berardi added support for counter column
nberardi authored
147 return ConvertColumnToFluentCounterColumn(col.Counter_column, schema);
3fe5603 Nick Berardi basic support DynamicCompositeType and CompositeType
nberardi authored
148 else if (col.Counter_column != null)
ac522e7 Nick Berardi added support for counter column
nberardi authored
149 return ConvertSuperColumnToFluentCounterSuperColumn(col.Counter_super_column, schema);
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
150 else
151 return null;
152 }
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
153
1c343e3 Nick Berardi fixed issue #53 where schema wasn't being passed in to the column creati...
nberardi authored
154 public static FluentCounterColumn ConvertColumnToFluentCounterColumn(CounterColumn col, CassandraColumnFamilySchema schema)
ac522e7 Nick Berardi added support for counter column
nberardi authored
155 {
156 var colSchema = new CassandraColumnSchema();
157
158 if (schema != null)
159 {
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
160 var name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, schema.ColumnNameType);
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
161 colSchema = schema.Columns.Where(x => x.Name == name).FirstOrDefault();
ac522e7 Nick Berardi added support for counter column
nberardi authored
162
163 if (colSchema == null)
164 {
165 colSchema = new CassandraColumnSchema();
166 colSchema.NameType = schema.ColumnNameType;
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
167 colSchema.Name = name;
ac522e7 Nick Berardi added support for counter column
nberardi authored
168 colSchema.ValueType = schema.DefaultColumnValueType;
169 }
170 }
171
172 var fcol = new FluentCounterColumn(colSchema) {
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
173 ColumnName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, colSchema.NameType),
ac522e7 Nick Berardi added support for counter column
nberardi authored
174 ColumnValue = col.Value
175 };
176
177 return fcol;
178 }
179
1c343e3 Nick Berardi fixed issue #53 where schema wasn't being passed in to the column creati...
nberardi authored
180 public static FluentColumn ConvertColumnToFluentColumn(Column col, CassandraColumnFamilySchema schema)
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
181 {
10617e5 Nick Berardi all tests now pass
nberardi authored
182 var colSchema = new CassandraColumnSchema();
183
184 if (schema != null)
185 {
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
186 var name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, schema.ColumnNameType);
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
187 colSchema = schema.Columns.Where(x => x.Name == name).FirstOrDefault();
10617e5 Nick Berardi all tests now pass
nberardi authored
188
189 if (colSchema == null)
190 {
191 colSchema = new CassandraColumnSchema();
192 colSchema.NameType = schema.ColumnNameType;
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
193 colSchema.Name = name;
fc725a6 Nick Berardi fixed issues discovered while running sandbox
nberardi authored
194 colSchema.ValueType = schema.DefaultColumnValueType;
10617e5 Nick Berardi all tests now pass
nberardi authored
195 }
196 }
197
ff16fb5 Nick Berardi supporting key aliases in CQL
nberardi authored
198 return ConvertColumnToFluentColumn(col, colSchema);
199 }
200
201 public static FluentColumn ConvertColumnToFluentColumn(Column col, CassandraColumnSchema colSchema)
202 {
203 colSchema = colSchema ?? new CassandraColumnSchema();
204
10617e5 Nick Berardi all tests now pass
nberardi authored
205 var fcol = new FluentColumn(colSchema) {
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
206 ColumnName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, colSchema.NameType),
207 ColumnValue = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Value, colSchema.ValueType),
27b16f3 Nick Berardi a fix for issue #44
nberardi authored
208 ColumnTimestamp = TimestampHelper.FromCassandraTimestamp(col.Timestamp),
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
209 };
dc0875f Nick Berardi only in Cassandra does TTL mean Seconds Until Deleted
nberardi authored
210
211 if (col.__isset.ttl)
212 fcol.ColumnSecondsUntilDeleted = col.Ttl;
213
214 return fcol;
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
215 }
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
216
1c343e3 Nick Berardi fixed issue #53 where schema wasn't being passed in to the column creati...
nberardi authored
217 public static FluentSuperColumn ConvertSuperColumnToFluentCounterSuperColumn(CounterSuperColumn col, CassandraColumnFamilySchema schema)
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
218 {
219 var superColSchema = new CassandraColumnSchema {
220 Name = col.Name
221 };
222
223 if (schema != null)
224 superColSchema = new CassandraColumnSchema {
225 NameType = schema.SuperColumnNameType,
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
226 Name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, schema.SuperColumnNameType),
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
227 ValueType = schema.ColumnNameType
228 };
229
230 var superCol = new FluentSuperColumn(superColSchema) {
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
231 ColumnName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, superColSchema.NameType)
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
232 };
233
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
234 ((ILoadable)superCol).BeginLoad();
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
235 foreach (var xcol in col.Columns)
236 superCol.Columns.Add(ConvertColumnToFluentCounterColumn(xcol, schema));
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
237 ((ILoadable)superCol).EndLoad();
732173d Nick Berardi fixed a couple predicate builder problems discovered during unit testing
nberardi authored
238
239 return superCol;
240 }
241
1c343e3 Nick Berardi fixed issue #53 where schema wasn't being passed in to the column creati...
nberardi authored
242 public static FluentSuperColumn ConvertSuperColumnToFluentSuperColumn(SuperColumn col, CassandraColumnFamilySchema schema)
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
243 {
8466f05 Nick Berardi some more tests are passing with the recent changes
nberardi authored
244 var superColSchema = new CassandraColumnSchema {
245 Name = col.Name
246 };
10617e5 Nick Berardi all tests now pass
nberardi authored
247
248 if (schema != null)
8466f05 Nick Berardi some more tests are passing with the recent changes
nberardi authored
249 superColSchema = new CassandraColumnSchema {
250 NameType = schema.SuperColumnNameType,
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
251 Name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, schema.SuperColumnNameType),
8466f05 Nick Berardi some more tests are passing with the recent changes
nberardi authored
252 ValueType = schema.ColumnNameType
253 };
10617e5 Nick Berardi all tests now pass
nberardi authored
254
8466f05 Nick Berardi some more tests are passing with the recent changes
nberardi authored
255 var superCol = new FluentSuperColumn(superColSchema) {
f3bc872 Nick Berardi moved around some methods because they were on the wrong object
nberardi authored
256 ColumnName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, superColSchema.NameType)
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
257 };
258
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
259 ((ILoadable)superCol).BeginLoad();
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
260 foreach (var xcol in col.Columns)
10617e5 Nick Berardi all tests now pass
nberardi authored
261 superCol.Columns.Add(ConvertColumnToFluentColumn(xcol, schema));
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
262 ((ILoadable)superCol).EndLoad();
2e93bd7 Nick Berardi all tests passing for GetColumn for both standard and super families
nberardi authored
263
264 return superCol;
265 }
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
266
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
267 public static IEnumerable<Mutation> CreateDeletedColumnMutation(IEnumerable<FluentMutation> mutation)
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
268 {
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
269 foreach (var col in mutation)
270 {
271 var deletion = new Deletion {
27b16f3 Nick Berardi a fix for issue #44
nberardi authored
272 Timestamp = col.ColumnTimestamp.ToCassandraTimestamp(),
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
273 Predicate = CreateSlicePredicate(new[] { col.Column.ColumnName })
274 };
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
275
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
276 yield return new Mutation {
277 Deletion = deletion
278 };
279 }
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
280 }
281
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
282 public static IEnumerable<Mutation> CreateDeletedSuperColumnMutation(IEnumerable<FluentMutation> mutation)
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
283 {
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
284 foreach (var col in mutation)
285 {
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
286 var superColumn = col.Column.GetPath().SuperColumn.ColumnName.TryToBigEndian();
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
287
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
288 var deletion = new Deletion {
27b16f3 Nick Berardi a fix for issue #44
nberardi authored
289 Timestamp = col.ColumnTimestamp.ToCassandraTimestamp(),
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
290 Super_column = superColumn,
291 Predicate = CreateSlicePredicate(new[] { col.Column.ColumnName })
292 };
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
293
1b28998 Nick Berardi added some tests for the remove column functionality
nberardi authored
294 yield return new Mutation {
295 Deletion = deletion
296 };
297 }
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
298 }
299
300 public static Mutation CreateInsertedOrChangedMutation(FluentMutation mutation)
301 {
302 switch (mutation.Type)
303 {
304 case MutationType.Added:
305 case MutationType.Changed:
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
306 var column = mutation.Column;
307
308 if (column is FluentColumn)
309 {
310 return new Mutation {
311 Column_or_supercolumn = new ColumnOrSuperColumn {
312 Column = CreateColumn((FluentColumn)column)
313 }
314 };
315 }
316 else if (column is FluentSuperColumn)
317 {
318 var colY = (FluentSuperColumn)column;
319 var superColumn = new SuperColumn {
320 Name = colY.ColumnName.TryToBigEndian(),
321 Columns = new List<Column>()
322 };
323
324 foreach (var col in colY.MutationTracker.GetMutations().Select(x => x.Column).OfType<FluentColumn>())
325 superColumn.Columns.Add(CreateColumn(col));
326
327 return new Mutation {
328 Column_or_supercolumn = new ColumnOrSuperColumn {
329 Super_column = superColumn
330 }
331 };
332 }
333 break;
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
334 }
2c77dfc Nick Berardi refactored mutation handling to better handle super columns which fixed ...
nberardi authored
335
336 return null;
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
337 }
338
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
339 public static Column CreateColumn(FluentColumn column)
8f81f56 Nick Berardi fixed a couple issues with Fluent Super Column use, check out the sandbo...
nberardi authored
340 {
d74583a bjuris Fixed FluentColumn.ColumnSecondsUntilDeleted
bjuris authored
341 var col = new Column {
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
342 Name = column.ColumnName.TryToBigEndian(),
343 Value = column.ColumnValue.TryToBigEndian(),
27b16f3 Nick Berardi a fix for issue #44
nberardi authored
344 Timestamp = column.ColumnTimestamp.ToCassandraTimestamp()
8f81f56 Nick Berardi fixed a couple issues with Fluent Super Column use, check out the sandbo...
nberardi authored
345 };
5b513eb Nick Berardi corrected some spaces to tab issues and made sure the tests worked from ...
nberardi authored
346
347 if (column.ColumnSecondsUntilDeleted.HasValue)
348 col.Ttl = column.ColumnSecondsUntilDeleted.Value;
349
350 return col;
8f81f56 Nick Berardi fixed a couple issues with Fluent Super Column use, check out the sandbo...
nberardi authored
351 }
352
210341a Nick Berardi started to import in the client objects, still needs more tests
nberardi authored
353 public static ColumnOrSuperColumn CreateColumnOrSuperColumn(IFluentBaseColumn column)
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
354 {
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
355 if (column is FluentColumn)
8f81f56 Nick Berardi fixed a couple issues with Fluent Super Column use, check out the sandbo...
nberardi authored
356 {
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
357 return new ColumnOrSuperColumn {
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
358 Column = CreateColumn((FluentColumn)column)
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
359 };
8f81f56 Nick Berardi fixed a couple issues with Fluent Super Column use, check out the sandbo...
nberardi authored
360 }
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
361 else if (column is FluentSuperColumn)
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
362 {
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
363 var colY = (FluentSuperColumn)column;
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
364 var superColumn = new SuperColumn {
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
365 Name = colY.ColumnName.TryToBigEndian(),
f77d3d9 Nick Berardi cleaning up some tests and getting example to work as part of some pre-p...
nberardi authored
366 Columns = new List<Column>()
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
367 };
368
e1b11ad Nick Berardi [breaking change] with recent changes in the Cassandra API and the new d...
nberardi authored
369 foreach (var col in colY.Columns.OfType<FluentColumn>())
8f81f56 Nick Berardi fixed a couple issues with Fluent Super Column use, check out the sandbo...
nberardi authored
370 superColumn.Columns.Add(CreateColumn(col));
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
371
372 return new ColumnOrSuperColumn {
373 Super_column = superColumn
374 };
375 }
376 else
377 {
378 return null;
379 }
380 }
381
d576460 Nick Berardi made the type system more robus to support parsing of complex types from...
nberardi authored
382 public static SlicePredicate CreateSlicePredicate(IEnumerable<CassandraObject> columnNames)
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
383 {
384 return new SlicePredicate {
321da49 Nick Berardi refactoring of way operations happen, and created a wrapper for the cass...
nberardi authored
385 Column_names = columnNames.Select(o => o.TryToBigEndian()).ToList()
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
386 };
387 }
a307b8e Nick Berardi fixed compression for CQL queries, it turns out that it is actually ZLIB
nberardi authored
388
389 public static byte[] ZlibCompress(byte[] data)
390 {
391 // Note: even though Cassandra calls this GZIP compression it is actually ZLIB compression provided by the
392 // Java Inflator class http://docs.oracle.com/javase/1.4.2/docs/api/java/util/zip/Inflater.html
393 // If it wasn't for this post explaining how to get Deflator to mimic ZLIB compression none of the following
394 // code would work http://tlzprgmr.wordpress.com/2010/03/17/net-deflatestreamzlib-compatibility/
395 using (MemoryStream outStream = new MemoryStream())
396 {
397 // zlib header
398 outStream.WriteByte(0x58);
399 outStream.WriteByte(0x85);
400
401 // zlib body
402 using (var compressor = new DeflateStream(outStream, CompressionMode.Compress, true))
403 compressor.Write(data, 0, data.Length);
404
405 // zlib checksum - a naive implementation of adler-32 checksum
406 const uint A32Mod = 65521;
407 uint s1 = 1, s2 = 0;
408 foreach (byte b in data)
409 {
410 s1 = (s1 + b) % A32Mod;
411 s2 = (s2 + s1) % A32Mod;
412 }
413
414 int adler32 = unchecked((int)((s2 << 16) + s1));
415 outStream.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(adler32)), 0, sizeof(uint));
416
417 // zlib compatible compressed query
418 var bytes = outStream.ToArray();
419 outStream.Close();
420
421 return bytes;
422 }
423 }
f27726f Nick Berardi adding mutation tracking to the fluent objects
nberardi authored
424 }
425 }
Something went wrong with that request. Please try again.