使用aws-php-sdk将参数传递给hive脚本


Pass parameters to hive script using aws php sdk

我正试图使用php-sdk在AWS EMR上运行一个配置单元脚本。如何传递脚本参数(例如,输入、输出和要处理的日期)?

感谢

如果您也在为此而挣扎。。。

将变量传递到配置单元脚本的示例代码可以在以下亚马逊论坛线程

中找到

我已经用Java SDK完成了这项工作,使用PHP SDK基本上你需要做的是用add_job_flow_steps函数解析你想要的参数

调用函数时,需要将参数添加到"Args"数组中的StepConfig(用于正在运行的脚本)中。

Args - string|array - Optional - A list of command line arguments passed to the JAR file’s main function when executed. Pass a string for a single value, or an indexed array for multiple values.

参数的格式有点混乱,您需要有一个形式的数组

("-d","yourVariable=itsValue","-d"anotherVariable=AnotherValue")

所以它最终应该看起来有点像这样:

 add_job_flow_steps('j-19430859jg9',array( new CFStepConfig(array(
'Name' => 'Run a hive script',
'HadoopJarStep' => array( 'Jar' => CFHadoopStep::run_hive_script(),
'Args' => array("-d","yourVariable=itsValue","-d","anotherVariable=AnotherValue")
))))

我不知道语法是否正确,我还没有尝试过。

至少对于java是这样的,也许对于PHP你可能需要一个关联数组,我会尝试各种格式。

我希望这是为了使这些参数不会与其他hadoop/hive配置参数混淆。

然后,您可以使用${yourVariable}以类似于bash的方式访问脚本中的这些变量。

SELECT * FROM TABLE WHERE column='${yourVariable};