Permalink
Browse files

supporting key aliases in CQL

  • Loading branch information...
1 parent e688282 commit ff16fb5196cf5547ce4d9e75c52cffb2ab812e6b @nberardi nberardi committed Jun 6, 2012
View
@@ -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
@@ -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
};
@@ -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
@@ -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()
@@ -281,6 +291,21 @@ public IEnumerable<ICqlRow> ExecuteQuery(UTF8Type cqlQuery)
return ExecuteOperation(op);
}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="cqlQuery"></param>
+ public void TryExecuteNonQuery(UTF8Type cqlQuery) {
+ try
+ {
+ ExecuteNonQuery(cqlQuery);
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ }
+ }
+
/// <summary>
///
/// </summary>
@@ -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;
@@ -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
@@ -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
};
Oops, something went wrong.

0 comments on commit ff16fb5

Please sign in to comment.