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