Overview

Namespaces

  • cassandra
  • None
  • PHP
  • phpcassa
    • Batch
    • Connection
    • Index
    • Iterator
    • Schema
      • DataType
    • Util
    • UUID

Classes

  • ColumnFamilyIterator
  • IndexedColumnFamilyIterator
  • RangeColumnFamilyIterator
  • RangeTokenColumnFamilyIterator
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace phpcassa\Iterator;
 3: 
 4: use phpcassa\Schema\DataType\Serialized;
 5: use cassandra\KeyRange;
 6: 
 7: /**
 8:  * Iterates over a column family row-by-row, typically with only a subset
 9:  * of each row's columns.
10:  *
11:  * @package phpcassa\Iterator
12:  */
13: class RangeTokenColumnFamilyIterator extends ColumnFamilyIterator {
14: 
15:     private $token_start;
16:     private $token_finish;
17: 
18:     public function __construct($column_family, $buffer_size,
19:                                 $tokenstart, $tokenfinish, $row_count,
20:                                 $column_parent, $predicate,
21:                                 $read_consistency_level) {
22: 
23:         // The key_start will be packed during the first get_buffer call
24:         $this->token_start  = $tokenstart;
25:         $this->token_finish = $tokenfinish;
26: 
27:         parent::__construct($column_family, $buffer_size, $row_count,
28:                             $key_start = null, $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:                 // we don't need to chunk, grab exactly the right number of rows
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:         // when fetching a second buffer or later, we have to fetch a minimum
44:         // of two rows since the first will be a repeat
45:         if ($this->buffer_number >= 1) {
46:             $buff_sz = max($buff_sz, 2);
47:         }
48: 
49:         $this->expected_page_size = $buff_sz;
50: 
51:         $key_range = new KeyRange();
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: 
58:         if ($this->buffer_number == 0){
59:             // First time use start token
60:             $key_range->start_token = $this->token_start;
61:         }else{
62:             // Next times use start ley
63:             $key_range->start_key = $this->column_family->pack_key($this->next_start_key, $handle_serialize);
64:         }
65: 
66:         // In both cases end is the final token.
67:         $key_range->end_token = $this->token_finish;
68: 
69:         $this->buffer_number++;
70:         $key_range->count = $buff_sz;
71: 
72:         $resp = $this->column_family->pool->call("get_range_slices", $this->column_parent, $this->predicate,
73:             $key_range, $this->read_consistency_level);
74: 
75:         $this->current_buffer = $this->column_family->keyslices_to_array($resp);
76:         $this->current_page_size = count($this->current_buffer);
77:     }
78: }
79: 
phpcassa API documentation generated by ApiGen 2.8.0