thobbs / phpcassa

PHP client library for Apache Cassandra
thobbs.github.com/phpcassa
MIT License
248 stars 78 forks source link

Issue #83: Column metadata not recognized with composite keys #84

Closed lafka closed 12 years ago

lafka commented 12 years ago

Possible fix for https://github.com/thobbs/phpcassa/issues/83.

All pack/unpack should use the same mechanisms to query col_type_dict but i have not changed anything except what's strictly needed.

Im not sure about ColumnFamily::get_data_type_for_col(); as it is never used, should it be removed?

ColumnFamily::pack_value serializes col name directly based on is_scalar() and seems to work fine.

Would like to hear some feedback if this is the correct way fix this issue.

thobbs commented 12 years ago

Thank you very much for the detailed ticket and pull request! I really appreciate it.

You're very close to understanding what's breaking. The col_type_dict uses the packed (thrift serialized) column name as the keys. Functions calling pack_value() and unpack_value() should pass in the raw, serialized version of the column name. The problem is that some functions are using the unpacked column names. Additionally, pack_value() and unpack_value() have some code in them to handle the wrong (unpacked) version of the column names (the is_scalar() check), which is very misleading.

I'm pretty familiar with how this code works, so I can finish it from here, unless you really want to try to finish it. If you do, I suggest using phpunit and running the tests under test/Autopacking.

thobbs commented 12 years ago

Alright, should be fixed now. Let me know if you still see any problems. Thanks!

lafka commented 12 years ago

Cheers :)

Sorry for not replying earlier but have been stuck with a huge backlog recently.

lafka commented 12 years ago

There still seems to be a problem when querying indexed composite columns:

Fix in pull request §88 (193a197b)

// usage: php bin/index-lookup.php <keyspace> <comp1:comp2:compN> <value>
$indexCol = false !== strpos($argv[3], ':') ? explode(':', $argv[3]) : $argv[3];

$pool = new ConnectionPool($argv[1], array('cassie1'));
$cf   = new ColumnFamily($pool, $argv[2]);
$cf->insert_format = ColumnFamily::ARRAY_FORMAT;
$cf->return_format = ColumnFamily::ARRAY_FORMAT;

$predicate  = array(
    new IndexExpression($indexCol, $argv[4]),
);

$constraint = new IndexClause($predicate);

$rows = $cf->get_indexed_slices($constraint);

$ret = array();

foreach ($rows as $col) {
    printf("row-key: %s\r\n", implode('-', $col[0]));
    for ($i = 0, $c = count($col[1]); $i < $c; $i++) {
        printf("%-20s -> %s\r\n", implode(':', $col[1][$i][0]), $col[1][$i][1]);

    }
    echo "\r\n";

}