thobbs / phpcassa

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

Multiget super column leaves out super column level from result array #110

Closed fono closed 11 years ago

fono commented 11 years ago

I am trying to fetch supercolumns' subcolumns. Please see reproduction steps below:

cassandra-cli:

create column family phpcassa_super_test with column_type = 'Super' and comparator = TimeUUIDType;
set phpcassa_super_test[utf8(test_key)][timeuuid(c2c01600-1dd6-11b2-801f-7f46596a3869)][utf8(test_colname)] = utf8(testvalue);

Now try to fetch with phpcassa:

$connection = new \phpcassa\Connection\ConnectionPool('test_ks', array('10.0.0.1:9160'));
$testCf = new \phpcassa\SuperColumnFamily($connection, 'phpcassa_super_test');
$result = $testCf->multiget_super_column(array('test_key'), UUID::import('c2c01600-1dd6-11b2-801f-7f46596a3869'));
print_r($result);

Actual result:

Array
(
    [0] => Array
        (
            [0] => test_key
            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => test_colname
                            [1] => testvalue
                        )
                )
        )
)

Expected result:

Array
(
    [0] => Array
        (
            [0] => test_key
            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => *UUID object(c2c01600-1dd6-11b2-801f-7f46596a3869)*
                            [1] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => test_colname
                                            [1] => testvalue
                                        )
                                )
                        )
                )
        )
)

This issue affects the dictionary format as well (when not using UUID as column name of course). My phpCassa version is up to date (99125430).

thobbs commented 11 years ago

This is the expected behavior for multiget_super_column(). The methods that are specific to a single super column leave out the super column name (since you already explicitly know what it is) and just return the subcolumns. If you want to include the super column in the results, just use a normal multiget() with the super column name in the column_names() array.

fono commented 11 years ago

Thanks for the quick reply. How can I use the column_names() array for this purpose when the super column name is a UUID? I can't use array format in this case I assume.

thobbs commented 11 years ago

PHP doesn't have problems with non-scalar types as items in an array, just as keys in an array (map/dict). So you can do:

$column_names = array(UUID::import('c2c01600-1dd6-11b2-801f-7f46596a3869'));
$result = $testCf->multiget(array('test_key'), null, $column_names);
fono commented 11 years ago

Okay, I get it: it's not possible to filter subcolumns this way. I ended up using multiget_super_column() and converting the result set to the expected format (this is needed for the wrapper I use above the phpCassa layer).

Thanks for your help!