Skip to content

Instantly share code, notes, and snippets.

@qpleple
Created August 20, 2015 16:30
Show Gist options
  • Save qpleple/68fd6b93893cf4be6cd8 to your computer and use it in GitHub Desktop.
Save qpleple/68fd6b93893cf4be6cd8 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import boto\n",
"from boto.emr.step import HiveStep\n",
"from boto.s3.key import Key\n",
"import pystache\n",
"\n",
"emr = boto.emr.connect_to_region('eu-west-1')\n",
"bucket = boto.connect_s3().get_bucket('short-edition-big-data', validate=False)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"hql = u\"\"\"CREATE EXTERNAL TABLE IF NOT EXISTS table_02 (col_1 STRING, col_2 STRING)\n",
" ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' \n",
" LOCATION 's3://short-edition-big-data/emr/runs/{{exp_name}}/table-02';\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CREATE EXTERNAL TABLE IF NOT EXISTS table_02 (col_1 STRING, col_2 STRING)\n",
" ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' \n",
" LOCATION 's3://short-edition-big-data/emr/runs/dummy/table-02';\n"
]
}
],
"source": [
"hive_script = pystache.render(hql, {'exp_name': 'dummy'})\n",
"print hive_script"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"205"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Key(bucket, name=\"/emr/scripts/test-step.hql\").set_contents_from_string(hive_script)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"step = HiveStep(\n",
" name=\"Test de step Hive\",\n",
" hive_file=\"s3://short-edition-big-data/emr/scripts/test-step.hql\",\n",
" hive_versions='latest',\n",
" hive_args=None\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<boto.emr.emrobject.JobFlowStepList at 0x107a1b7d0>"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"emr.add_jobflow_steps(\"j-3SIKYPKV5G6SE\", step)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment