2

I'm trying to get data from Cassandra with this query:

$cf=new ColumnFamily($data->cp,'ips');
$index[]=CassandraUtil::create_index_expression('c',1,'EQ');
$index[]=CassandraUtil::create_index_expression('begin_ip',1599147740,'GTE');
$index[]=CassandraUtil::create_index_expression('end_ip',1599147740,'LTE');
$index_clause = CassandraUtil::create_index_clause($index);
$rows=$cf->get_indexed_slices($index_clause);
foreach($rows AS $key=>$row)
{
    $result[]=$row;
}
var_dump($result);

But the result is null. I'm definitely sure that there is a row in cf ips which absolutely answers this query.

Validation class for all columns is IntegerType.

In cassandra-cli the equal query:

get ips where c = int('1') and 
    begin_ip <= int('1599147740') and
    end_ip >= int('1599147740');

also gets null.

What am I doing wrong?

Anthony
  • 12,177
  • 9
  • 69
  • 105
Undrooleek
  • 223
  • 4
  • 12

1 Answers1

3

First, have you created an index on the 'c' column?

Second, you'll need to use 'cassandra_IndexOperator::EQ' and similar for the expression operator instead of a string.

Tyler Hobbs
  • 6,872
  • 24
  • 31
  • Yes 'c' column has an index. I tried so. Now the query works too long more than my send_time_out(60 000 ms)/recv_time_out(60 000 ms) period and that all causes an exceptions `Error performing get_indexed_slices on localhost:9160: exception 'cassandra_TimedOutException` and in the end of a query `Uncaught exception 'MaxRetriesException' with message 'An attempt to execute get_indexed_slices failed 6 times. The last error was cassandra_TimedOutException:` Why so happens? – Undrooleek Nov 25 '11 at 14:27
  • the CF has almost 3 millions of rows with 4 columns in each – Undrooleek Nov 25 '11 at 14:34
  • Is the value of 'c' always 1, meaning all 3 million rows match? – Tyler Hobbs Nov 25 '11 at 19:31
  • yes, im specially added this column with this value to be able to use with EQ operator also other operators – Undrooleek Nov 26 '11 at 23:44
  • That's a very inefficient query, then. You should look at storing your 'ip' numbers as column names, and get a slice of columns instead of using a secondary index. – Tyler Hobbs Nov 27 '11 at 04:17
  • is there a limit on a number of columns in a one row? – Undrooleek Nov 27 '11 at 09:03
  • mmm, but that means that i wont be able to use any operators(such as <,>,=)directly in a query? – Undrooleek Nov 27 '11 at 09:10
  • The limit on the number of columns is 2 billion, but you should try to keep rows much smaller than that. – Tyler Hobbs Nov 27 '11 at 19:21
  • You can use <, >, = operators, they will just be on column names. You can get a slice (a range) of columns from a row based on their names; remember that columns are stored in sorted order by their names. This article should give you some ideas about what the queries will look like and how to model your data: http://rubyscale.com/2011/basic-time-series-with-cassandra/ – Tyler Hobbs Nov 27 '11 at 19:23
  • i changed a structure of my CF with the recomendations that you said.trying to insert data and sometimes get such error `Error performing batch_mutate on localhost:9160: exception 'TTransportException' with message 'TSocket: Could not write 19863863 bytes localhost:9160'` – Undrooleek Nov 28 '11 at 13:01
  • You shouldn't write 19MB in a single request. At the most, keep it under 10MB per request. – Tyler Hobbs Nov 28 '11 at 20:08
  • `$index[]=CassandraUtil::create_index_expression(1,1); $index_clause = CassandraUtil::create_index_clause($index); $rows=$cf->get_indexed_slices($index_clause,null,3673688270,3673688670);` causes 500 server internal error with error in lighttpd log - **2011-12-04 20:41:46: (mod_fastcgi.c.3356) response not received, request sent: 843 on socket: unix:/tmp/php.socket-7 for /data/getData.php?, closing connection.** The same error appears when when im using get_range with the same quering by $column_start and $column_finish – Undrooleek Dec 04 '11 at 17:48
  • maybe i am wrong, but i think that is strange when so powerfull db as cassandra can't do the query which was a reason for this topic: to select data between two clauses – Undrooleek Dec 04 '11 at 21:16
  • ...or i just need try to built my db schema with another conception according to cassandra features which completely differs from other db – Undrooleek Dec 04 '11 at 21:21