douduan7295 2013-06-11 16:14
浏览 22
已采纳

在phpcassa中插入TimeUUIDType作为行键

I created a simple keyspace and a column family using Cassandra-Cluster-Admin

I have a column family named players

create column family player
  with column_type = 'Standard'
  and comparator = 'TimeUUIDType'
  and default_validation_class = 'BytesType'
  and key_validation_class = 'BytesType'
  and rows_cached = 0.0
  and row_cache_save_period = 0
  and row_cache_keys_to_save = 2147483647
  and keys_cached = 200000.0
  and key_cache_save_period = 14400
  and read_repair_chance = 1.0
  and gc_grace = 864000
  and min_compaction_threshold = 4
  and max_compaction_threshold = 32
  and replicate_on_write = true
  and row_cache_provider = 'ConcurrentLinkedHashCacheProvider'
  and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy';

I'm trying to insert a row with row key TimeUUIDType.

I'm initialing ConnectionPool with the following;

$this->_connection_pool = new ConnectionPool($key_space, $this->_config['servers']);

I'm initializing the ColumnFamily instance with the following;

$this->_column_family = new ColumnFamily($this->_connection_pool, $column_family);

Finally, I'm inserting to the column family with this code;

this->_column_family->insert(UUID::uuid1, $data);

Data array is like the following;

$data = array('user_name' => 'aacanakin', 'full_name' => 'Aras Can Akin');

It's not inserting and it says the following;

Notice: unserialize(): Error at offset 0 of 9 bytes in /home/arascan/projects/peak-api/vendor/phpcassa/lib/phpcassa/Schema/DataType/UUIDType.php on line 16 

Notice: Trying to get property of non-object in /home/arascan/projects/peak-api/vendor/phpcassa/lib/phpcassa/Schema/DataType/UUIDType.php on line 17

Notice: unserialize(): Error at offset 0 of 9 bytes in /home/arascan/projects/peak-api/vendor/phpcassa/lib/phpcassa/Schema/DataType/UUIDType.php on line 16

 Notice: Trying to get property of non-object in /home/arascan/projects/peak-api/vendor/phpcassa/lib/phpcassa/Schema/DataType/UUIDType.php on line 17

Warning: Illegal offset type in /home/arascan/projects/peak-api/vendor/phpcassa/lib/phpcassa/AbstractColumnFamily.php on line 683

I really need some help. Thanks

  • 写回答

2条回答 默认 最新

  • drsxobip501258 2013-06-14 07:37
    关注

    I've found out the problem. The key_validation_class must be TimeUUIDType if row key will be . The insert function is the following;

    class Cassandra
    {
        // the active connection pool inserted into
        private $_connection_pool;
        private $_column_family;
        private $_config;
        public function __construct($_config)
        {   
            $this->_config = $_config;
            $this->_connection_pool = null;
            $this->_column_family = null;
        }
    
        public function connection($key_space)
        {
            if (is_null($this->_connection_pool)) {
    
                try {
                    $this->_connection_pool = new ConnectionPool($key_space,  
                                    $this->_config['servers']);             
                } catch(Exception $e) {
                    echo $e->getMessage();
                }
            }
    
            return $this;
        }
        public function insert($column_family, $data = array())
        {
            if (is_null($this->_column_family)) {
                $this->_column_family = new ColumnFamily($this->_connection_pool,
                            $column_family);                
                $this->_column_family->insert_format = ColumnFamily::ARRAY_FORMAT;
                $this->_column_family->return_format = ColumnFamily::ARRAY_FORMAT;
            }
    
            $key = UUID::uuid1();
    
            $raw_data = array();
    
            $i = 0;
            foreach ($data as $k => $v)
            {
                $raw_data[$i][] = $k;
                $raw_data[$i][] = $v;
                $i++;
            }
    
            try {
                $this->_column_family->insert($key, $raw_data);
                $error = false;
            } catch (Exception $e) {
                $error = true;
                echo $e->getMessage();
            }
    
            return array('error' => $error);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重