| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
4 |
*
|
|
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
6 |
* You may not use this file except in compliance with the License.
|
|
|
7 |
* A copy of the License is located at
|
|
|
8 |
*
|
|
|
9 |
* http://aws.amazon.com/apache2.0
|
|
|
10 |
*
|
|
|
11 |
* or in the "license" file accompanying this file. This file is distributed
|
|
|
12 |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
13 |
* express or implied. See the License for the specific language governing
|
|
|
14 |
* permissions and limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
/*%******************************************************************************************%*/
|
|
|
19 |
// CLASS
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Contains core functionality for Hadoop helpers.
|
|
|
23 |
*
|
|
|
24 |
* @version 2011.05.03
|
|
|
25 |
* @license See the included NOTICE.md file for more information.
|
|
|
26 |
* @copyright See the included NOTICE.md file for more information.
|
|
|
27 |
* @link http://aws.amazon.com/php/ PHP Developer Center
|
|
|
28 |
* @link http://hadoop.apache.org Apache Hadoop
|
|
|
29 |
*/
|
|
|
30 |
class CFHadoopBase
|
|
|
31 |
{
|
|
|
32 |
/**
|
|
|
33 |
* Runs a specified script on the master node of your cluster.
|
|
|
34 |
*
|
|
|
35 |
* @param string $script (Required) The script to run with `script-runner.jar`.
|
|
|
36 |
* @param array $args (Optional) An indexed array of arguments to pass to the script.
|
|
|
37 |
* @return array A standard array that is intended to be passed into a <CFStepConfig> object.
|
|
|
38 |
*/
|
|
|
39 |
public static function script_runner($script, $args = null)
|
|
|
40 |
{
|
|
|
41 |
if (!$args) $args = array();
|
|
|
42 |
array_unshift($args, $script);
|
|
|
43 |
|
|
|
44 |
return array(
|
|
|
45 |
'Jar' => 's3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar',
|
|
|
46 |
'Args' => $args
|
|
|
47 |
);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Prepares a Hive or Pig script before passing it to the script runner.
|
|
|
52 |
*
|
|
|
53 |
* @param string $type (Required) The type of script to run. [Allowed values: `hive`, `pig`].
|
|
|
54 |
* @param array $args (Optional) An indexed array of arguments to pass to the script.
|
|
|
55 |
* @return array A standard array that is intended to be passed into a <CFStepConfig> object.
|
|
|
56 |
* @link http://hive.apache.org Apache Hive
|
|
|
57 |
* @link http://pig.apache.org Apache Pig
|
|
|
58 |
*/
|
|
|
59 |
public static function hive_pig_script($type, $args = null)
|
|
|
60 |
{
|
|
|
61 |
if (!$args) $args = array();
|
|
|
62 |
$args = is_array($args) ? $args : array($args);
|
|
|
63 |
$args = array_merge(array('--base-path', 's3://us-east-1.elasticmapreduce/libs/' . $type . '/'), $args);
|
|
|
64 |
|
|
|
65 |
return self::script_runner('s3://us-east-1.elasticmapreduce/libs/' . $type . '/' . $type . '-script', $args);
|
|
|
66 |
}
|
|
|
67 |
}
|