1: <?php
2: namespace phpcassa\Iterator;
3:
4: use phpcassa\Schema\DataType\Serialized;
5:
6: 7: 8: 9: 10: 11:
12: class IndexedColumnFamilyIterator extends ColumnFamilyIterator {
13:
14: private $index_clause;
15:
16: public function __construct($column_family, $index_clause, $buffer_size,
17: $column_parent, $predicate,
18: $read_consistency_level) {
19:
20: $this->index_clause = $index_clause;
21:
22: $row_count = $index_clause->count;
23: $orig_start_key = $index_clause->start_key;
24:
25: parent::__construct($column_family, $buffer_size, $row_count,
26: $orig_start_key, $column_parent, $predicate,
27: $read_consistency_level);
28: }
29:
30: protected function get_buffer() {
31:
32: $buff_sz = $this->buffer_size;
33: if($this->row_count !== null) {
34: if ($this->buffer_number == 0 && $this->row_count <= $buff_sz) {
35:
36: $buff_sz = $this->row_count;
37: } else {
38: $buff_sz = min($this->row_count - $this->rows_seen + 1, $this->buffer_size);
39: }
40: }
41:
42:
43:
44: if ($this->buffer_number >= 1) {
45: $buff_sz = max($buff_sz, 2);
46: }
47:
48: $this->expected_page_size = $buff_sz;
49: $this->index_clause->count = $buff_sz;
50: $this->buffer_number++;
51:
52: if (is_string($this->next_start_key) && $this->column_family->key_type instanceof Serialized) {
53: $handle_serialize = true;
54: } else {
55: $handle_serialize = false;
56: }
57: $this->index_clause->start_key = $this->column_family->pack_key($this->next_start_key, $handle_serialize);
58: $resp = $this->column_family->pool->call("get_indexed_slices",
59: $this->column_parent, $this->index_clause, $this->predicate,
60: $this->read_consistency_level);
61:
62: $this->current_buffer = $this->column_family->keyslices_to_array($resp);
63: $this->current_page_size = count($this->current_buffer);
64: }
65: }
66:
67: