case 'lte': $operator = cassandra_IndexOperator::LTE; break; case 'lt': $operator = cassandra_IndexOperator::LT; break; default: // Invalid operator break; } $arr_index_expression[] = CassandraUtil::create_index_expression($index_name, $column_value, $operator); $no_index_expression++; } $index_clause = CassandraUtil::create_index_clause($arr_index_expression, '', $nb_rows); $time_start = microtime(true); $result = $column_family->get_indexed_slices($index_clause); $time_end = microtime(true); $vw_row_vars['is_super_cf'] = $column_family->cfdef->column_type == 'Super'; $vw_row_vars['is_counter_column'] = $column_family->cfdef->default_validation_class == 'org.apache.cassandra.db.marshal.CounterColumnType'; $vw_vars['results_secondary_index'] = ''; $vw_vars['results'] = ''; $nb_results = 0; foreach ($result as $key => $value) { $vw_row_vars['key'] = $key; $vw_row_vars['value'] = $value; $vw_row_vars['keyspace_name'] = $keyspace_name; $vw_row_vars['columnfamily_name'] = $columnfamily_name; $vw_row_vars['show_actions_link'] = false; $vw_vars['results_secondary_index'] .= getHTML('columnfamily_browse_data_row.php', $vw_row_vars); $nb_results++; }
public function test_get_indexed_slices() { $this->require_opp(); $indexed_cf = new ColumnFamily($this->pool, 'Indexed1'); $indexed_cf->truncate(); $columns = array('birthdate' => 1); foreach (range(1, 3) as $i) { $indexed_cf->insert('key' . $i, $columns); } $expr = new IndexExpression($column_name = 'birthdate', $value = 1); $clause = new IndexClause(array($expr), 10000); $result = $indexed_cf->get_indexed_slices($clause); $count = 0; foreach ($result as $key => $cols) { $count++; $this->assertEquals($columns, $cols); $this->assertEquals($key, "key{$count}"); } $this->assertEquals($count, 3); # Insert and remove a matching row at the beginning $indexed_cf->insert('key0', $columns); $indexed_cf->remove('key0'); # Insert and remove a matching row at the end $indexed_cf->insert('key4', $columns); $indexed_cf->remove('key4'); # Remove a matching row from the middle $indexed_cf->remove('key2'); $result = $indexed_cf->get_indexed_slices($clause); $count = 0; foreach ($result as $key => $cols) { $count++; $this->assertContains($key, array("key1", "key3")); } $this->assertEquals($count, 2); $indexed_cf->truncate(); $keys = array(); foreach (range(1, 1000) as $i) { $indexed_cf->insert("key{$i}", $columns); if ($i % 50 != 0) { $indexed_cf->remove("key{$i}"); } else { $keys[] = "key{$i}"; } } $count = 0; foreach ($result as $key => $cols) { $count++; $this->assertContains($key, $keys); unset($keys[$key]); } $this->assertEquals($count, 20); $indexed_cf->truncate(); }
public function test_get_indexed_slices() { $cf = new ColumnFamily($this->pool, 'Indexed1'); $cf->insert_format = ColumnFamily::ARRAY_FORMAT; $cf->return_format = ColumnFamily::ARRAY_FORMAT; $cols = array(array('birthdate', 1), array('col', 'val')); $rows = array(array(self::$KEYS[0], $cols), array(self::$KEYS[1], $cols), array(self::$KEYS[2], $cols)); $cf->batch_insert($rows); $expr = new IndexExpression('birthdate', 1); $clause = new IndexClause(array($expr)); $result = iterator_to_array($cf->get_indexed_slices($clause)); // usort($rows, array("ArrayFormatCFTest", "sort_rows")); usort($result, array("ArrayFormatCFTest", "sort_rows")); $this->assertEquals($rows, $result); }