3

私はcql 3.0.0を使用しています

私はクエリを実行しました:

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 に設定しましたが、取得時に int 値を取得していません。

正しい値を取得するにはどうすればよいですか。utf-8 値は必要ありません。

ありがとう

カサンドラ1.2.4を使用しています

以下は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>";

生成される出力は次のとおりです。

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] => 
                            )

                    )

            )
4

2 に答える 2

2

少し遅い回答ですが、Yiiフレームワーク用の独自のcassandra-wrapperを作成しながら、必死に解決策を探していました. 次のクラスのようなものを思いつきました。これは、整数型を含むcassandraのさまざまなデータ型へのバイナリが正しくないという問題を解消します。

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

}
于 2013-05-15T17:16:43.260 に答える