Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在phpcassa中将TimeUUIDType作为行键插入_Php_Cassandra_Phpcassa - Fatal编程技术网

在phpcassa中将TimeUUIDType作为行键插入

在phpcassa中将TimeUUIDType作为行键插入,php,cassandra,phpcassa,Php,Cassandra,Phpcassa,我使用Cassandra Cluster Admin创建了一个简单的键空间和一个列族 我有一个名为玩家的专栏族 create column family player with column_type = 'Standard' and comparator = 'TimeUUIDType' and default_validation_class = 'BytesType' and key_validation_class = 'BytesType' and rows_cac

我使用Cassandra Cluster Admin创建了一个简单的键空间和一个列族

我有一个名为玩家的专栏族

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';
我正在尝试插入一个行键为TimeUUIDType的行

我正在用以下代码初始化ConnectionPool:

$this->_connection_pool = new ConnectionPool($key_space, $this->_config['servers']);
$this->_column_family = new ColumnFamily($this->_connection_pool, $column_family);
$data = array('user_name' => 'aacanakin', 'full_name' => 'Aras Can Akin');
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
我正在使用以下命令初始化ColumnFamily实例:

$this->_connection_pool = new ConnectionPool($key_space, $this->_config['servers']);
$this->_column_family = new ColumnFamily($this->_connection_pool, $column_family);
$data = array('user_name' => 'aacanakin', 'full_name' => 'Aras Can Akin');
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
最后,我将使用此代码插入到列族中

this->_column_family->insert(UUID::uuid1, $data);
数据数组如下所示

$this->_connection_pool = new ConnectionPool($key_space, $this->_config['servers']);
$this->_column_family = new ColumnFamily($this->_connection_pool, $column_family);
$data = array('user_name' => 'aacanakin', 'full_name' => 'Aras Can Akin');
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
它不是插入,而是说:

$this->_connection_pool = new ConnectionPool($key_space, $this->_config['servers']);
$this->_column_family = new ColumnFamily($this->_connection_pool, $column_family);
$data = array('user_name' => 'aacanakin', 'full_name' => 'Aras Can Akin');
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

我真的需要一些帮助。谢谢

我正在使用hector client for java

我用UTF8Type和TimeUUID的组合键成功地实现了这一点,如下所示,希望您能得到一些线索

Composite compKey = new Composite();
compKey.addComponent("c1", HFactoryHelper.stringSerializer);
compKey.addComponent(TimeUUIDUtils.getUniqueTimeUUIDinMillis(),HFactoryHelper.uuidSerializer);

mutator.addInsertion("my row key",
                     "my CF",
                      HFactory.createColumn
                (compKey,"my column value",
                 new CompositeSerializer()
                , HFactoryHelper.stringSerializer
                )
             );

我已经发现了问题所在。如果行键为,则
键\u验证\u类
必须为TimeUUIDType。插入函数如下所示

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);
    }