public function finalize($finalize)
{
switch ($this->query['type']) {
case Query::TYPE_MAP_REDUCE:
$this->query['mapReduce']['options']['finalize'] = $finalize;
break;
case Query::TYPE_GROUP:
$this->query['group']['options']['finalize'] = $finalize;
break;
default:
throw new BadMethodCallException('mapReduce(), map() or group() must be called before finalize()');
}
return $this;
}