Skip to content

Commit 6c24bd0

Browse files
author
Nate Kupp
committed
Add docstring for emr_pyspark_resource
Test Plan: docs only Reviewers: max, alangenfeld, sashank Reviewed By: sashank Differential Revision: https://dagster.phacility.com/D2026
1 parent 708af82 commit 6c24bd0

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

  • python_modules/libraries/dagster-aws/dagster_aws/emr

python_modules/libraries/dagster-aws/dagster_aws/emr/resources.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020

2121
class EmrPySparkResource(PySparkResourceDefinition):
22+
'''See the docstring on `emr_pyspark_resource` for instructions on using this resource.
23+
'''
24+
2225
def __init__(self, config):
2326
self.config = config
2427
self.emr_job_runner = EmrJobRunner(region=self.config['region_name'])
@@ -230,6 +233,45 @@ def running_on_emr(self):
230233
}
231234
)
232235
def emr_pyspark_resource(init_context):
236+
'''EMR Pyspark Resource.
237+
238+
The EMR pyspark resource provides the capability to run pyspark code transparently, without any
239+
code changes, across both your local machine and EMR. This is as straightforward as the
240+
following:
241+
242+
.. code-block:: python
243+
244+
from dagster import ModeDefinition, pipeline
245+
from dagster_aws.emr import emr_pyspark_resource
246+
from dagster_pyspark import pyspark_resource, pyspark_solid
247+
248+
@pyspark_solid
249+
def example_solid(context):
250+
list_p = [('John', 19), ('Jennifer', 29), ('Adam', 35), ('Henry', 50)]
251+
rdd = context.resources.pyspark.spark_context.parallelize(list_p)
252+
res = rdd.take(2)
253+
for name, age in res:
254+
context.log.info('%s: %d' % (name, age))
255+
256+
@pipeline(
257+
mode_defs=[
258+
ModeDefinition('prod', resource_defs={'pyspark': emr_pyspark_resource}),
259+
ModeDefinition('local', resource_defs={'pyspark': pyspark_resource}),
260+
]
261+
)
262+
def example_pipe():
263+
example_solid()
264+
265+
When running locally, this will use the standard pyspark resource, which will bring up Spark
266+
locally and execute your code. In "prod" mode, for each pyspark solid, the EMR resource will:
267+
268+
1. Sync your code to a zip file on S3, including a code-generated `main.py` to kickstart
269+
execution;
270+
2. If a requirements.txt file is present (or specified via resource configuration), Python
271+
requirements will be installed on EMR prior to job execution;
272+
3. An EMR job will be constructed for the solid and execution invoked. Job logs will be
273+
retrieved and logged if configured via `wait_for_logs`.
274+
'''
233275
emr_pyspark = EmrPySparkResource(init_context.resource_config)
234276
try:
235277
yield emr_pyspark

0 commit comments

Comments
 (0)