Пример #1
0
        public ParsedFolderData(List <ColumnOrSuperColumn> allColumns)
        {
            byte[] propertiesKey = ByteEncoderHelper.UTF8Encoder.ToByteArray("properties");
            byte[] subFoldersKey = ByteEncoderHelper.UTF8Encoder.ToByteArray("sub_folders");

            bool propsFound      = false;
            bool subFoldersFound = false;

            _items = new List <ColumnOrSuperColumn>();
            foreach (ColumnOrSuperColumn col in allColumns)
            {
                if (!propsFound && col.Super_column.Name.SequenceEqual(propertiesKey))
                {
                    //properties
                    propsFound    = true;
                    _propertiesSc = col;
                }
                else if (!subFoldersFound && col.Super_column.Name.SequenceEqual(subFoldersKey))
                {
                    subFoldersFound = true;
                    _subfoldersSc   = col;
                }
                else
                {
                    _items.Add(col);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Reads data from storage
        /// </summary>
        /// <param name="key">Key which identifies the data</param>
        /// <returns>Storage data</returns>
        public object Value(Guid key)
        {
            // Get statement
            byte[]     keyEncoded = key.ToByteArray();
            ColumnPath columnPath = new ColumnPath()
            {
                Column        = ByteEncoderHelper.UTF8Encoder.ToByteArray("Value"),
                Column_family = columnFamily,
            };

            ColumnOrSuperColumn column = (ColumnOrSuperColumn)cluster.Execute(new ExecutionBlock(delegate(Cassandra.Client client)
            {
                return(client.get(keyEncoded, columnPath, ConsistencyLevel.ONE));
            }), keySpace);

            var data = column.Column.Value;

            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    return(Serializer.Deserialize(br));
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            //建立数据库连接
            TTransport transport = new TSocket("192.168.10.2", 9160);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            Cassandra.Client client = new Cassandra.Client(protocol);
            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("age")
            };

            //写入数据
            client.insert("Keyspace1",
                          "studentA",
                          nameColumnPath,
                          utf8Encoding.GetBytes("18"),
                          timeStamp,
                          ConsistencyLevel.ONE);

            //读取数据
            ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "studentA", nameColumnPath, ConsistencyLevel.ONE);

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

            //关闭连接
            transport.Close();
        }
        public override void Execute(Apache.Cassandra.Cassandra.Client cassandraClient, ILog logger)
        {
            ColumnOrSuperColumn columnOrSupercolumn = null;
            var columnPath = BuildColumnPath(columnName);

            try
            {
                columnOrSupercolumn = cassandraClient.get(PartitionKey, columnPath, consistencyLevel);
            }
            catch (NotFoundException)
            {
                //ничего не делаем
            }

            Output = columnOrSupercolumn?.Column.FromCassandraColumn();
        }
Пример #5
0
 public static IFluentBaseColumn ConvertToFluentBaseColumn(ColumnOrSuperColumn col, CassandraColumnFamilySchema schema)
 {
     if (col.Super_column != null)
     {
         return(ConvertSuperColumnToFluentSuperColumn(col.Super_column, schema));
     }
     else if (col.Column != null)
     {
         return(ConvertColumnToFluentColumn(col.Column, schema));
     }
     else if (col.Counter_super_column != null)
     {
         return(ConvertColumnToFluentCounterColumn(col.Counter_column, schema));
     }
     else if (col.Counter_column != null)
     {
         return(ConvertSuperColumnToFluentCounterSuperColumn(col.Counter_super_column, schema));
     }
     else
     {
         return(null);
     }
 }
Пример #6
0
 public void Read(TProtocol iprot)
 {
     TField field;
       iprot.ReadStructBegin();
       while (true)
       {
     field = iprot.ReadFieldBegin();
     if (field.Type == TType.Stop) {
       break;
     }
     switch (field.ID)
     {
       case 1:
     if (field.Type == TType.String) {
       this.key = iprot.ReadString();
       this.__isset.key = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       case 2:
     if (field.Type == TType.List) {
       {
         this.columns = new List<ColumnOrSuperColumn>();
         TList _list8 = iprot.ReadListBegin();
         for( int _i9 = 0; _i9 < _list8.Count; ++_i9)
         {
           ColumnOrSuperColumn _elem10 = new ColumnOrSuperColumn();
           _elem10 = new ColumnOrSuperColumn();
           _elem10.Read(iprot);
           this.columns.Add(_elem10);
         }
         iprot.ReadListEnd();
       }
       this.__isset.columns = true;
     } else {
       TProtocolUtil.Skip(iprot, field.Type);
     }
     break;
       default:
     TProtocolUtil.Skip(iprot, field.Type);
     break;
     }
     iprot.ReadFieldEnd();
       }
       iprot.ReadStructEnd();
 }
Пример #7
0
 public static IFluentBaseColumn <CompareWith> ConvertToFluentBaseColumn <CompareWith, CompareSubcolumnWith>(ColumnOrSuperColumn col)
     where CompareWith : CassandraType
     where CompareSubcolumnWith : CassandraType
 {
     if (col.Super_column != null)
     {
         return(ConvertSuperColumnToFluentSuperColumn <CompareWith, CompareSubcolumnWith>(col.Super_column));
     }
     else if (col.Column != null)
     {
         return(ConvertColumnToFluentColumn <CompareWith>(col.Column));
     }
     else
     {
         return(null);
     }
 }
Пример #8
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();
        }