Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added support for MultiGetSlice for Counter columns and super columns #101

Merged
merged 4 commits into from

2 participants

@Aaronontheweb

Added support for MultiGetSlice for Counter columns and super columns

Quick question though: I haven't been able to get any of the unit tests that connect to a live Cassandra instance to run due to errors with the CassandraDatabaseSetup.cs bootstrapper throwing errors - I think it has to do with the version of Cassandra running on my machine (DataStax Community Edition v1.1)

Could someone try running these and see if my new unit test Counter_GetSlice_Columns() passes? I've been able to verify that the behavior works as expected inside my application now that I've made this change, but I don't like the fact that I can't get 80ish of the built-in unit tests to run on my system :(

Aaronontheweb added some commits
@Aaronontheweb Aaronontheweb Changed the MultiGetColumnFamilySlice operator to check to see if a c…
…ounter column type was returned, and do the subsequent conversion if found. Otherwise, default to normal behavior.
668cc47
@Aaronontheweb Aaronontheweb Made the same change to SuperColumnFamilies cce150d
@Aaronontheweb Aaronontheweb Added a CounterColumnFamily to the DatabaseSetup a6e3f52
@Aaronontheweb Aaronontheweb Finished adding the Counters bootstrap information to the CassandraDa…
…tabaseSetup.cs file and implemented the Counter_GetSlice_Columns() unit test in the MultiSliceGetTest.cs file
311cd7b
@nberardi
Owner

These look good, but please be respectful of the tab formatting. If you don't have this tool yet. It is great for fixing mixed tab/space files.

http://blogs.msdn.com/b/visualstudio/archive/2012/11/07/productivity-power-tools-2012.aspx

@nberardi nberardi merged commit 8825803 into from
@Aaronontheweb

will do - thanks @nberardi

@nberardi nberardi was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2013
  1. @Aaronontheweb

    Changed the MultiGetColumnFamilySlice operator to check to see if a c…

    Aaronontheweb authored
    …ounter column type was returned, and do the subsequent conversion if found. Otherwise, default to normal behavior.
  2. @Aaronontheweb
  3. @Aaronontheweb
  4. @Aaronontheweb

    Finished adding the Counters bootstrap information to the CassandraDa…

    Aaronontheweb authored
    …tabaseSetup.cs file and implemented the Counter_GetSlice_Columns() unit test in the MultiSliceGetTest.cs file
This page is out of date. Refresh to see the latest.
View
4 src/Operations/MultiGetColumnFamilySlice.cs
@@ -36,7 +36,9 @@ public override IEnumerable<FluentColumnFamily> Execute()
var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyValueType);
var r = new FluentColumnFamily(key, ColumnFamily.FamilyName, schema, result.Value.Select(col => {
- return Helper.ConvertColumnToFluentColumn(col.Column, schema);
+ if(col.Counter_column != null)
+ return Helper.ConvertColumnToFluentCounterColumn(col.Counter_column, schema);
+ return Helper.ConvertColumnToFluentColumn(col.Column, schema);
}));
ColumnFamily.Context.Attach(r);
r.MutationTracker.Clear();
View
7 src/Operations/MultiGetSuperColumnFamilySlice.cs
@@ -53,7 +53,12 @@ public override IEnumerable<FluentSuperColumnFamily> Execute()
}
else
{
- superColumns = result.Value.Select(col => Helper.ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema));
+ superColumns = result.Value.Select(col =>
+ {
+ if (col.Counter_super_column != null)
+ return Helper.ConvertSuperColumnToFluentCounterSuperColumn(col.Counter_super_column, schema);
+ return Helper.ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema);
+ });
}
var familyName = ColumnFamily.FamilyName;
View
35 test/FluentCassandra.Tests/CassandraDatabaseSetup.cs
@@ -13,8 +13,11 @@ public class CassandraDatabaseSetup
public CassandraContext DB;
public CassandraColumnFamily<AsciiType> Family;
+
public CassandraSuperColumnFamily<AsciiType, AsciiType> SuperFamily;
+
public CassandraColumnFamily UserFamily;
+ public CassandraColumnFamily CounterFamily;
public User[] Users = new[] {
new User { Id = 1, Name = "Darren Gemmell", Email = "darren@somewhere.com", Age = 32 },
@@ -51,6 +54,7 @@ public CassandraDatabaseSetup(bool reset = false)
Family = DB.GetColumnFamily<AsciiType>("Standard");
SuperFamily = DB.GetColumnFamily<AsciiType, AsciiType>("Super");
UserFamily = DB.GetColumnFamily("Users");
+ CounterFamily = DB.GetColumnFamily("Counters");
if (exists && !reset)
return;
@@ -82,6 +86,12 @@ public void ResetDatabase()
keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
+ keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema()
+ {
+ FamilyName = "Counters",
+ ColumnNameType = CassandraType.AsciiType,
+ DefaultColumnValueType = CassandraType.CounterColumnType
+ });
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "StandardDecimalType",
ColumnNameType = CassandraType.DecimalType
@@ -95,23 +105,25 @@ public void ResetDatabase()
ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
});
- db.ExecuteNonQuery(@"
+ db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
Id int PRIMARY KEY,
Name ascii,
Email ascii,
Age int
);");
- db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
+ db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);");
db.Keyspace.ClearCachedKeyspaceSchema();
var family = db.GetColumnFamily<AsciiType>("Standard");
var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
- var userFamily = db.GetColumnFamily("Users");
+ var userFamily = db.GetColumnFamily("Users");
+ var counterFamily = db.GetColumnFamily("Counter");
ResetFamily(family);
ResetSuperFamily(superFamily);
- ResetUsersFamily(userFamily);
+ ResetUsersFamily(userFamily);
+ ResetCounterColumnFamily(counterFamily);
}
}
@@ -164,5 +176,20 @@ public void ResetSuperFamily(CassandraSuperColumnFamily superFamily = null)
superFamily.InsertColumn(TestKey2, TestSuperName, "Test2", Math.PI);
superFamily.InsertColumn(TestKey2, TestSuperName, "Test3", Math.PI);
}
+
+ public void ResetCounterColumnFamily(CassandraColumnFamily counterFamily = null)
+ {
+ counterFamily = counterFamily ?? CounterFamily;
+
+ counterFamily.RemoveAllRows();
+
+ counterFamily.InsertCounterColumn(TestKey1, "Test1", 1);
+ counterFamily.InsertCounterColumn(TestKey1, "Test2", 2);
+ counterFamily.InsertCounterColumn(TestKey1, "Test3", 3);
+
+ counterFamily.InsertCounterColumn(TestKey2, "Test1", 2);
+ counterFamily.InsertCounterColumn(TestKey2, "Test2", 4);
+ counterFamily.InsertCounterColumn(TestKey2, "Test3", 6);
+ }
}
}
View
19 test/FluentCassandra.Tests/Operations/MultiGetSliceTest.cs
@@ -10,6 +10,8 @@ public class MultiGetSliceTest : IUseFixture<CassandraDatabaseSetupFixture>, IDi
{
private CassandraContext _db;
private CassandraColumnFamily<AsciiType> _family;
+ private CassandraColumnFamily _counterFamily;
+
private CassandraSuperColumnFamily<AsciiType, AsciiType> _superFamily;
public void SetFixture(CassandraDatabaseSetupFixture data)
@@ -18,6 +20,7 @@ public void SetFixture(CassandraDatabaseSetupFixture data)
_db = setup.DB;
_family = setup.Family;
_superFamily = setup.SuperFamily;
+ _counterFamily = setup.CounterFamily;
}
public void Dispose()
@@ -46,6 +49,22 @@ public void Standard_GetSlice_Columns()
Assert.Equal(expectedCount, columns.Count());
}
+ [Fact]
+ public void Counter_GetSlice_Columns()
+ {
+ // arrange
+ int expectedCount = 2;
+
+ // act
+ var columns = _counterFamily
+ .Get(new BytesType[] { _testKey, _testKey2 })
+ .FetchColumns(new AsciiType[] { "Test1", "Test2" })
+ .Execute();
+
+ // assert
+ Assert.Equal(expectedCount, columns.Count());
+ }
+
[Fact]
public void Super_GetSlice_Columns()
{
Something went wrong with that request. Please try again.