Ejemplo n.º 1
0
        public void GetSuperRangeSlice()
        {
            for (int i = 0; i < 10; i++)
            {
                var cp = new ColumnPath("Super1", "SuperColumn.1", "GetSuperRangeSlice." + i);
                Keyspace.Insert("GetSuperRangeSlice.0", cp, "GetSuperRangeSlice_value_" + i);
                Keyspace.Insert("GetSuperRangeSlice.1", cp, "GetSuperRangeSlice_value_" + i);
            }

            var columnParent = new ColumnParent("Super1");
            var predicate    = new SlicePredicate(null, new SliceRange(false, 150));
            var keySlices    = Keyspace.GetSuperRangeSlice(columnParent, predicate, "GetSuperRangeSlice.0", "GetSuperRangeSlice.3", 5);

            Assert.NotNull(keySlices);

            Assert.Equal(2, keySlices.Where(x => x.Key.StartsWith("GetSuperRangeSlice.")).Count());
            Assert.NotNull(keySlices["GetSuperRangeSlice.0"]);
            Assert.Equal("GetSuperRangeSlice_value_0",
                         keySlices["GetSuperRangeSlice.0"].First().Columns.First().Value);
            Assert.Equal(1, keySlices["GetSuperRangeSlice.1"].Count);
            Assert.Equal(10, keySlices["GetSuperRangeSlice.1"].First().Columns.Count);

            var columnPath = new ColumnPath("Super1");

            for (int i = 0; i < 2; i++)
            {
                Keyspace.Remove("GetSuperRangeSlice" + i, columnPath);
            }
        }
Ejemplo n.º 2
0
        public void GetSlice()
        {
            // insert
            var columnNames = new List <string>();

            for (int i = 0; i < 100; i++)
            {
                Keyspace.Insert("GetSlice", new ColumnPath("Standard2", null, "GetSlice." + i), "GetSlice.Value." + i);
                columnNames.Add("GetSlice." + i);
            }

            // get
            var columnParent   = new ColumnParent("Standard2");
            var sliceRange     = new SliceRange(false, 150);
            var slicePredicate = new SlicePredicate(null, sliceRange);
            var columns        = Keyspace.GetSlice("GetSlice", columnParent, slicePredicate);

            Assert.NotNull(columns);
            Assert.Equal(100, columns.Count());

            var receivedColumnNames = columns.OrderBy(c => c.Name).Select(c => c.Name).ToList();

            Assert.NotEmpty(receivedColumnNames);
            Assert.Equal(columnNames.OrderBy(i => i).ToList(), receivedColumnNames);

            // clean up
            Keyspace.Remove("GetSlice", new ColumnPath("Standard2"));
        }
Ejemplo n.º 3
0
        public void GetRangeSlice()
        {
            env.RestartCassandra();
            env.OpenConnection();

            // build 3 keys with 10 columns each
            for (int i = 0; i < 10; i++)
            {
                var cp = new ColumnPath("Standard2", null, "c" + i);

                Insert("rs0", "v" + i, cp);
                Insert("rs1", "v" + i, cp);
                Insert("rs2", "v" + i, cp);
            }

            var columnParent = new ColumnParent("Standard2");
            var predicate    = new SlicePredicate(new SliceRange(false, 150));

            var keySlices = client.get_range_slice(
                "Keyspace1", columnParent, predicate,
                "rs0", "rs3", 5, ConsistencyLevel.ONE);

            Assert.NotNull(keySlices);
            Assert.Equal(3, keySlices.Count);
            Assert.NotNull(keySlices[0]);
            Assert.Equal("v0", keySlices[0].Columns[0].Column.Value.UTFDecode());
            Assert.Equal(10, keySlices[1].Columns.Count);

            env.CloseConnection();
            env.StopCassandra();
        }
Ejemplo n.º 4
0
        public void MultigetSlice()
        {
            // insert
            var columnPath = new ColumnPath("Standard1", null, "MultigetSlice");
            var keys       = new List <string>();

            for (int i = 0; i < 100; i++)
            {
                var key = "MultigetSlice." + i;
                Keyspace.Insert(key, columnPath, "MultigetSlice.value." + i);
                keys.Add(key);
            }

            // get
            var columnParent   = new ColumnParent("Standard1");
            var sliceRange     = new SliceRange(false, 150);
            var slicePredicate = new SlicePredicate(null, sliceRange);
            var ms             = Keyspace.MultigetSlice(keys, columnParent, slicePredicate);

            for (int i = 0; i < 100; i++)
            {
                var columns = ms[keys[i]];
                Assert.NotNull(columns);
                Assert.Equal(1, columns.Count);
                Assert.True(columns.First().Value.StartsWith("MultigetSlice."));
            }

            // remove
            for (int i = 0; i < 100; i++)
            {
                Keyspace.Remove("MultigetSlice." + i, columnPath);
            }
        }
Ejemplo n.º 5
0
        public List <K> getRowKeyList <K>(string keyspace, Object columnFamily)
        {
            client.set_keyspace(keyspace);
            KeyRange range = new KeyRange();

            range.Count     = ALL_COUNT;
            range.Start_key = new byte[0];
            range.End_key   = new byte[0];

            SlicePredicate sp = new SlicePredicate();

            sp.Slice_range          = new SliceRange();
            sp.Slice_range.Start    = new byte[0];
            sp.Slice_range.Finish   = new byte[0];
            sp.Slice_range.Reversed = false;
            sp.Slice_range.Count    = ALL_COUNT;
            ColumnParent cp = new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            };
            List <KeySlice> rows = client.get_range_slices(cp, sp, range, consistencyLevel);

            List <K> list = new List <K>();

            foreach (var row in rows)
            {
                list.Add((K)row.Key.ToObjectFromByteArray(typeof(K)));
            }
            return(list);
        }
Ejemplo n.º 6
0
        public void GetRangeSlice()
        {
            // build 3 keys with 10 columns each
            for (int i = 0; i < 10; i++)
            {
                var cp = new ColumnPath("Standard2", null, "c" + i);
                Keyspace.Insert("rs0", cp, "v" + i);
                Keyspace.Insert("rs1", cp, "v" + i);
                Keyspace.Insert("rs2", cp, "v" + i);
            }

            var columnParent = new ColumnParent("Standard2");
            var predicate    = new SlicePredicate(new SliceRange(false, 150));

            var keySlices = Keyspace.GetRangeSlice(columnParent, predicate, "rs0", "rs3", 5);

            Assert.NotNull(keySlices);
            Assert.Equal(3, keySlices.Count);
            Assert.NotNull(keySlices["rs0"]);
            Assert.Equal("v0", keySlices["rs0"].First().Value);
            Assert.Equal(10, keySlices["rs1"].Count);

            var columnPath = new ColumnPath("Standard2");

            for (int i = 0; i < 3; i++)
            {
                Keyspace.Remove("rs" + i, columnPath);
            }
        }
        public List <RawColumn> GetColumns(byte[] key, List <byte[]> columnNames)
        {
            var slicePredicate  = new SlicePredicate(columnNames);
            var getSliceCommand = new GetSliceCommand(keyspaceName, columnFamilyName, key, readConsistencyLevel, slicePredicate);

            commandExecutor.Execute(getSliceCommand);
            return(getSliceCommand.Output);
        }
Ejemplo n.º 8
0
        public void SimpleScenario()
        {
            env.RestartCassandra();
            env.OpenConnection();

            //At this point we're using the standard configuration file
            var cp = new ColumnPath("Standard1", null, "name");

            Console.WriteLine("Inserting a column");

            Insert("1", "Josh Blogs", cp);
            Insert("2", "Something else", cp);

            //Let's get something back out (this is our select statement)
            var returnedColumn = client.get(
                "Keyspace1",         //The database
                "1",                 //The actual key we want
                cp,                  //Where that key sits
                ConsistencyLevel.ONE //HAZY
                );

            Console.WriteLine("We got Name: {0}, value {1}",
                              returnedColumn.Column.Name.UTFDecode(),
                              returnedColumn.Column.Value.UTFDecode());

            Console.WriteLine("Now let's try getting a range");

            //This is telling us the offest to get.  This is where paging would occur.
            var predicate = new SlicePredicate(new SliceRange(false, 10));
            var parent    = new ColumnParent("Standard1");

            var keyedResults =
                client.multiget_slice("Keyspace1",
                                      new List <string> {
                "1", "2"
            },
                                      parent,
                                      predicate,
                                      ConsistencyLevel.ONE);

            foreach (var keyedResult in keyedResults)
            {
                Console.WriteLine("Key: {0}", keyedResult.Key);
                foreach (ColumnOrSuperColumn result in keyedResult.Value)
                {
                    Column column = result.Column;
                    Console.WriteLine("Name: {0}, value: {1}",
                                      column.Name.UTFDecode(),
                                      column.Value.UTFDecode());
                }
            }

            env.CloseConnection();
            env.StopCassandra();
        }
        public List <byte[]> GetKeys(byte[] startKey, int count)
        {
            var keyRange = new KeyRange {
                StartKey = startKey ?? new byte[0], EndKey = new byte[0], Count = count
            };
            var aquilesSlicePredicate   = new SlicePredicate(new List <byte[]>());
            var getKeyRangeSliceCommand = new GetKeyRangeSliceCommand(keyspaceName, columnFamilyName, readConsistencyLevel, keyRange, aquilesSlicePredicate);

            commandExecutor.Execute(getKeyRangeSliceCommand);
            return(getKeyRangeSliceCommand.Output);
        }
        public List <KeyValuePair <byte[], List <RawColumn> > > GetRegion(List <byte[]> keys, byte[] startColumnName, byte[] finishColumnName, int limitPerRow)
        {
            var slicePredicate = new SlicePredicate(new SliceRange
            {
                Count       = limitPerRow,
                StartColumn = startColumnName,
                EndColumn   = finishColumnName,
                Reversed    = false
            });
            var command = new MultiGetSliceCommand(keyspaceName, columnFamilyName, readConsistencyLevel, keys, slicePredicate);

            commandExecutor.Execute(command);
            return(command.Output.Where(pair => pair.Value.Any()).ToList());
        }
        public List <RawColumn> GetRow(byte[] key, byte[] startColumnName, byte[] endColumnName, int count, bool reversed)
        {
            var aquilesSlicePredicate = new SlicePredicate(new SliceRange
            {
                Count       = count,
                StartColumn = startColumnName,
                EndColumn   = endColumnName,
                Reversed    = reversed
            });
            var getSliceCommand = new GetSliceCommand(keyspaceName, columnFamilyName, key, readConsistencyLevel, aquilesSlicePredicate);

            commandExecutor.Execute(getSliceCommand);
            return(getSliceCommand.Output);
        }
Ejemplo n.º 12
0
        public List <NColumn <N, V> > getColumns <N, V>(string keyspace, Object columnFamily, Object key, HashSet <String> columnNames)
        {
            client.set_keyspace(keyspace);
            SlicePredicate sp = new SlicePredicate();

            sp.Column_names = columnNames.ToByteArrayListFromCollection <string>();
            var results = ThriftUtility.ToNColumnList <N, V>(client.get_slice(key.ToByteArray(),
                                                                              new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            }, sp, consistencyLevel));

            return(results);
        }
Ejemplo n.º 13
0
        public void MultigetSuperSlice_With_SuperColumn()
        {
            var list = new List <Column>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(new Column("MultigetSuperSlice." + i, "MultigetSuperSlice.value." + i));
            }

            var scmap = new Dictionary <string, IList <SuperColumn> >();

            scmap.Add("Super1", new List <SuperColumn>
            {
                new SuperColumn("SuperColumn.1", list),
                new SuperColumn("SuperColumn.2", list),
            });

            var keys = new List <string>();

            for (int i = 1; i <= 3; i++)
            {
                var key = "MultigetSuperSlice." + i;
                Keyspace.BatchInsert(key, null, scmap);
                keys.Add(key);
            }

            try
            {
                var columnParent = new ColumnParent("Super1", "SuperColumn.1");
                var predicate    = new SlicePredicate(null, new SliceRange(false, 150));
                var superc       = Keyspace.MultigetSuperSlice(keys, columnParent, predicate);

                Assert.NotNull(superc);
                Assert.Equal(3, superc.Count);
                var scls = superc[keys[0]];
                Assert.NotNull(scls);
                Assert.Equal(1, scls.Count);
                Assert.NotNull(scls[0].Columns);
                Assert.Equal(10, scls[0].Columns.Count);
                Assert.NotNull(scls[0].Columns[0].Value);
            }
            finally
            {
                var columnPath = new ColumnPath("Super1");
                for (int i = 1; i <= 3; i++)
                {
                    Keyspace.Remove("MultigetSuperSlice." + i, columnPath);
                }
            }
        }
Ejemplo n.º 14
0
        public Rows <K, N, V> getRows <K, N, V>(string keyspace, Object columnFamily, ICollection <K> keys,
                                                ICollection <String> columnNames)
        {
            client.set_keyspace(keyspace);
            List <byte[]>  binaryKeys = keys.ToByteArrayListFromCollection <K>();
            SlicePredicate sp         = new SlicePredicate();

            sp.Column_names = columnNames.ToByteArrayListFromCollection <string>();
            Rows <K, N, V> results = ThriftUtility.ToRowsFromSliceQuery <K, N, V>(client.multiget_slice(binaryKeys,
                                                                                                        new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            }, sp, consistencyLevel));

            return(results);
        }
Ejemplo n.º 15
0
        public List <ColumnOrSuperColumn> GetSlice(string family, string key, string superColumnName, int count)
        {
            //var getSliceCommand = new GetSliceCommand
            //                          {
            //                              KeySpace = Name,
            //                              Key = key,
            //                              ColumnFamily = family,
            //                              SuperColumn = superColumnName,
            //                              Predicate =
            //                                  new SlicePredicate
            //                                      {
            //                                          Slice_range = new SliceRange {Count = count}
            //                                      }
            //
            //using (var connection = AquilesHelper.RetrieveConnection(Cluster))
            //{
            //    connection.Execute(getSliceCommand);
            //    return getSliceCommand.Output == null
            //               ? new List<AquilesColumn>()
            //               : getSliceCommand.Output.Results.Select(o => o.Column).ToList();
            //}

            byte[] keyAsByteArray = Encoding.ASCII.GetBytes(key);
            var    columnParent   = new ColumnParent
            {
                Column_family = family,
            };
            var predicate = new SlicePredicate
            {
                Slice_range = new SliceRange
                {
                    Count    = 1000,
                    Reversed = false,
                    Start    = new byte[0],
                    Finish   = new byte[0],
                },
            };

            ICluster cluster  = AquilesHelper.RetrieveCluster(Cluster);
            object   rtnValue = cluster.Execute(new ExecutionBlock(
                                                    client =>
                                                    client.get_slice(keyAsByteArray, columnParent, predicate,
                                                                     ConsistencyLevel.ONE)), keyspaceName);

            return(rtnValue as List <ColumnOrSuperColumn>);
        }
Ejemplo n.º 16
0
        public override IEnumerable <IFluentSuperColumn <CompareWith, CompareSubcolumnWith> > Execute(BaseCassandraColumnFamily columnFamily)
        {
            CassandraSession _localSession = null;

            if (CassandraSession.Current == null)
            {
                _localSession = new CassandraSession();
            }

            try
            {
                var parent = new ColumnParent {
                    Column_family = columnFamily.FamilyName
                };

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

                var output = CassandraSession.Current.GetClient().multiget_slice(
                    Keys.ToByteArrayList(),
                    parent,
                    SlicePredicate.CreateSlicePredicate(),
                    CassandraSession.Current.ReadConsistency
                    );

                foreach (var result in output)
                {
                    var r = new FluentSuperColumn <CompareWith, CompareSubcolumnWith>(result.Value.Select(col => {
                        return(Helper.ConvertColumnToFluentColumn <CompareSubcolumnWith>(col.Column));
                    }));
                    columnFamily.Context.Attach(r);
                    r.MutationTracker.Clear();

                    yield return(r);
                }
            }
            finally
            {
                if (_localSession != null)
                {
                    _localSession.Dispose();
                }
            }
        }
Ejemplo n.º 17
0
        public ColumnSlice <N, V> getColumns <N, V>(string keyspace, Object columnFamily, Object key, N[] columnNames)
        {
            client.set_keyspace(keyspace);
            byte[]       binaryKey = key.ToByteArray();
            ColumnParent cp        = new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            };
            SlicePredicate sp = new SlicePredicate();

            sp.Column_names = columnNames.ToByteArrayListFromCollection <N>();
            var result = ThriftUtility.ToNColumnList <N, V>(client.get_slice(binaryKey, cp, sp, consistencyLevel));
            ColumnSlice <N, V> cslice = new ColumnSlice <N, V>();

            cslice.Columns = result;
            return(cslice);
        }
Ejemplo n.º 18
0
        public override IEnumerable <IFluentSuperColumnFamily <CompareWith, CompareSubcolumnWith> > Execute(BaseCassandraColumnFamily columnFamily)
        {
            CassandraSession _localSession = null;

            if (CassandraSession.Current == null)
            {
                _localSession = new CassandraSession();
            }

            try
            {
                var parent = new ColumnParent {
                    Column_family = columnFamily.FamilyName
                };

                var output = CassandraSession.Current.GetClient().get_indexed_slices(
                    parent,
                    IndexClause.CreateIndexClause(),
                    SlicePredicate.CreateSlicePredicate(),
                    CassandraSession.Current.ReadConsistency
                    );

                foreach (var result in output)
                {
                    var r = new FluentSuperColumnFamily <CompareWith, CompareSubcolumnWith>(result.Key, columnFamily.FamilyName, result.Columns.Select(col => {
                        var superCol = Helper.ConvertSuperColumnToFluentSuperColumn <CompareWith, CompareSubcolumnWith>(col.Super_column);
                        columnFamily.Context.Attach(superCol);
                        superCol.MutationTracker.Clear();

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

                    yield return(r);
                }
            }
            finally
            {
                if (_localSession != null)
                {
                    _localSession.Dispose();
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns the columns in the range from the start column to the finish column for a given row key
        /// </summary>
        /// <param name="keyspace"></param>
        /// <param name="columnFamily"></param>
        /// <param name="key"></param>
        /// <param name="start">start column name</param>
        /// <param name="finish">end column name</param>
        /// <param name="count"></param>
        /// <param name="reversed"></param>
        /// <returns></returns>
        public List <NColumn <byte, byte> > getColumns(string keyspace, Object columnFamily, Object key, Object start,
                                                       Object finish, int count, Boolean reversed)
        {
            client.set_keyspace(keyspace);

            byte[]       binaryKey = key.ToByteArray();
            ColumnParent cp        = new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            };
            SlicePredicate sp = new SlicePredicate();

            sp.Slice_range          = new SliceRange();
            sp.Slice_range.Start    = start.ToByteArray();
            sp.Slice_range.Finish   = finish.ToByteArray();
            sp.Slice_range.Reversed = reversed;
            sp.Slice_range.Count    = count;
            return(ThriftUtility.ToNColumnList <byte, byte>(client.get_slice(binaryKey, cp, sp, consistencyLevel)));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Generic method to get the columns.
        /// </summary>
        /// <typeparam name="N">Type of column name</typeparam>
        /// <typeparam name="V">Type of column value</typeparam>
        /// <param name="keyspace"></param>
        /// <param name="columnFamily"></param>
        /// <param name="key">Row key</param>
        /// <returns>List of NColumns of N,V types</returns>
        public List <NColumn <N, V> > getAllColumns <N, V>(string keyspace, Object columnFamily, Object key)
        {
            client.set_keyspace(keyspace);
            byte[]       binaryKey = key.ToByteArray();
            ColumnParent cp        = new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            };
            SlicePredicate sp = new SlicePredicate();

            sp.Slice_range          = new SliceRange();
            sp.Slice_range.Start    = new byte[0];
            sp.Slice_range.Finish   = new byte[0];
            sp.Slice_range.Reversed = false;
            sp.Slice_range.Count    = ALL_COUNT;
            var result = ThriftUtility.ToNColumnList <N, V>(client.get_slice(binaryKey, cp, sp, consistencyLevel));

            return(result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Determines if data is present in the storage
        /// </summary>
        /// <param name="key">Key which identifies the data</param>
        /// <returns>True if data is present</returns>
        public bool Contains(Guid key)
        {
            // Get statement
            byte[] keyEncoded = key.ToByteArray();

            ColumnParent columnParent = new ColumnParent();

            columnParent.Column_family = columnFamily;

            var predicate = new SlicePredicate();
            //predicate.Column_names = new List<byte[]>();
            //predicate.Column_names.Add(ByteEncoderHelper.UTF8Encoder.ToByteArray("Value"));

            bool result = (bool)cluster.Execute(new ExecutionBlock(delegate(Cassandra.Client client)
            {
                return(client.get_count(keyEncoded, columnParent, predicate, ConsistencyLevel.ONE) > 0);
            }), keySpace);

            return(result);
        }
Ejemplo n.º 22
0
        public void BlogModelScenario()
        {
            env.RestartCassandra();
            env.OpenConnection();

            string entryTitle    = "now with bonus batch writes";
            string entryAuthor   = "josh";
            string entryBody     = "This is my blog entry yet again";
            string entryPostDate = DateTime.Now.ToShortDateString();

            var cfmap = new Dictionary <string, List <ColumnOrSuperColumn> >();

            //Column families are case sensitive
            //"BlogEntries"
            cfmap.Add("Standard1", new List <ColumnOrSuperColumn>
            {
                new ColumnOrSuperColumn(new Column("title", entryTitle)),
                new ColumnOrSuperColumn(new Column("body", entryBody)),
                new ColumnOrSuperColumn(new Column("author", entryAuthor)),
                new ColumnOrSuperColumn(new Column("postDate", entryPostDate)),
            });

            client.batch_insert("Keyspace1", entryTitle, cfmap, ConsistencyLevel.ONE);

            //Now Read it back.
            var predicate = new SlicePredicate(new SliceRange(false, 10));
            var parent    = new ColumnParent("Standard1");          //"BlogEntries");

            var results = client.get_slice("Keyspace1", entryTitle, parent, predicate, ConsistencyLevel.ONE);

            foreach (ColumnOrSuperColumn resultColumn in results)
            {
                Column column = resultColumn.Column;
                Console.WriteLine("Name: {0}, value: {1}",
                                  column.Name.UTFDecode(),
                                  column.Value.UTFDecode());
            }

            env.CloseConnection();
            env.StopCassandra();
        }
        private IEnumerable <IFluentColumnFamily <CompareWith> > GetFamilies(BaseCassandraColumnFamily columnFamily)
        {
            CassandraSession _localSession = null;

            if (CassandraSession.Current == null)
            {
                _localSession = new CassandraSession();
            }

            try
            {
                var parent = new ColumnParent {
                    Column_family = columnFamily.FamilyName
                };

                var output = CassandraSession.Current.GetClient().get_range_slices(
                    parent,
                    SlicePredicate.CreateSlicePredicate(),
                    KeyRange.CreateKeyRange(),
                    CassandraSession.Current.ReadConsistency
                    );

                foreach (var result in output)
                {
                    var r = new FluentColumnFamily <CompareWith>(result.Key, columnFamily.FamilyName, result.Columns.Select(col => {
                        return(Helper.ConvertColumnToFluentColumn <CompareWith>(col.Column));
                    }));
                    columnFamily.Context.Attach(r);
                    r.MutationTracker.Clear();

                    yield return(r);
                }
            }
            finally
            {
                if (_localSession != null)
                {
                    _localSession.Dispose();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Returns a dictionary of NColumns for a given set of row keys from start colmn to finish column
        /// </summary>
        /// <param name="keyspace"></param>
        /// <param name="columnFamily"></param>
        /// <param name="keys"></param>
        /// <param name="start">start column name</param>
        /// <param name="finish">end column name</param>
        /// <param name="count"></param>
        /// <param name="reversed"></param>
        /// <returns></returns>
        public Dictionary <byte[], List <NColumn <byte[], byte[]> > > multiGetColumns(string keyspace, Object columnFamily,
                                                                                      List <object> keys, Object start,
                                                                                      Object finish, int count,
                                                                                      bool reversed)
        {
            client.set_keyspace(keyspace);
            List <byte[]>  binaryKeys = keys.ToByteArrayListFromCollection <object>();
            SlicePredicate sp         = new SlicePredicate();

            sp.Slice_range          = new SliceRange();
            sp.Slice_range.Start    = start.ToByteArray();
            sp.Slice_range.Finish   = finish.ToByteArray();
            sp.Slice_range.Reversed = reversed;
            sp.Slice_range.Count    = count;
            var results = ThriftUtility.ToByteDictionaryFromColumnDictionary(client.multiget_slice(binaryKeys,
                                                                                                   new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            }, sp, consistencyLevel));

            return(results);
        }
Ejemplo n.º 25
0
        public Rows <K, N, V> getRows <K, N, V>(string keyspace, Object columnFamily, ICollection <K> keys)
        {
            client.set_keyspace(keyspace);
            List <byte[]> binaryKeys = keys.ToByteArrayListFromCollection <K>();
            ColumnParent  cp         = new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            };
            SlicePredicate sp = new SlicePredicate();

            sp.Slice_range          = new SliceRange();
            sp.Slice_range.Start    = new byte[0];
            sp.Slice_range.Finish   = new byte[0];
            sp.Slice_range.Reversed = false;
            sp.Slice_range.Count    = ALL_COUNT;
            Rows <K, N, V> results = ThriftUtility.ToRowsFromSliceQuery <K, N, V>(client.multiget_slice(binaryKeys,
                                                                                                        new ColumnParent()
            {
                Column_family = columnFamily.ToString()
            }, sp, consistencyLevel));

            return(results);
        }
Ejemplo n.º 26
0
        public void deleteColumn(string keyspace, Object columnFamily, Object key, Object columnName)
        {
            client.set_keyspace(keyspace);
            Mutation       mutation = new Mutation();
            SlicePredicate sp       = new SlicePredicate();

            sp.Column_names = (new[] { columnName }).ToByteArrayListFromCollection <object>();
            Deletion deletion = new Deletion();

            deletion.Predicate = sp;
            //timestamp should be optional but its not
            deletion.Timestamp = createTimestamp();
            mutation.Deletion  = deletion;

            Dictionary <byte[], Dictionary <string, List <Mutation> > > mutation_map = new Dictionary <byte[], Dictionary <string, List <Mutation> > >();
            Dictionary <string, List <Mutation> > columnFamilyKey = new Dictionary <string, List <Mutation> >();
            List <Mutation> mutationList = new List <Mutation>();

            mutationList.Add(mutation);
            columnFamilyKey.Add(columnFamily.ToString(), mutationList);
            mutation_map.Add(key.ToByteArray(), columnFamilyKey);
            client.batch_mutate(mutation_map, consistencyLevel);
        }
Ejemplo n.º 27
0
        public void GetSuperSlice()
        {
            // insert
            for (int i = 0; i < 100; i++)
            {
                var cp  = new ColumnPath("Super1", "SuperColumn.1", "GetSuperSlice_" + i);
                var cp2 = new ColumnPath("Super1", "SuperColumn.2", "GetSuperSlice_" + i);
                Keyspace.Insert("GetSuperSlice", cp, "GetSuperSlice_value_" + i);
                Keyspace.Insert("GetSuperSlice", cp2, "GetSuperSlice_value_" + i);
            }

            // get
            var columnParent   = new ColumnParent("Super1");
            var sliceRange     = new SliceRange(false, 150);
            var slicePredicate = new SlicePredicate(null, sliceRange);
            var columns        = Keyspace.GetSuperSlice("GetSuperSlice", columnParent, slicePredicate);

            Assert.NotNull(columns);
            Assert.Equal(2, columns.Count());

            // clean up
            Keyspace.Remove("GetSuperSlice", new ColumnPath("Super1"));
        }
Ejemplo n.º 28
0
 public MultiGetCountCommand(string keyspace, string columnFamily, ConsistencyLevel consistencyLevel, List <byte[]> keys, SlicePredicate predicate)
     : base(keyspace, columnFamily)
 {
     this.consistencyLevel = consistencyLevel;
     this.keys             = keys;
     this.predicate        = predicate ?? new SlicePredicate(new SliceRange {
         Count = int.MaxValue
     });
 }
Ejemplo n.º 29
0
 public GetCountCommand(string keyspace, string columnFamily, byte[] rowKey, ConsistencyLevel consistencyLevel, SlicePredicate predicate = null)
     : base(keyspace, columnFamily)
 {
     PartitionKey          = rowKey;
     this.consistencyLevel = consistencyLevel;
     this.predicate        = predicate ?? new SlicePredicate(new SliceRange {
         Count = int.MaxValue
     });
 }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            TTransport transport = new TSocket("localhost", 9160);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            Cassandra.Client client = new Cassandra.Client(protocol);

            Console.WriteLine("Opening connection");
            transport.Open();

            System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8;

            long       timeStamp      = DateTime.Now.Millisecond;
            ColumnPath nameColumnPath = new ColumnPath()
            {
                Column_family = "Standard1",
                Column        = utf8Encoding.GetBytes("name")
            };

            Console.WriteLine("Inserting name columns");

            //Insert the data into the column 'name'
            client.insert("Keyspace1",
                          "1",
                          nameColumnPath,
                          utf8Encoding.GetBytes("Joe Bloggs"),
                          timeStamp,
                          ConsistencyLevel.ONE);

            client.insert("Keyspace1",
                          "2",
                          nameColumnPath,
                          utf8Encoding.GetBytes("Joe Soap"),
                          timeStamp,
                          ConsistencyLevel.ONE);

            //Simple single value get using the key to get column 'name'
            ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "1", nameColumnPath, ConsistencyLevel.ONE);

            Console.WriteLine("Column Data in Keyspace1/Standard1: name: {0}, value: {1}",
                              utf8Encoding.GetString(returnedColumn.Column.Name),
                              utf8Encoding.GetString(returnedColumn.Column.Value));

            Console.WriteLine("Getting splice range");

            //Read an entire row
            SlicePredicate predicate = new SlicePredicate()
            {
                Slice_range = new SliceRange()
                {
                    //Start and Finish cannot be null
                    Start    = new byte[0],
                    Finish   = new byte[0],
                    Count    = 10,
                    Reversed = false
                }
            };

            ColumnParent parent = new ColumnParent()
            {
                Column_family = "Standard1"
            };
            Dictionary <string, List <ColumnOrSuperColumn> > results = client.multiget_slice("Keyspace1",
                                                                                             new List <string>()
            {
                "1", "2"
            },
                                                                                             parent,
                                                                                             predicate,
                                                                                             ConsistencyLevel.ONE);

            foreach (KeyValuePair <string, List <ColumnOrSuperColumn> > resultPair in results)
            {
                Console.WriteLine("Key: {0}", resultPair.Key);

                foreach (ColumnOrSuperColumn resultColumn in resultPair.Value)
                {
                    Column column = resultColumn.Column;
                    Console.WriteLine("name: {0}, value: {1}", utf8Encoding.GetString(column.Name), utf8Encoding.GetString(column.Value));
                }
            }

            Console.WriteLine("Closing connection");
            transport.Close();
        }