Cassandra没有检索到正确的整数值 [英] Cassandra is not retrieving the correct integer value
问题描述
我使用的是cql 3.0.0
我已执行查询:
code> INSERT INTO emp(empID,deptID,first_name,last_name)
VALUES(104,15,'jane','smith')
在检索此记录时,我获得以下值:
empid = h
deptid =(blank value)
first_name ='jane'
last_name ='smith'
在搜索它时,我发现h等同于utf-8字符104. utf-8中的15也是空白。
(参考链接: http:/ /www.utf8-chartable.de/unicode-utf8-table.pl?utf8=dec&unicodeinhtml=dec )
我已设置列类型在创建表期间,但在检索我没有获得int值。
如何获取正确的值被检索。我不想要utf-8的值。
感谢
我使用cassandra 1.2.4
下面是我的代码写在phpcassa:
require_once(__ DIR__。 /../lib/autoload.php');
使用phpcassa\Connection\ConnectionPool;
使用phpcassa\ColumnFamily;
使用phpcassa\SystemManager;
使用phpcassa\Schema\StrategyClass;
使用cassandra\Compression;
使用cassandra\ConsistencyLevel;
$ pool = new ConnectionPool(prod,array('X.X.X.X','X.X.X.X'));
$ raw = $ pool-> get();
$ rows = $ raw-> client-> set_cql_version(3.0.0);
$ rows = $ raw-> client-> execute_cql3_query('USE prod;',Compression :: NONE,ConsistencyLevel :: ONE);
$ rows = $ raw-> client-> execute_cql3_query('CREATE TABLE emp(
empID int,
deptID int,
first_name varchar,
last_name varchar ,
PRIMARY KEY(empID,deptID));
',Compression :: NONE,ConsistencyLevel :: ONE);
$ rows = $ raw-> client-> execute_cql3_query('INSERT INTO emp(empID,deptID,first_name,last_name)
VALUES(104,15, \\'jane \',\'smith\');
',Compression :: NONE,ConsistencyLevel :: ONE);
$ rows = $ raw-> client-> execute_cql3_query('SELECT * FROM emp WHERE empID IN(2,104)ORDER BY deptID ASC;',Compression :: NONE,ConsistencyLevel :: ONE);
echo< pre>;
print_r($ rows);
echo< pre>;
生成的输出是:
cassandra\CqlRow Object
(
[key] =>
[columns] => Array
(
[0 ] => cassandra\Column对象
(
[name] => empid
[value] => h
[timestamp] =>
[ttl] =>
)
[1] => cassandra\Column对象
(
[name] => deptid
[value] =>
[timestamp] =>
[ttl] =>
)
[2] => cassandra\Column对象
(
[name] => first_name
[value] => jane
[timestamp] =>
[ttl] =>
)
[3] => cassandra\Column Object
(
[name] => last_name
[value] => smith
[timestamp] =>
[ttl] = >
)
)
)
虽然有点晚的答案,但我拼命寻找解决方案,同时为Yii框架编写我自己的cassandra包装。我想出了类似下面的类,消除了不正确的二进制到不同的数据类型在cassandra包括整数类型的问题:
Yii :: import('ext.phpcassa.autoload');
require_once('protected / extensions / phpcassa / autoload.php');
使用phpcassa\Connection\ConnectionPool;
使用phpcassa\ColumnFamily;
使用phpcassa\ColumnSlice;
使用phpcassa\SystemManager;
使用phpcassa\Schema\StrategyClass;
使用phpcassa\Schema\DataType;
class ACassandraConnection extends CApplicationComponent {
protected $ _pool = null;
public $ keyspace = null;
public $ servers = null;
/ **
*建立到cassandra集群的连接
* @return object
* /
私有函数_get_raw(){
if ($ this-> _pool === null){
$ this-> _pool = new ConnectionPool($ this-> keyspace,$ this-> servers);
}
return $ this-> _pool-> get();
}
public function cql_query($ query){
$ raw = $ this-> _get_raw();
$ cql_result = $ raw-> client-> execute_cql3_query($ query,cassandra\Compression :: NONE,cassandra\ ConsistencyLevel :: ONE);
$ this-> _pool-> return_connection($ raw);
return $ cql_result;
}
public function cql_get_rows($ cql_result){
if($ cql_result-> type == 1){
$ rows = array
foreach($ cql_result-> rows as $ rowIndex => $ cqlRow){
$ cols = array();
foreach($ cqlRow-> columns as $ colIndex => $ column){
$ type = DataType :: get_type_for($ cql_result-> schema-> value_types [$ column-&名称]);
$ cols [$ column-> name] = $ type-> unpack($ column-> value);
}
$ rows [] = $ cols;
}
return $ rows;
} else {
return null;
}
}
/ **
*执行垃圾回收
* /
public function __destruct(){
if($ this-> _pool!== null){
$ this-> _pool-> close();
}
}
}
I am using cql 3.0.0
I have executed the query:
INSERT INTO emp (empID, deptID, first_name, last_name)
VALUES (104, 15, 'jane', 'smith')
On retrieving this record, I get the following values:
empid = h
deptid = (blank value)
first_name = 'jane'
last_name = 'smith'
On searching for it, I found that h is equivalent to utf-8 character 104. Also 15 in utf-8 is blank. (Reference Link: http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=dec&unicodeinhtml=dec )
I have set the column types to int during create table, but on retrieving I am not getting the int values.
How do I get the correct values to be retrieved. I do not want the utf-8 values.
Thanks
I am using cassandra 1.2.4
Below is my code written in phpcassa:
require_once(__DIR__.'/../lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;
use cassandra\Compression;
use cassandra\ConsistencyLevel;
$pool = new ConnectionPool("prod",array('X.X.X.X','X.X.X.X'));
$raw = $pool->get();
$rows = $raw->client->set_cql_version("3.0.0");
$rows = $raw->client->execute_cql3_query('USE prod;', Compression::NONE, ConsistencyLevel::ONE );
$rows = $raw->client->execute_cql3_query('CREATE TABLE emp (
empID int,
deptID int,
first_name varchar,
last_name varchar,
PRIMARY KEY (empID, deptID));
', Compression::NONE, ConsistencyLevel::ONE );
$rows = $raw->client->execute_cql3_query('INSERT INTO emp (empID, deptID, first_name, last_name)
VALUES (104, 15, \'jane\', \'smith\');
', Compression::NONE, ConsistencyLevel::ONE );
$rows = $raw->client->execute_cql3_query('SELECT * FROM emp WHERE empID IN (2,104) ORDER BY deptID ASC;', Compression::NONE, ConsistencyLevel::ONE );
echo "<pre>";
print_r($rows);
echo "<pre>";
The output generated is:
cassandra\CqlRow Object
(
[key] =>
[columns] => Array
(
[0] => cassandra\Column Object
(
[name] => empid
[value] => h
[timestamp] =>
[ttl] =>
)
[1] => cassandra\Column Object
(
[name] => deptid
[value] =>
[timestamp] =>
[ttl] =>
)
[2] => cassandra\Column Object
(
[name] => first_name
[value] => jane
[timestamp] =>
[ttl] =>
)
[3] => cassandra\Column Object
(
[name] => last_name
[value] => smith
[timestamp] =>
[ttl] =>
)
)
)
Though a bit late answer, but I was desperately searching for the solution while writing my own cassandra-wrapper for Yii framework. I came up with something like the following class that eliminates the problem of incorrect binary to different data types in cassandra including integer types:
Yii::import('ext.phpcassa.autoload');
require_once('protected/extensions/phpcassa/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;
use phpcassa\Schema\DataType;
class ACassandraConnection extends CApplicationComponent {
protected $_pool = null;
public $keyspace = null;
public $servers = null;
/**
* Establish connection to cassandra cluster
* @return object
*/
private function _get_raw() {
if ($this->_pool === null) {
$this->_pool = new ConnectionPool($this->keyspace, $this->servers);
}
return $this->_pool->get();
}
public function cql_query($query) {
$raw = $this->_get_raw();
$cql_result = $raw->client->execute_cql3_query($query, cassandra\Compression::NONE, cassandra\ConsistencyLevel::ONE);
$this->_pool->return_connection($raw);
return $cql_result;
}
public function cql_get_rows($cql_result) {
if ($cql_result->type == 1) {
$rows = array();
foreach ($cql_result->rows as $rowIndex => $cqlRow) {
$cols = array();
foreach ($cqlRow->columns as $colIndex => $column) {
$type = DataType::get_type_for($cql_result->schema->value_types[$column->name]);
$cols[$column->name] = $type->unpack($column->value);
}
$rows[] = $cols;
}
return $rows;
} else {
return null;
}
}
/**
* Perform garbage collection
*/
public function __destruct() {
if($this->_pool !== null) {
$this->_pool->close();
}
}
}
这篇关于Cassandra没有检索到正确的整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!