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