Esempio n. 1
0
        public NColumn <N, V> getColumn <N, V>(string keyspace, Object columnFamily, Object key, N columnName)
        {
            client.set_keyspace(keyspace);
            byte[]     binaryKey = key.ToByteArray();
            ColumnPath cp        = new ColumnPath();

            cp.Column_family = columnFamily.ToString();
            cp.Column        = columnName.ToByteArray();
            var result = ThriftUtility.ToNColumn <N, V>(client.get(binaryKey, cp, consistencyLevel).Column);

            return(result);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the Keyspace with given name
        /// </summary>
        /// <param name="keyspace"></param>
        /// <returns></returns>
        public Keyspace getKeyspace(String keyspace)
        {
            KsDef ks = null;

            try
            {
                ks = client.describe_keyspace(keyspace);
            }
            catch (InvalidRequestException e)
            {
            }

            return(ThriftUtility.ToKeyspaceFromKsDef(ks));
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public List <Keyspace> getKeyspaces()
        {
            List <KsDef> ks = null;

            try
            {
                ks = client.describe_keyspaces();
            }
            catch (InvalidRequestException e)
            {
            }

            List <Keyspace> keyspaces = ThriftUtility.ToKeyspaceListFromKsfDefList(ks);

            return(keyspaces);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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)));
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
 /// <summary>
 /// Creates a column family in the keyspace. If it doesn't exist, it will be created, then the call will sleep
 /// until all nodes have acknowledged the schema change
 /// </summary>
 /// <param name="keyspace"></param>
 /// <param name="cf"></param>
 public void createColumnFamily(String keyspace, ColumnFamily cf)
 {
     if (cf.Keyspace == null)
     {
         cf.Keyspace = keyspace;
     }
     client.set_keyspace(keyspace);
     if (getKeyspace(keyspace) == null)
     {
         throw new InvalidRequestException();
     }
     //add the cf
     if (!cfExists(keyspace, cf.Name))
     {
         //default read repair chance to 0.1
         cf.ReadRepairChance = 0.1d;
         client.system_add_column_family(ThriftUtility.ToCfDefFromColumnFamily(cf));
     }
 }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }