/** * @param string $content Text content or path to file in local file system * @param string $filePath * @return mixed * @throws \Exception */ public function writeToFile($content, $filePath) { if (is_file($content)) { return $this->exec('put', array($content, $filePath)); } if (!is_string($content) && method_exists($content, '__toString')) { $content = $content->__toString(); } if (is_string($content)) { return $this->shell->exec('printf "' . str_replace('"', '\\"', str_replace('\\', '\\\\', $content)) . '" | %hadoop% dfs -put', array('-', $filePath)); } throw new \Exception(sprintf('Invalid content type "%s"', is_object($content) ? get_class($content) : gettype($content))); }
/** * @return \Phadoop\MapReduce\Job */ public function run() { $this->assertCacheDirIsSet(); $this->assertMapperIsSet(); $this->assertReducerIsSet(); $this->getCodeGenerator()->generateScript($this->mapper, $this->cacheDir . '/Mapper.php'); $this->getCodeGenerator()->generateScript($this->reducer, $this->cacheDir . '/Reducer.php'); $jobParams = array($this->getHadoopStreamingJarPath(), '-D mapred.output.compress=false'); foreach ($this->streamingOptions as $option => $value) { $jobParams[] = "-D {$option}={$value}"; } $jobParams = array_merge($jobParams, array('input' => $this->name . '/tasks/*', 'output' => $this->name . '/results', 'mapper' => $this->cacheDir . '/Mapper.php', 'reducer' => $this->cacheDir . '/Reducer.php')); if ($this->hasCombiner()) { $this->getCodeGenerator()->generateScript($this->combiner, $this->cacheDir . '/Combiner.php'); $jobParams['combiner'] = $this->cacheDir . '/Combiner.php'; } /** * @todo Populate mapper, reducer, combiner & other code to all Hadoop nodes */ $this->shell->exec('jar', $jobParams); $this->rememberResults(); return $this; }