-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapReducePhase.php
77 lines (69 loc) · 2.11 KB
/
MapReducePhase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace riiak;
use \CComponent;
/**
* The MapReducePhase holds information about a Map or Reduce phase
* in a MapReduce operation.
* @package riiak
*/
class MapReducePhase extends CComponent {
/**
* @var string map|reduce
*/
public $type;
/**
* @var mixed String or array
*/
public $language;
/**
* @var string javascript|erlang
*/
public $function;
/**
* @var bool Whether to return phase output in results
*/
public $keep;
/**
* @var mixed Additional value for map/reduce function
*/
public $arg;
/**
* Construct a MapReducePhase object.
*
* @param string $type map|reduce
* @param mixed $function String or array
* @param string $language javascript|erlang
* @param bool $keep Whether to return phase output in results
* @param mixed $arg Additional value for map/reduce function
*/
public function __construct($type, $function, $language, $keep, $arg) {
$this->type = $type;
$this->function = $function;
$this->language = $language;
$this->keep = $keep;
$this->arg = $arg;
}
/**
* Convert the MapReducePhase to an associative array. Used internally.
*
* @return array
*/
public function toArray() {
$stepdef = array('keep' => $this->keep,
'language' => $this->language,
'arg' => $this->arg);
if ($this->language == 'javascript' && is_array($this->function)) {
$stepdef['bucket'] = $this->function[0];
$stepdef['key'] = $this->function[1];
} else if ($this->language == 'javascript' && is_string($this->function)) {
if (strpos($this->function, '{') == FALSE)
$stepdef['name'] = $this->function;
else
$stepdef['source'] = $this->function;
} else if ($this->language == 'erlang' && is_array($this->function)) {
$stepdef['module'] = $this->function[0];
$stepdef['function'] = $this->function[1];
}
return array(($this->type) => $stepdef);
}
}