public static CassandraSlicePredicate SetSchemaForSlicePredicate(CassandraSlicePredicate predicate, CassandraColumnFamilySchema schema, bool forSuperColumn = false) { CassandraType columnType = forSuperColumn ? schema.SuperColumnNameType : schema.ColumnNameType; if (predicate is CassandraRangeSlicePredicate) { var x = (CassandraRangeSlicePredicate)predicate; var start = CassandraObject.GetCassandraObjectFromObject(x.Start, columnType); var finish = CassandraObject.GetCassandraObjectFromObject(x.Finish, columnType); return(new CassandraRangeSlicePredicate(start, finish, x.Reversed, x.Count)); } else if (predicate is CassandraColumnSlicePredicate) { var x = (CassandraColumnSlicePredicate)predicate; var cols = x.Columns.ToList(); for (int i = 0; i < cols.Count; i++) { cols[i] = CassandraObject.GetCassandraObjectFromObject(cols[i], columnType); } return(new CassandraColumnSlicePredicate(cols)); } return(null); }
private static Cassandra.IndexExpression VisitRelationalExpression(BinaryExpression exp) { Cassandra.IndexExpression indexExpression; var columnName = GetColumnName(exp.Left); var value = CassandraType.GetType <BytesType>(Expression.Lambda(exp.Right).Compile().DynamicInvoke()); indexExpression = new Cassandra.IndexExpression { Column_name = columnName, Value = value }; switch (exp.NodeType) { case ExpressionType.Equal: indexExpression.Op = Cassandra.IndexOperator.EQ; break; case ExpressionType.GreaterThan: indexExpression.Op = Cassandra.IndexOperator.GT; break; case ExpressionType.GreaterThanOrEqual: indexExpression.Op = Cassandra.IndexOperator.GTE; break; case ExpressionType.LessThan: indexExpression.Op = Cassandra.IndexOperator.LT; break; case ExpressionType.LessThanOrEqual: indexExpression.Op = Cassandra.IndexOperator.LTE; break; default: throw new NotSupportedException(exp.NodeType.ToString() + " is not a supported relational criteria."); } return(indexExpression); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> public override bool TrySetColumn(object name, object value) { var col = Columns.FirstOrDefault(c => c.ColumnName == name); var mutationType = MutationType.Changed; // if column doesn't exisit create it and add it to the columns if (col == null) { mutationType = MutationType.Added; col = new FluentColumn <CompareWith>(); ((FluentColumn <CompareWith>)col).ColumnName = CassandraType.GetType <CompareWith>(name); _columns.SupressChangeNotification = true; _columns.Add(col); _columns.SupressChangeNotification = false; } // set the column value col.ColumnValue = CassandraType.GetType <BytesType>(value); // notify the tracker that the column has changed OnColumnMutated(mutationType, col); return(true); }
public RangeSlicePredicate(CassandraType start, CassandraType finish, bool reversed = false, int count = 100) { Start = start; Finish = finish; Reversed = reversed; Count = count; }
public void Test_Composite3() { // arrange var keyspace = _db.Keyspace; // create column family using API _db.TryDropColumnFamily("Data"); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "Data", KeyValueType = CassandraType.CompositeType(CassandraType.AsciiType, CassandraType.AsciiType, CassandraType.TimeUUIDType), ColumnNameType = CassandraType.AsciiType, DefaultColumnValueType = CassandraType.BytesType }); var stamp = new DateTimeOffset(2012, 6, 22, 4, 41, 00, TimeSpan.Zero); InsertData3("TT", "A", stamp, new Dictionary <string, string> { { "Status", "Working" } }); // act var actual = GetData3("TT", "A", stamp, "Status"); // assert Assert.NotNull(actual); Assert.Equal(1, actual.Columns.Count); }
public void ResetDatabase() { using (var session = new CassandraSession(ConnectionBuilder)) using (var db = new CassandraContext(session)) { db.ThrowErrors = true; db.TryDropKeyspace(Keyspace); var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema { Name = Keyspace }, db); db.Keyspace = keyspace; keyspace.TryCreateSelf(); keyspace.TryCreateColumnFamily <AsciiType>("Standard"); keyspace.TryCreateColumnFamily <AsciiType, AsciiType>("Super"); keyspace.TryCreateColumnFamily <AsciiType>("StandardAsciiType"); keyspace.TryCreateColumnFamily <BytesType>("StandardBytesType"); keyspace.TryCreateColumnFamily <IntegerType>("StandardIntegerType"); keyspace.TryCreateColumnFamily <LexicalUUIDType>("StandardLexicalUUIDType"); keyspace.TryCreateColumnFamily <LongType>("StandardLongType"); keyspace.TryCreateColumnFamily <TimeUUIDType>("StandardTimeUUIDType"); keyspace.TryCreateColumnFamily <UTF8Type>("StandardUTF8Type"); keyspace.TryCreateColumnFamily <UUIDType>("StandardUUIDType"); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "StandardCompositeType", ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType }) }); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "StandardDynamicCompositeType", ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary <char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } }) }); db.ExecuteNonQuery(string.Format(@" CREATE TABLE {0} ( id int , name ascii, email ascii, age int, PRIMARY KEY(id) );", toLowerIf(toLower, "Users"))); //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(toLowerIf(toLower, "Users")); ResetFamily(family); ResetSuperFamily(superFamily); ResetUsersFamily(userFamily); } }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryGetColumn(object name, out object result) { var col = Columns.FirstOrDefault(c => c.ColumnName == name); result = (col == null) ? CreateSuperColumn(CassandraType.GetType <CompareWith>(name)) : col; return(true); }
public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTimeOffset timestamp, int timeToLive) { Key = key; ColumnName = name; ColumnValue = value; Timestamp = timestamp; TimeToLive = timeToLive; }
public static FluentColumn <CompareWith> ConvertColumnToFluentColumn <CompareWith>(Column col) where CompareWith : CassandraType { return(new FluentColumn <CompareWith> { ColumnName = CassandraType.GetType <CompareWith>(col.Name), ColumnValue = col.Value, ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero), ColumnTimeToLive = col.Ttl }); }
private static CassandraSlicePredicate BuildPredicateFromExpression(IDictionary <string, object> calls) { object fetch, take, takeUntil; if (!calls.TryGetValue("Fetch", out fetch)) { fetch = new CassandraType[0]; } var columns = (CassandraType[])fetch; RangeSlicePredicate predicate; if (columns.Length > 1) { if (calls.Count > 1) { throw new CassandraException("A multi column fetch cannot be used with the following query options: " + String.Join(", ", calls.Keys.Where(x => x != "Fetch"))); } return(new ColumnSlicePredicate(columns)); } else if (columns.Length == 1) { if (calls.Count == 1) { return(new ColumnSlicePredicate(columns)); } predicate = new RangeSlicePredicate(columns[0], null); } else { predicate = new RangeSlicePredicate(null, null); } if (calls.TryGetValue("Take", out take)) { int count = (int)take; predicate.Count = count; } if (calls.TryGetValue("TakeUntil", out takeUntil)) { CassandraType column = (CassandraType)takeUntil; predicate.Finish = column; } if (calls.ContainsKey("Reverse")) { predicate.Reversed = true; } return(predicate); }
public void CassandraType_Cast() { // arranage string expected = "The quick brown fox jumps over the lazy dog."; UTF8Type actualType = expected; // act CassandraType actual = actualType; // assert Assert.AreEqual(expected, (string)actual); }
public void CassandraType_Cast() { // arranage Guid expected = guid; LexicalUUIDType actualType = expected; // act CassandraType actual = actualType; // assert Assert.AreEqual(expected, (Guid)actual); }
public void CassandraType_Cast() { // arranage BigInteger expected = 100; IntegerType actualType = expected; // act CassandraType actual = actualType; // assert Assert.AreEqual(expected, (BigInteger)actual); }
public void CassandraType_Cast() { // arranage long expected = 100L; IntegerType actualType = expected; // act CassandraType actual = actualType; // assert Assert.AreEqual(expected, (long)actual); }
public void CassandraType_Cast() { // arranage byte[] expected = new byte[] { 0, 32, 0, 16, 0, 0, 64, 128 }; BytesType actualType = expected; // act CassandraType actualCassandraType = actualType; byte[] actual = actualCassandraType; // assert Assert.IsTrue(expected.SequenceEqual(actual)); }
public static FluentSuperColumn <CompareWith, CompareSubcolumnWith> ConvertSuperColumnToFluentSuperColumn <CompareWith, CompareSubcolumnWith>(SuperColumn col) where CompareWith : CassandraType where CompareSubcolumnWith : CassandraType { var superCol = new FluentSuperColumn <CompareWith, CompareSubcolumnWith> { ColumnName = CassandraType.GetType <CompareWith>(col.Name) }; foreach (var xcol in col.Columns) { superCol.Columns.Add(ConvertColumnToFluentColumn <CompareSubcolumnWith>(xcol)); } return(superCol); }
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 CassandraColumnFamilySchema(CfDef def) { _def = def; KeyspaceName = def.Keyspace; var familyType = ColumnType.Standard; Enum.TryParse <ColumnType>(def.Column_type, out familyType); var defaultKeyValueType = CassandraType.GetCassandraType(def.Key_validation_class); var defaultColumnValueType = CassandraType.GetCassandraType(def.Default_validation_class); CassandraType columnNameType, superColumnNameType; if (familyType == ColumnType.Super) { superColumnNameType = CassandraType.GetCassandraType(def.Comparator_type); columnNameType = CassandraType.GetCassandraType(def.Subcomparator_type); } else { superColumnNameType = null; columnNameType = CassandraType.GetCassandraType(def.Comparator_type); } FamilyType = familyType; FamilyName = def.Name; FamilyDescription = def.Comment; KeyName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(def.Key_alias, DefaultKeyNameType); KeyValueType = defaultKeyValueType; SuperColumnNameType = superColumnNameType; ColumnNameType = columnNameType; DefaultColumnValueType = defaultColumnValueType; Columns = def.Column_metadata.Select(col => new CassandraColumnSchema(col, columnNameType)).ToList(); }
public GetSuperColumnRangeSlices(CassandraKeyRange keyRange, CassandraType superColumnName, CassandraSlicePredicate columnSlicePredicate) { KeyRange = keyRange; SuperColumnName = superColumnName; SlicePredicate = columnSlicePredicate; }
public void ResetDatabase() { using (var session = new CassandraSession(ConnectionBuilder)) using (var db = new CassandraContext(session)) { db.ThrowErrors = true; db.TryDropKeyspace(Keyspace); var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema { Name = Keyspace }, db); db.Keyspace = keyspace; keyspace.TryCreateSelf(); keyspace.TryCreateColumnFamily <AsciiType>("Standard"); keyspace.TryCreateColumnFamily <AsciiType, AsciiType>("Super"); keyspace.TryCreateColumnFamily <AsciiType>("StandardAsciiType"); keyspace.TryCreateColumnFamily <BytesType>("StandardBytesType"); keyspace.TryCreateColumnFamily <IntegerType>("StandardIntegerType"); keyspace.TryCreateColumnFamily <LexicalUUIDType>("StandardLexicalUUIDType"); keyspace.TryCreateColumnFamily <LongType>("StandardLongType"); 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(type: ColumnType.Super) { FamilyName = "SuperCounters", SuperColumnNameType = CassandraType.AsciiType, ColumnNameType = CassandraType.AsciiType, DefaultColumnValueType = CassandraType.CounterColumnType }); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "StandardDecimalType", ColumnNameType = CassandraType.DecimalType }); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "StandardCompositeType", ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType }) }); keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema { FamilyName = "StandardDynamicCompositeType", ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary <char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } }) }); 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 COLUMNFAMILY Cql3List ( Id int PRIMARY KEY, TagList list<text> --list of strings );"); db.ExecuteNonQuery(@" CREATE COLUMNFAMILY Cql3Set ( Id int PRIMARY KEY, TagSet set<uuid> --set of Guids );"); db.ExecuteNonQuery(@" CREATE COLUMNFAMILY Cql3Map ( Id int PRIMARY KEY, TagMap map<bigint,uuid> --map of long integers and Guids );"); db.Keyspace.ClearCachedKeyspaceSchema(); var family = db.GetColumnFamily <AsciiType>("Standard"); var superFamily = db.GetColumnFamily <AsciiType, AsciiType>("Super"); var userFamily = db.GetColumnFamily("Users"); var counterFamily = db.GetColumnFamily("Counters"); ResetFamily(family); ResetSuperFamily(superFamily); ResetUsersFamily(userFamily); ResetCounterColumnFamily(counterFamily); } }
public static IMarshaller GetMarshallerForCassandraType(CassandraType type) { return TypeDescriptions.Where(td => td.Type == type).First().Marshaller; }
public GetColumn(BytesType key, CassandraType superColumnName, CassandraType columnName) { Key = key; SuperColumnName = superColumnName; ColumnName = columnName; }
public GetColumn(BytesType key, CassandraType columnName) { Key = key; ColumnName = columnName; }
public MultiGetSuperColumnSlice(IEnumerable <BytesType> keys, CassandraType superColumnName, CassandraSlicePredicate columnSlicePredicate) { Keys = keys.ToList(); SuperColumnName = superColumnName; SlicePredicate = columnSlicePredicate; }
public CassandraColumnSchema(ColumnDef def, CassandraType columnNameType) { NameType = columnNameType; Name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(def.Name, columnNameType); ValueType = CassandraType.GetCassandraType(def.Validation_class); }
public GetSuperColumnSlice(BytesType key, CassandraType superColumnName, CassandraSlicePredicate columnSlicePredicate) { Key = key; SuperColumnName = superColumnName; SlicePredicate = columnSlicePredicate; }
public RemoveSuperColumn(BytesType key, CassandraType superColumnName) { Key = key; SuperColumnName = superColumnName; }
/// <summary> /// /// </summary> /// <param name="binder"></param> /// <param name="value"></param> /// <returns></returns> public override bool TrySetColumn(object name, object value) { if (!(value is FluentSuperColumn <CompareWith, CompareSubcolumnWith>)) { throw new ArgumentException("Value must be of type " + typeof(FluentSuperColumn <CompareWith, CompareSubcolumnWith>) + ", because this column family is of type Super.", "value"); } var col = Columns.FirstOrDefault(c => c.ColumnName == name); var mutationType = col == null ? MutationType.Added : MutationType.Changed; col = (FluentSuperColumn <CompareWith, CompareSubcolumnWith>)value; ((FluentSuperColumn <CompareWith, CompareSubcolumnWith>)col).ColumnName = CassandraType.GetType <CompareWith>(name); int index = Columns.IndexOf(col); _columns.SupressChangeNotification = true; if (index < 0) { Columns.Add(col); } else { Columns.Insert(index, col); } _columns.SupressChangeNotification = false; // notify the tracker that the column has changed OnColumnMutated(mutationType, col); return(true); }
public GetSuperColumnIndexedSlices(CassandraIndexClause indexClause, CassandraType superColumnName, CassandraSlicePredicate columnSlicePredicate) { IndexClause = indexClause; SuperColumnName = superColumnName; SlicePredicate = columnSlicePredicate; }