Skip to content
Browse files

supporting key aliases in CQL

  • Loading branch information...
1 parent e688282 commit ff16fb5196cf5547ce4d9e75c52cffb2ab812e6b @nberardi nberardi committed Jun 6, 2012
View
95 FluentCassandra.sln
@@ -1,6 +1,6 @@

-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra", "src\FluentCassandra.csproj", "{EAA32600-3C2A-4B34-B9B2-5764F280FCE3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra.Sandbox", "test\FluentCassandra.Sandbox\FluentCassandra.Sandbox.csproj", "{DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}"
@@ -18,14 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{BF5D39
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{1A88B962-9A09-4692-80D3-E88712A9E516}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra.StressTest", "test\FluentCassandra.StressTest\FluentCassandra.StressTest.csproj", "{AC3818E2-E260-4193-A3D1-6E3FF87383F6}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra.Tests", "test\FluentCassandra.Tests\FluentCassandra.Tests.csproj", "{9DAF7022-5820-4214-B13E-AC0A1B37691F}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{AC1223D1-1638-4DEB-9CFF-8B0C43854BB0}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCassandra.LinqPad", "utility\FluentCassandra.LinqPad\FluentCassandra.LinqPad.csproj", "{CACA3463-BBEE-4C7E-AC89-49240B0D8F46}"
-EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = FluentCassandra.vsmdi
@@ -39,36 +33,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Debug|x86.ActiveCfg = Debug|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Any CPU.Build.0 = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|x86.ActiveCfg = Release|Any CPU
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Any CPU.ActiveCfg = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|x86.ActiveCfg = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|x86.Build.0 = Debug|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Any CPU.ActiveCfg = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|Mixed Platforms.Build.0 = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|x86.ActiveCfg = Release|x86
- {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Release|x86.Build.0 = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Any CPU.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.Build.0 = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Any CPU.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.Build.0 = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.Build.0 = Release|x86
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -79,27 +43,6 @@ Global
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9DAF7022-5820-4214-B13E-AC0A1B37691F}.Release|x86.ActiveCfg = Release|Any CPU
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Any CPU.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.ActiveCfg = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Debug|x86.Build.0 = Debug|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Any CPU.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|Mixed Platforms.Build.0 = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.ActiveCfg = Release|x86
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6}.Release|x86.Build.0 = Release|x86
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Debug|x86.ActiveCfg = Debug|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46}.Release|x86.ActiveCfg = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
{DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Any CPU.ActiveCfg = Debug|x86
{DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55}.Debug|Mixed Platforms.Build.0 = Debug|x86
@@ -121,40 +64,36 @@ Global
{EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EAA32600-3C2A-4B34-B9B2-5764F280FCE3}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
GlobalSection(NestedProjects) = preSolution
- {AC3818E2-E260-4193-A3D1-6E3FF87383F6} = {1A88B962-9A09-4692-80D3-E88712A9E516}
{9DAF7022-5820-4214-B13E-AC0A1B37691F} = {1A88B962-9A09-4692-80D3-E88712A9E516}
- {CACA3463-BBEE-4C7E-AC89-49240B0D8F46} = {AC1223D1-1638-4DEB-9CFF-8B0C43854BB0}
+ {DE6B46DE-C37A-49AF-8B9A-B9B6D4F03A55} = {1A88B962-9A09-4692-80D3-E88712A9E516}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = test\FluentCassandra.Sandbox\FluentCassandra.Sandbox.csproj
- Policies = $0
+ $0.CSharpFormattingPolicy = $3
+ $0.ChangeLogPolicy = $6
$0.DotNetNamingPolicy = $1
+ $0.StandardHeader = $4
+ $0.TextStylePolicy = $2
+ $0.VersionControlPolicy = $5
$1.DirectoryNamespaceAssociation = None
$1.ResourceNamePolicy = FileFormatDefault
- $0.TextStylePolicy = $2
$2.inheritsSet = null
$2.scope = text/x-csharp
- $0.CSharpFormattingPolicy = $3
- $3.inheritsSet = Mono
$3.inheritsScope = text/x-csharp
+ $3.inheritsSet = Mono
$3.scope = text/x-csharp
- $0.StandardHeader = $4
- $4.Text =
$4.IncludeInNewFiles = True
- $0.VersionControlPolicy = $5
+ $4.Text =
$5.inheritsSet = Mono
- $0.ChangeLogPolicy = $6
- $6.UpdateMode = None
$6.MessageStyle = $7
- $7.LineAlign = 0
+ $6.UpdateMode = None
$6.inheritsSet = Mono
+ $7.LineAlign = 0
+ Policies = $0
+ StartupItem = test\FluentCassandra.Sandbox\FluentCassandra.Sandbox.csproj
version = 1.0.0
EndGlobalSection
- GlobalSection(TestCaseManagementSettings) = postSolution
- CategoryFile = FluentCassandra.vsmdi
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
EndGlobal
View
17 src/CassandraColumnFamilySchema.cs
@@ -9,6 +9,7 @@ namespace FluentCassandra
public class CassandraColumnFamilySchema
{
public static readonly AsciiType DefaultKeyName = "KEY";
+ public static readonly CassandraType DefaultKeyNameType = CassandraType.AsciiType;
#if DEBUG
private CfDef _def;
@@ -25,8 +26,9 @@ public CassandraColumnFamilySchema(CfDef def)
var familyType = ColumnType.Standard;
Enum.TryParse<ColumnType>(def.Column_type, out familyType);
- var keyType = CassandraType.GetCassandraType(def.Key_validation_class);
+ var defaultKeyValueType = CassandraType.GetCassandraType(def.Key_validation_class);
var defaultColumnValueType = CassandraType.GetCassandraType(def.Default_validation_class);
+
CassandraType columnNameType, superColumnNameType;
if (familyType == ColumnType.Super)
@@ -44,8 +46,9 @@ public CassandraColumnFamilySchema(CfDef def)
FamilyName = def.Name;
FamilyDescription = def.Comment;
- KeyName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(def.Key_alias, CassandraType.BytesType);
- KeyType = keyType;
+ KeyName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(def.Key_alias, DefaultKeyNameType);
+ DefaultKeyValueType = defaultKeyValueType;
+
SuperColumnNameType = superColumnNameType;
ColumnNameType = columnNameType;
DefaultColumnValueType = defaultColumnValueType;
@@ -60,7 +63,8 @@ public CassandraColumnFamilySchema(string name = null, ColumnType type = ColumnT
FamilyDescription = null;
KeyName = DefaultKeyName;
- KeyType = CassandraType.BytesType;
+ DefaultKeyValueType = CassandraType.BytesType;
+
SuperColumnNameType = type == ColumnType.Super ? CassandraType.BytesType : null;
ColumnNameType = CassandraType.BytesType;
DefaultColumnValueType = CassandraType.BytesType;
@@ -75,7 +79,8 @@ public CassandraColumnFamilySchema(string name = null, ColumnType type = ColumnT
public string FamilyDescription { get; set; }
public CassandraObject KeyName { get; set; }
- public CassandraType KeyType { get; set; }
+ public CassandraType DefaultKeyValueType { get; set; }
+
public CassandraType SuperColumnNameType { get; set; }
public CassandraType ColumnNameType { get; set; }
public CassandraType DefaultColumnValueType { get; set; }
@@ -90,7 +95,7 @@ public CassandraColumnFamilySchema(string name = null, ColumnType type = ColumnT
Comment = schema.FamilyDescription,
Column_type = schema.FamilyType.ToString(),
Key_alias = schema.KeyName.ToBigEndian(),
- Key_validation_class = schema.KeyType.DatabaseType,
+ Key_validation_class = schema.DefaultKeyValueType.DatabaseType,
Comparator_type = schema.ColumnNameType.DatabaseType,
Default_validation_class = schema.DefaultColumnValueType.DatabaseType
};
View
2 src/CassandraColumnSchema.cs
@@ -19,6 +19,8 @@ public CassandraColumnSchema(ColumnDef def, CassandraType columnNameType)
ValueType = CassandraType.GetCassandraType(def.Validation_class);
}
+ public bool IsKey { get; set; }
+
private CassandraObject _name;
public CassandraObject Name
{
View
35 src/CassandraContext.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using Apache.Cassandra;
using FluentCassandra.Connections;
@@ -12,7 +13,6 @@ namespace FluentCassandra
public class CassandraContext : IDisposable
{
private readonly IList<IFluentMutationTracker> _trackers;
- private readonly IConnectionBuilder _connectionBuilder;
private CassandraSession _session;
/// <summary>
@@ -61,9 +61,9 @@ public CassandraContext(IConnectionBuilder connectionBuilder)
ThrowErrors = true;
_trackers = new List<IFluentMutationTracker>();
- _connectionBuilder = connectionBuilder;
+ ConnectionBuilder = connectionBuilder;
- Keyspace = new CassandraKeyspace(_connectionBuilder.Keyspace, this);
+ Keyspace = new CassandraKeyspace(ConnectionBuilder.Keyspace, this);
}
/// <summary>
@@ -120,6 +120,11 @@ public CassandraColumnFamily<CompareWith> GetColumnFamily<CompareWith>(string co
/// </summary>
public CassandraKeyspace Keyspace { get; set; }
+ /// <summary>
+ /// The connection builder that is currently in use for this context.
+ /// </summary>
+ public IConnectionBuilder ConnectionBuilder { get; private set; }
+
#region Cassandra System For Server
public string AddKeyspace(KsDef definition)
@@ -176,7 +181,12 @@ public string DropColumnFamily(string columnFamily)
public bool KeyspaceExists(string keyspaceName)
{
- return DescribeKeyspaces().Any(keyspace => keyspace.KeyspaceName == keyspaceName);
+ return DescribeKeyspaces().Any(keyspace => String.Equals(keyspace.KeyspaceName, keyspaceName, StringComparison.OrdinalIgnoreCase));
+ }
+
+ public bool ColumnFamilyExists(string columnFamily)
+ {
+ return Keyspace.ColumnFamilyExists(columnFamily);
}
public IEnumerable<CassandraKeyspace> DescribeKeyspaces()
@@ -285,6 +295,21 @@ public IEnumerable<ICqlRow> ExecuteQuery(UTF8Type cqlQuery)
///
/// </summary>
/// <param name="cqlQuery"></param>
+ public void TryExecuteNonQuery(UTF8Type cqlQuery) {
+ try
+ {
+ ExecuteNonQuery(cqlQuery);
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="cqlQuery"></param>
public void ExecuteNonQuery(UTF8Type cqlQuery)
{
var op = new ExecuteCqlNonQuery(cqlQuery);
@@ -316,7 +341,7 @@ public TResult ExecuteOperation<TResult>(Operation<TResult> action, bool? throwO
var localSession = _session == null;
var session = _session;
if (session == null)
- session = new CassandraSession(_connectionBuilder);
+ session = new CassandraSession(ConnectionBuilder);
action.Context = this;
View
75 src/CassandraCqlRowSchema.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Apache.Cassandra;
+using FluentCassandra.Types;
+
+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 sampleRow = result.Rows.FirstOrDefault();
+ 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>();
+ var keyColNames = new List<CassandraObject>();
+
+ 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);
+ }
+
+ // sample row to find key names
+ if (sampleRow != null)
+ keyColNames = sampleRow.Columns.Where(x => x.Ttl == -1).Select(x => CassandraObject.GetCassandraObjectFromDatabaseByteArray(x.Name, CassandraType.BytesType)).ToList();
+
+ // 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);
+ var isKey = keyColNames.Contains(name);
+
+ if (colNameTypes.ContainsKey(name))
+ nameType = colNameTypes[name];
+
+ var colSchema = new CassandraColumnSchema {
+ NameType = nameType,
+ Name = name,
+ ValueType = type,
+ IsKey = isKey
+ };
+
+ Columns.Add(colSchema);
+ }
+ }
+
+ public string FamilyName { get; set; }
+
+ public CassandraType DefaultColumnNameType { get; set; }
+ public CassandraType DefaultColumnValueType { get; set; }
+
+ public IList<CassandraColumnSchema> Columns { get; set; }
+ }
+}
View
5 src/CassandraKeyspace.cs
@@ -122,7 +122,7 @@ public CassandraColumnFamilySchema GetColumnFamilySchema(string columnFamily)
public bool ColumnFamilyExists(string columnFamilyName)
{
- return GetSchema().ColumnFamilies.Any(cf => cf.FamilyName == columnFamilyName);
+ return GetSchema().ColumnFamilies.Any(cf => String.Equals(cf.FamilyName, columnFamilyName, StringComparison.OrdinalIgnoreCase));
}
public void ClearCachedKeyspaceSchema()
@@ -141,8 +141,9 @@ public CassandraKeyspaceSchema GetSchema()
return ctx.Session.GetClient().describe_keyspace(KeyspaceName);
})));
}
- catch (CassandraOperationException)
+ catch (CassandraOperationException exc)
{
+ Debug.WriteLine(exc);
_cachedSchema = new CassandraKeyspaceSchema {
Name = KeyspaceName
};
View
8 src/CassandraKeyspaceSchema.cs
@@ -11,6 +11,10 @@ public class CassandraKeyspaceSchema
public const string ReplicaPlacementStrategyLocal = "org.apache.cassandra.locator.LocalStrategy";
public const string ReplicaPlacementStrategyNetworkTopology = "org.apache.cassandra.locator.NetworkTopologyStrategy";
+#if DEBUG
+ private KsDef _def;
+#endif
+
public CassandraKeyspaceSchema()
{
Strategy = ReplicaPlacementStrategySimple;
@@ -21,6 +25,10 @@ public CassandraKeyspaceSchema()
public CassandraKeyspaceSchema(KsDef def)
{
+#if DEBUG
+ _def = def;
+#endif
+
Name = def.Name;
Strategy = def.Strategy_class;
StrategyOptions = def.Strategy_options ?? new Dictionary<string, string>();
View
5 src/Connections/CqlVersion.cs
@@ -5,9 +5,8 @@ namespace FluentCassandra.Connections
{
public sealed class CqlVersion
{
- public const string Cql1 = "1.0.0.0";
- public const string Cql2 = "2.0.0.0";
- public const string Cql3 = "3.0.0.0";
+ public const string Cql2 = "2.0.0";
+ public const string Cql3 = "3.0.0";
public const string ServerDefault = null;
public const string Edge = Cql3;
View
4 src/FluentCassandra.csproj
@@ -122,6 +122,9 @@
<Compile Include="Connections\TimedLock.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="CassandraCqlRowSchema.cs" />
+ <Compile Include="FluentCqlRow.cs" />
+ <Compile Include="ObjectSerializer\ObjectSerializerConventions.cs" />
<Compile Include="System\DateTimePrecise.cs" />
<Compile Include="FluentCassandraException.cs" />
<Compile Include="FluentColumn.cs">
@@ -157,7 +160,6 @@
<Compile Include="Linq\CqlObjectQuery.cs" />
<Compile Include="Linq\ICassandraColumnFamilyInfo.cs" />
<Compile Include="ObjectSerializer\IObjectSerializer.cs" />
- <Compile Include="ObjectSerializer\ObjectSerializerConventions.cs" />
<Compile Include="Linq\CqlObjectQueryProvider.cs" />
<Compile Include="Linq\CqlQuery.cs" />
<Compile Include="Linq\CqlQueryEvaluator.cs" />
View
7 src/FluentColumnFamily.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using FluentCassandra.Types;
-using FluentCassandra.Linq;
namespace FluentCassandra
{
@@ -13,12 +12,12 @@ public class FluentColumnFamily<CompareWith> : FluentColumnFamily
public FluentColumnFamily(CassandraObject key, string columnFamily)
: base(key, columnFamily, new CassandraColumnFamilySchema {
FamilyName = columnFamily,
- KeyType = typeof(BytesType),
+ DefaultKeyValueType = typeof(BytesType),
ColumnNameType = typeof(CompareWith)
}) { }
}
- public class FluentColumnFamily : FluentRecord<FluentColumn>, IFluentBaseColumnFamily, IFluentRecordExpression, ICqlRow
+ public class FluentColumnFamily : FluentRecord<FluentColumn>, IFluentBaseColumnFamily, IFluentRecordExpression
{
private CassandraObject _key;
private FluentColumnList<FluentColumn> _columns;
@@ -61,7 +60,7 @@ internal FluentColumnFamily(CassandraObject key, string columnFamily, CassandraC
public CassandraObject Key
{
get { return _key; }
- set { _key = value.GetValue(GetSchema().KeyType); }
+ set { _key = value.GetValue(GetSchema().DefaultKeyValueType); }
}
/// <summary>
View
128 src/FluentCqlRow.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FluentCassandra.Linq;
+using FluentCassandra.Types;
+
+namespace FluentCassandra
+{
+ public class FluentCqlRow : FluentRecord<FluentColumn>, ICqlRow
+ {
+ private readonly IList<FluentColumn> _columns;
+ private CassandraCqlRowSchema _schema;
+
+ internal FluentCqlRow(CassandraObject key, string columnFamily, CassandraCqlRowSchema schema, IEnumerable<FluentColumn> columns)
+ {
+ SetSchema(schema);
+
+ Key = key;
+ FamilyName = columnFamily;
+
+ _columns = new List<FluentColumn>(columns);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public CassandraCqlRowSchema GetSchema()
+ {
+ return _schema;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="schema"></param>
+ public void SetSchema(CassandraCqlRowSchema schema)
+ {
+ _schema = schema;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="result"></param>
+ /// <returns></returns>
+ private CassandraObject GetColumnValue(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col == null)
+ return NullType.Value;
+
+ var schema = GetColumnSchema(name);
+ return col.ColumnValue.GetValue(schema.ValueType);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ private CassandraColumnSchema GetColumnSchema(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col != null)
+ return col.GetSchema();
+
+ var schema = GetSchema();
+ var colSchema = schema.Columns.FirstOrDefault(c => c.Name == name);
+
+ if (colSchema != null)
+ return colSchema;
+
+ return new CassandraColumnSchema { NameType = schema.DefaultColumnNameType, ValueType = typeof(BytesType) };
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="result"></param>
+ /// <returns></returns>
+ public override bool TryGetColumn(object name, out object result)
+ {
+ result = GetColumnValue(name);
+
+ return true;
+ }
+
+ public override bool TrySetColumn(object name, object value)
+ {
+ throw new NotSupportedException();
+ }
+
+ public string FamilyName
+ {
+ get;
+ private set;
+ }
+
+ public CassandraObject Key
+ {
+ get;
+ private set;
+ }
+
+ public override IList<FluentColumn> Columns
+ {
+ get { return _columns; }
+ }
+
+ public CassandraObject this[CassandraObject columnName]
+ {
+ get
+ {
+ var value = GetColumnValue(columnName);
+
+ if (value is NullType)
+ throw new CassandraException(String.Format("Column, {0}, could not be found.", columnName));
+
+ return value;
+ }
+ }
+ }
+}
View
4 src/FluentSuperColumnFamily.cs
@@ -13,7 +13,7 @@ public class FluentSuperColumnFamily<CompareWith, CompareSubcolumnWith> : Fluent
public FluentSuperColumnFamily(CassandraObject key, string columnFamily)
: base(key, columnFamily, new CassandraColumnFamilySchema {
FamilyName = columnFamily,
- KeyType = typeof(BytesType),
+ DefaultKeyValueType = typeof(BytesType),
SuperColumnNameType = typeof(CompareWith),
ColumnNameType = typeof(CompareSubcolumnWith)
}) { }
@@ -63,7 +63,7 @@ internal FluentSuperColumnFamily(CassandraObject key, string columnFamily, Cassa
public CassandraObject Key
{
get { return _key; }
- set { _key = value.GetValue(GetSchema().KeyType); }
+ set { _key = value.GetValue(GetSchema().DefaultKeyValueType); }
}
/// <summary>
View
5 src/Linq/CqlQueryEvaluator.cs
@@ -158,12 +158,7 @@ private string GetPropertyName(Expression exp)
// if object queries
if (GetBaseType(memExp) != typeof(ICqlRow))
- {
- if (_conventions.KeyPropertyNames.Contains(name, _conventions.AreKeyPropertyNamesCaseSensitive ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal))
- name = "KEY";
-
return name;
- }
if (name != "Key")
throw new NotSupportedException(name + " is not a supported property.");
View
2 src/Linq/ICqlRow.cs
@@ -8,7 +8,7 @@ namespace FluentCassandra.Linq
{
public interface ICqlRow : IDynamicMetaObjectProvider
{
- CassandraObject Key { get; set; }
+ CassandraObject Key { get; }
CassandraObject this[CassandraObject columnName] { get; }
IList<FluentColumn> Columns { get; }
View
8 src/ObjectSerializer/ObjectSerializerConventions.cs
@@ -6,13 +6,5 @@ namespace FluentCassandra.ObjectSerializer
{
public class ObjectSerializerConventions
{
- public ObjectSerializerConventions()
- {
- AreKeyPropertyNamesCaseSensitive = false;
- KeyPropertyNames = new List<string>(new[] { "Key", "Id" });
- }
-
- public bool AreKeyPropertyNamesCaseSensitive { get; set; }
- public List<string> KeyPropertyNames { get; set; }
}
}
View
10 src/ObjectSerializer/ReflectionObjectSerializer.cs
@@ -31,11 +31,6 @@ private object AnonymousRowDeserializer(ICqlRow row, ObjectSerializerConventions
foreach (var prop in props)
{
var name = prop.Name;
- if (conventions.KeyPropertyNames.Contains(name, conventions.AreKeyPropertyNamesCaseSensitive ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal))
- {
- args.Add(Convert.ChangeType(row.Key, prop.PropertyType));
- continue;
- }
if (row.Columns.Any(x => x.ColumnName == name))
args.Add(Convert.ChangeType(row[name], prop.PropertyType));
@@ -57,11 +52,6 @@ private object RowDeserializer(ICqlRow row, ObjectSerializerConventions conventi
foreach (var prop in _type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
var name = prop.Name;
- if (conventions.KeyPropertyNames.Contains(name, conventions.AreKeyPropertyNamesCaseSensitive ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal))
- {
- prop.SetValue(obj, Convert.ChangeType(row.Key, prop.PropertyType), null);
- continue;
- }
if (row.Columns.Any(x => x.ColumnName == name))
prop.SetValue(obj, Convert.ChangeType(row[name], prop.PropertyType), null);
View
48 src/Operations/ExecuteCqlQuery.cs
@@ -14,39 +14,6 @@ public class ExecuteCqlQuery : ColumnFamilyOperation<IEnumerable<ICqlRow>>
public UTF8Type CqlQuery { get; private set; }
- private CassandraColumnFamilySchema TryGetSchema(Apache.Cassandra.CqlResult result, string familyName)
- {
- //if (ColumnFamily != null && ColumnFamily.FamilyName != null)
- // return ColumnFamily.Schema();
-
- var keyName = CassandraColumnFamilySchema.DefaultKeyName.ToBigEndian();
- var resultSchema = result.Schema;
- var colNameType = CassandraType.GetCassandraType(resultSchema.Default_name_type);
- var colValueType = CassandraType.GetCassandraType(resultSchema.Default_value_type);
-
- var schema = new CassandraColumnFamilySchema();
- schema.FamilyName = familyName;
- schema.ColumnNameType = colNameType;
- schema.DefaultColumnValueType = colValueType;
-
- foreach (var s in resultSchema.Value_types)
- {
- var key = s.Key;
- if (key.Length == 3 && key[0] == keyName[0] && key[1] == keyName[1] && key[2] == keyName[2])
- {
- schema.KeyType = CassandraType.GetCassandraType(s.Value);
- continue;
- }
-
- schema.Columns.Add(new CassandraColumnSchema {
- Name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(s.Key, colNameType),
- ValueType = CassandraType.GetCassandraType(s.Value)
- });
- }
-
- return schema;
- }
-
private string TryGetFamilyName()
{
if (ColumnFamily != null && ColumnFamily.FamilyName != null)
@@ -82,25 +49,24 @@ public override IEnumerable<ICqlRow> Execute()
private IEnumerable<ICqlRow> GetRows(Apache.Cassandra.CqlResult result)
{
var familyName = TryGetFamilyName();
- var schema = TryGetSchema(result, familyName);
+ var schema = new CassandraCqlRowSchema(result, familyName);
foreach (var row in result.Rows)
- yield return new FluentColumnFamily(
- CassandraObject.GetCassandraObjectFromDatabaseByteArray(row.Key, schema.KeyType),
+ yield return new FluentCqlRow(
+ CassandraObject.GetCassandraObjectFromDatabaseByteArray(row.Key, CassandraType.BytesType),
familyName,
schema,
GetColumns(row, schema));
}
- private IEnumerable<FluentColumn> GetColumns(Apache.Cassandra.CqlRow row, CassandraColumnFamilySchema schema)
+ private IEnumerable<FluentColumn> GetColumns(Apache.Cassandra.CqlRow row, CassandraCqlRowSchema schema)
{
foreach (var col in row.Columns)
{
- // it's a key and it has already been taken care of
- if (col.Timestamp == -1)
- continue;
+ var name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, CassandraType.BytesType);
+ var colSchema = schema.Columns.Where(x => x.Name == name).FirstOrDefault();
- var fcol = Helper.ConvertColumnToFluentColumn(col, schema);
+ var fcol = Helper.ConvertColumnToFluentColumn(col, colSchema);
yield return fcol;
}
}
View
7 src/Operations/Helper.cs
@@ -228,6 +228,13 @@ public static FluentColumn ConvertColumnToFluentColumn(Column col, CassandraColu
}
}
+ return ConvertColumnToFluentColumn(col, colSchema);
+ }
+
+ public static FluentColumn ConvertColumnToFluentColumn(Column col, CassandraColumnSchema colSchema)
+ {
+ colSchema = colSchema ?? new CassandraColumnSchema();
+
var fcol = new FluentColumn(colSchema) {
ColumnName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, colSchema.NameType),
ColumnValue = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Value, colSchema.ValueType),
View
2 src/Operations/MultiGetColumnFamilySlice.cs
@@ -32,7 +32,7 @@ public override IEnumerable<FluentColumnFamily> Execute()
foreach (var result in output)
{
- var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyType);
+ var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.DefaultKeyValueType);
var r = new FluentColumnFamily(key, ColumnFamily.FamilyName, schema, result.Value.Select(col => {
return Helper.ConvertColumnToFluentColumn(col.Column, schema);
View
2 src/Operations/MultiGetSuperColumnFamilySlice.cs
@@ -33,7 +33,7 @@ public override IEnumerable<FluentSuperColumnFamily> Execute()
foreach (var result in output)
{
- var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyType);
+ var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.DefaultKeyValueType);
var superColumns = (IEnumerable<FluentSuperColumn>)null;
View
4 test/FluentCassandra.Sandbox/Program.cs
@@ -38,7 +38,7 @@ PostedOn timestamp
// create column family using API
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "Tags",
- KeyType = CassandraType.AsciiType,
+ DefaultKeyValueType = CassandraType.AsciiType,
ColumnNameType = CassandraType.Int32Type,
DefaultColumnValueType = CassandraType.UTF8Type
});
@@ -47,7 +47,7 @@ PostedOn timestamp
keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
FamilyName = "Comments",
FamilyType = ColumnType.Super,
- KeyType = CassandraType.AsciiType,
+ DefaultKeyValueType = CassandraType.AsciiType,
SuperColumnNameType = CassandraType.DateType,
ColumnNameType = CassandraType.UTF8Type,
DefaultColumnValueType = CassandraType.UTF8Type
View
93 test/FluentCassandra.Tests/Bugs/Issue36KeyAliasSupport.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Linq;
+using FluentCassandra.Connections;
+using Xunit;
+
+namespace FluentCassandra.Bugs
+{
+ public class Issue36KeyAliasSupport: IUseFixture<CassandraDatabaseSetupFixture>, IDisposable
+ {
+ private CassandraContext _db;
+
+ public void SetFixture(CassandraDatabaseSetupFixture data)
+ {
+ var setup = data.DatabaseSetup(false);
+ _db = setup.DB;
+ }
+
+ public void Dispose()
+ {
+ _db.Dispose();
+ }
+
+ [Fact]
+ public void Test_Cql2()
+ {
+ var connBuilder = _db.ConnectionBuilder;
+ connBuilder = new ConnectionBuilder(connBuilder.Keyspace, connBuilder.Servers[0], cqlVersion: CqlVersion.Cql2);
+ var db = new CassandraContext(connBuilder);
+
+ // arrange
+ db.TryExecuteNonQuery("DROP COLUMNFAMILY Users_Issue36");
+
+ db.ExecuteNonQuery(@"
+CREATE COLUMNFAMILY Users_Issue36 (
+ UserName text PRIMARY KEY,
+ LastLogin timestamp);");
+
+ db.ExecuteNonQuery(@"
+BEGIN BATCH
+ INSERT INTO Users_Issue36 (UserName, LastLogin) VALUES ('nberardi', '2012-6-6T04:30:00')
+ INSERT INTO Users_Issue36 (UserName, LastLogin) VALUES ('jdoe', '2012-10-31T00:30:02')
+ INSERT INTO Users_Issue36 (UserName, LastLogin) VALUES ('akim', '2003-6-6T05:35:23')
+ INSERT INTO Users_Issue36 (UserName, LastLogin) VALUES ('jboes', '2001-1-1T13:02:10')
+APPLY BATCH;
+");
+
+ // act
+ var actual = db.ExecuteQuery("SELECT * FROM Users_Issue36");
+
+ // assert
+ var results = actual.ToList();
+ Assert.Equal(4, results.Count);
+ }
+
+ [Fact]
+ public void Test_Cql3()
+ {
+ var connBuilder = _db.ConnectionBuilder;
+ connBuilder = new ConnectionBuilder(connBuilder.Keyspace, connBuilder.Servers[0], cqlVersion: CqlVersion.Cql3);
+ var db = new CassandraContext(connBuilder);
+
+ // arrange
+ db.TryExecuteNonQuery("DROP TABLE Timeline_Issue36");
+
+ db.ExecuteNonQuery(@"
+CREATE TABLE Timeline_Issue36 (
+ user_id varchar,
+ tweet_id int,
+ author text,
+ body varchar,
+ PRIMARY KEY (user_id, tweet_id));");
+
+ db.ExecuteNonQuery(@"
+BEGIN BATCH
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('nberardi', 1, 'nberardi', 'test 1234')
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('nberardi', 2, 'nberardi', 'test 4567')
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('nberardi', 3, 'nberardi', 'test 8910')
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('jdoe', 1, 'nberardi', 'test 1111')
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('akim', 1, 'nberardi', 'test 2222')
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('jboes', 1, 'nberardi', 'test 3333')
+ INSERT INTO Timeline_Issue36 (user_id, tweet_id, author, body) VALUES ('jboes', 2, 'nberardi', 'test 4444')
+APPLY BATCH;
+");
+
+ // act
+ var actual = db.ExecuteQuery("SELECT * FROM Timeline_Issue36");
+
+ // assert
+ var results = actual.ToList();
+ Assert.Equal(7, results.Count);
+ }
+ }
+}
View
5 test/FluentCassandra.Tests/FluentCassandra.Tests.csproj
@@ -52,6 +52,7 @@
<Compile Include="BigDecimalTest.cs" />
<Compile Include="Bugs\Issue28GuidGeneratorInParallelContext.cs" />
<Compile Include="Bugs\Issue25JavaBigDecimalBinaryConversion.cs" />
+ <Compile Include="Bugs\Issue36KeyAliasSupport.cs" />
<Compile Include="CassandraDatabaseSetupFixture.cs" />
<Compile Include="CassandraQueryTest.cs" />
<Compile Include="Connections\ConnectionProviderTests.cs" />
@@ -108,7 +109,9 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <Folder Include="Cql\" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 comments on commit ff16fb5

Please sign in to comment.
Something went wrong with that request. Please try again.