hadoopbase.class.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // CLASS
  18. /**
  19. * Contains core functionality for Hadoop helpers.
  20. *
  21. * @version 2011.05.03
  22. * @license See the included NOTICE.md file for more information.
  23. * @copyright See the included NOTICE.md file for more information.
  24. * @link http://aws.amazon.com/php/ PHP Developer Center
  25. * @link http://hadoop.apache.org Apache Hadoop
  26. */
  27. class CFHadoopBase
  28. {
  29. /**
  30. * Runs a specified script on the master node of your cluster.
  31. *
  32. * @param string $script (Required) The script to run with `script-runner.jar`.
  33. * @param array $args (Optional) An indexed array of arguments to pass to the script.
  34. * @return array A standard array that is intended to be passed into a <CFStepConfig> object.
  35. */
  36. public static function script_runner($script, $args = null)
  37. {
  38. if (!$args) $args = array();
  39. array_unshift($args, $script);
  40. return array(
  41. 'Jar' => 's3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar',
  42. 'Args' => $args
  43. );
  44. }
  45. /**
  46. * Prepares a Hive or Pig script before passing it to the script runner.
  47. *
  48. * @param string $type (Required) The type of script to run. [Allowed values: `hive`, `pig`].
  49. * @param array $args (Optional) An indexed array of arguments to pass to the script.
  50. * @return array A standard array that is intended to be passed into a <CFStepConfig> object.
  51. * @link http://hive.apache.org Apache Hive
  52. * @link http://pig.apache.org Apache Pig
  53. */
  54. public static function hive_pig_script($type, $args = null)
  55. {
  56. if (!$args) $args = array();
  57. $args = is_array($args) ? $args : array($args);
  58. $args = array_merge(array('--base-path', 's3://us-east-1.elasticmapreduce/libs/' . $type . '/'), $args);
  59. return self::script_runner('s3://us-east-1.elasticmapreduce/libs/' . $type . '/' . $type . '-script', $args);
  60. }
  61. }