예제 #1
0
        public void TwoExpressions()
        {
            // arrange
            string key          = "test";
            int    count        = 20;
            var    columnName1  = "test1-column";
            var    columnValue1 = "test1-value";
            var    columnName2  = "test2-column";
            var    columnValue2 = Math.PI;

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName1] == columnValue1 &&
                family[columnName2] > columnValue2);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.Equal(2, expressions.Count);

            var firstExpression = expressions[0];

            Assert.NotNull(firstExpression);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName1);
            Assert.Equal(firstExpression.Op, IndexOperator.EQ);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue1);

            var secondExpression = expressions[1];

            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(secondExpression.Column_name, typeof(BytesType)), (BytesType)columnName2);
            Assert.Equal(secondExpression.Op, IndexOperator.GT);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(secondExpression.Value, typeof(BytesType)), (BytesType)columnValue2);
        }
        public override IEnumerable <FluentColumnFamily> Execute()
        {
            var schema = ColumnFamily.GetSchema();
            var list   = new List <FluentColumnFamily>();

            var parent = new CassandraColumnParent
            {
                ColumnFamily = ColumnFamily.FamilyName
            };

            SlicePredicate = Helper.SetSchemaForSlicePredicate(SlicePredicate, schema);

            var output = Session.GetClient().get_indexed_slices(
                parent,
                IndexClause,
                SlicePredicate,
                Session.ReadConsistency
                );

            foreach (var result in output)
            {
                var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyValueType);

                var r = new FluentColumnFamily(key, ColumnFamily.FamilyName, schema, result.Columns.Select(col =>
                {
                    return(Helper.ConvertColumnToFluentColumn(col.Column, schema));
                }));
                ColumnFamily.Context.Attach(r);
                r.MutationTracker.Clear();

                list.Add(r);
            }

            return(list);
        }
예제 #3
0
        public void SingleExpression()
        {
            // arrange
            string key         = "test";
            int    count       = 20;
            var    columnName  = "test-column";
            var    columnValue = "test-value";

            // act
            var index = new CassandraIndexClause(
                key,
                count,
                family => family[columnName] == columnValue);
            var expressions = index.CompiledExpressions;

            // assert
            Assert.Equal(1, expressions.Count);

            var firstExpression = expressions[0];

            Assert.NotNull(firstExpression);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Column_name, typeof(BytesType)), (BytesType)columnName);
            Assert.Equal(firstExpression.Op, IndexOperator.EQ);
            Assert.Equal(CassandraObject.GetCassandraObjectFromDatabaseByteArray(firstExpression.Value, typeof(BytesType)), (BytesType)columnValue);
        }
예제 #4
0
        public static FluentSuperColumn ConvertSuperColumnToFluentSuperColumn(SuperColumn col, CassandraColumnFamilySchema schema)
        {
            var superColSchema = new CassandraColumnSchema {
                Name = col.Name
            };

            if (schema != null)
            {
                superColSchema = new CassandraColumnSchema {
                    NameType  = schema.SuperColumnNameType,
                    Name      = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, schema.SuperColumnNameType),
                    ValueType = schema.ColumnNameType
                }
            }
            ;

            var superCol = new FluentSuperColumn(superColSchema)
            {
                ColumnName = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, superColSchema.NameType)
            };

            ((ILoadable)superCol).BeginLoad();
            foreach (var xcol in col.Columns)
            {
                superCol.Columns.Add(ConvertColumnToFluentColumn(xcol, schema));
            }
            ((ILoadable)superCol).EndLoad();

            return(superCol);
        }
예제 #5
0
        public static FluentCounterColumn ConvertColumnToFluentCounterColumn(CounterColumn col, CassandraColumnFamilySchema schema)
        {
            var colSchema = new CassandraColumnSchema();

            if (schema != null)
            {
                var name = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, schema.ColumnNameType);
                colSchema = schema.Columns.Where(x => x.Name == name).FirstOrDefault();

                if (colSchema == null)
                {
                    colSchema           = new CassandraColumnSchema();
                    colSchema.NameType  = schema.ColumnNameType;
                    colSchema.Name      = name;
                    colSchema.ValueType = schema.DefaultColumnValueType;
                }
            }

            var fcol = new FluentCounterColumn(colSchema)
            {
                ColumnName  = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, colSchema.NameType),
                ColumnValue = col.Value
            };

            return(fcol);
        }
예제 #6
0
        private IEnumerable <FluentColumnFamily> GetFamilies(BaseCassandraColumnFamily columnFamily)
        {
            var schema = ColumnFamily.GetSchema();

            var parent = new CassandraColumnParent {
                ColumnFamily = columnFamily.FamilyName
            };

            SlicePredicate = Helper.SetSchemaForSlicePredicate(SlicePredicate, schema);

            var output = Session.GetClient().get_range_slices(
                parent,
                SlicePredicate,
                KeyRange,
                Session.ReadConsistency
                );

            foreach (var result in output)
            {
                var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyValueType);

                var r = new FluentColumnFamily(key, columnFamily.FamilyName, columnFamily.GetSchema(), result.Columns.Select(col => {
                    return(Helper.ConvertColumnToFluentColumn(col.Column, schema));
                }));
                columnFamily.Context.Attach(r);
                r.MutationTracker.Clear();

                yield return(r);
            }
        }
        public override IEnumerable <FluentSuperColumnFamily> Execute()
        {
            var schema = ColumnFamily.GetSchema();

            var parent = new CassandraColumnParent {
                ColumnFamily = ColumnFamily.FamilyName
            };

            SlicePredicate = Helper.SetSchemaForSlicePredicate(SlicePredicate, schema, SuperColumnName == null);

            var output = Session.GetClient().get_range_slices(
                parent,
                SlicePredicate,
                KeyRange,
                Session.ReadConsistency
                );

            foreach (var result in output)
            {
                var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyValueType);

                var r = new FluentSuperColumnFamily(key, ColumnFamily.FamilyName, schema, result.Columns.Select(col => {
                    var superCol = Helper.ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema);
                    ColumnFamily.Context.Attach(superCol);
                    superCol.MutationTracker.Clear();

                    return(superCol);
                }));
                ColumnFamily.Context.Attach(r);
                r.MutationTracker.Clear();

                yield return(r);
            }
        }
예제 #8
0
        private IEnumerable <FluentColumn> GetColumns(Apache.Cassandra.CqlRow row, CassandraCqlRowSchema schema)
        {
            foreach (var col in row.Columns)
            {
                var name      = CassandraObject.GetCassandraObjectFromDatabaseByteArray(col.Name, CassandraType.BytesType);
                var colSchema = schema.Columns.Where(x => x.Name == name).FirstOrDefault();

                var fcol = Helper.ConvertColumnToFluentColumn(col, colSchema);
                yield return(fcol);
            }
        }
        public override IEnumerable <FluentSuperColumnFamily> Execute()
        {
            var schema = ColumnFamily.GetSchema();

            var parent = new CassandraColumnParent {
                ColumnFamily = ColumnFamily.FamilyName
            };

            if (SuperColumnName != null)
            {
                parent.SuperColumn = SuperColumnName;
            }

            SlicePredicate = Helper.SetSchemaForSlicePredicate(SlicePredicate, schema, SuperColumnName == null);

            var output = Session.GetClient().multiget_slice(
                Keys,
                parent,
                SlicePredicate,
                Session.ReadConsistency
                );

            foreach (var result in output)
            {
                var key = CassandraObject.GetCassandraObjectFromDatabaseByteArray(result.Key, schema.KeyValueType);

                var superColumns = (IEnumerable <FluentSuperColumn>)null;

                if (SuperColumnName != null)
                {
                    var superColSchema = new CassandraColumnSchema {
                        NameType  = schema.SuperColumnNameType,
                        Name      = SuperColumnName,
                        ValueType = schema.ColumnNameType
                    };

                    var superCol = new FluentSuperColumn(superColSchema, result.Value.Select(col => Helper.ConvertColumnToFluentColumn(col.Column, schema)));
                    ColumnFamily.Context.Attach(superCol);

                    superColumns = new[] { superCol };
                }
                else
                {
                    superColumns = result.Value.Select(col => Helper.ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema));
                }

                var familyName = ColumnFamily.FamilyName;
                var r          = new FluentSuperColumnFamily(key, familyName, schema, superColumns);
                ColumnFamily.Context.Attach(r);

                yield return(r);
            }
        }
예제 #10
0
        private IEnumerable <ICqlRow> GetRows(Apache.Cassandra.CqlResult result)
        {
            var familyName = TryGetFamilyName();
            var schema     = new CassandraCqlRowSchema(result, familyName);

            foreach (var row in result.Rows)
            {
                yield return(new FluentCqlRow(
                                 CassandraObject.GetCassandraObjectFromDatabaseByteArray(row.Key, CassandraType.BytesType),
                                 familyName,
                                 schema,
                                 GetColumns(row, schema)));
            }
        }
예제 #11
0
        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);
            }
        }
예제 #12
0
        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),
                ColumnTimestamp = TimestampHelper.FromCassandraTimestamp(col.Timestamp),
            };

            if (col.__isset.ttl)
            {
                fcol.ColumnSecondsUntilDeleted = col.Ttl;
            }

            return(fcol);
        }
        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();
        }
예제 #14
0
 public CassandraColumnSchema(ColumnDef def, CassandraType columnNameType)
 {
     NameType  = columnNameType;
     Name      = CassandraObject.GetCassandraObjectFromDatabaseByteArray(def.Name, columnNameType);
     ValueType = CassandraType.GetCassandraType(def.Validation_class);
 }