|
25 | 25 | ] |
26 | 26 | }, |
27 | 27 | { |
| 28 | + "attachments": {}, |
28 | 29 | "cell_type": "markdown", |
29 | 30 | "metadata": {}, |
30 | 31 | "source": [ |
|
43 | 44 | "\n", |
44 | 45 | "This notebook provides Apache Spark operations for customers by bridging the existing local PySpark workflows with cloud based capabilities. Data scientists can use their familiar local environments with JupyterLab and work with remote data and remote clusters simply by selecting a kernel. The operations that will be demonstrated are: how to use the interactive Spark environment and produce a Spark script; how to prepare and create an application; how to prepare and create a run; how to list existing dataflow applications; and how to retrieve and display the logs.\n", |
45 | 46 | "\n", |
46 | | - "The purpose of the `dataflow` module is to provide an efficient and convenient way for users to launch a Spark application and run Spark jobs. The interactive Spark kernel provides a simple and efficient way to edit and build your Spark script, and easy access to read from OCI Object Storage.\n", |
| 47 | + "The interactive Spark kernel provides a simple and efficient way to edit and build your Spark script, and easy access to read from OCI Object Storage.\n", |
47 | 48 | "\n", |
48 | | - "Compatible conda pack: [PySpark 2.4 and Data Flow](https://docs.oracle.com/iaas/data-science/using/conda-pyspark-fam.htm) for CPU on Python 3.7 (version 3.0)\n", |
| 49 | + "Compatible conda pack: [PySpark 3.2 and Data Flow](https://docs.oracle.com/iaas/data-science/using/conda-pyspark-fam.htm) for CPU on Python 3.8 (version 2.0)\n", |
49 | 50 | "\n", |
50 | 51 | "---\n", |
51 | 52 | "\n", |
|
71 | 72 | "metadata": {}, |
72 | 73 | "outputs": [], |
73 | 74 | "source": [ |
74 | | - "import io\n", |
75 | 75 | "import matplotlib.pyplot as plt\n", |
76 | 76 | "import os\n", |
77 | 77 | "import pandas as pd\n", |
78 | | - "import tempfile\n", |
79 | | - "import uuid\n", |
80 | 78 | "\n", |
81 | | - "from ads.dataflow.dataflow import DataFlow\n", |
82 | | - "from os import path\n", |
83 | 79 | "from pyspark.sql import SparkSession" |
84 | 80 | ] |
85 | 81 | }, |
86 | 82 | { |
| 83 | + "attachments": {}, |
87 | 84 | "cell_type": "markdown", |
88 | 85 | "metadata": {}, |
89 | 86 | "source": [ |
|
111 | 108 | ] |
112 | 109 | }, |
113 | 110 | { |
| 111 | + "attachments": {}, |
114 | 112 | "cell_type": "markdown", |
115 | 113 | "metadata": {}, |
116 | 114 | "source": [ |
117 | | - "Load the Employee Attrition data file from Oracle Cloud Infrastructure Object Storage into an Apache Spark DataFrame" |
| 115 | + "Load the Employee Attrition data file from Oracle Cloud Infrastructure Object Storage into an Apache Spark DataFrame. You can configure your `core-site.xml` for accessing to Object Storage by `odsc core-site config` command. Running `odsc core-site config -h` in terminal to see the usage." |
118 | 116 | ] |
119 | 117 | }, |
120 | 118 | { |
|
137 | 135 | ] |
138 | 136 | }, |
139 | 137 | { |
| 138 | + "attachments": {}, |
140 | 139 | "cell_type": "markdown", |
141 | 140 | "metadata": {}, |
142 | 141 | "source": [ |
|
153 | 152 | ] |
154 | 153 | }, |
155 | 154 | { |
| 155 | + "attachments": {}, |
156 | 156 | "cell_type": "markdown", |
157 | 157 | "metadata": {}, |
158 | 158 | "source": [ |
|
194 | 194 | ] |
195 | 195 | }, |
196 | 196 | { |
| 197 | + "attachments": {}, |
197 | 198 | "cell_type": "markdown", |
198 | 199 | "metadata": {}, |
199 | 200 | "source": [ |
|
210 | 211 | ] |
211 | 212 | }, |
212 | 213 | { |
| 214 | + "attachments": {}, |
213 | 215 | "cell_type": "markdown", |
214 | 216 | "metadata": {}, |
215 | 217 | "source": [ |
|
239 | 241 | ] |
240 | 242 | }, |
241 | 243 | { |
| 244 | + "attachments": {}, |
242 | 245 | "cell_type": "markdown", |
243 | 246 | "metadata": {}, |
244 | 247 | "source": [ |
|
275 | 278 | ] |
276 | 279 | }, |
277 | 280 | { |
| 281 | + "attachments": {}, |
278 | 282 | "cell_type": "markdown", |
279 | 283 | "metadata": {}, |
280 | 284 | "source": [ |
281 | 285 | "Note: other compression formats Data Flow supports today include snappy parquet (example above) and gzip on both csv and parquet." |
282 | 286 | ] |
283 | 287 | }, |
284 | 288 | { |
| 289 | + "attachments": {}, |
285 | 290 | "cell_type": "markdown", |
286 | 291 | "metadata": {}, |
287 | 292 | "source": [ |
288 | | - "We have come to a query that we want to run in Data Flow from previous explorations. Please refer to the dataflow.ipynb on how to submit a job to dataflow" |
289 | | - ] |
290 | | - }, |
291 | | - { |
292 | | - "cell_type": "code", |
293 | | - "execution_count": null, |
294 | | - "metadata": {}, |
295 | | - "outputs": [], |
296 | | - "source": [ |
297 | | - "dataflow_base_folder = tempfile.mkdtemp()\n", |
298 | | - "data_flow = DataFlow(dataflow_base_folder=dataflow_base_folder)\n", |
299 | | - "print(\"Data flow directory: {}\".format(dataflow_base_folder))" |
300 | | - ] |
301 | | - }, |
302 | | - { |
303 | | - "cell_type": "code", |
304 | | - "execution_count": null, |
305 | | - "metadata": {}, |
306 | | - "outputs": [], |
307 | | - "source": [ |
308 | | - "pyspark_file_path = path.join(\n", |
309 | | - " dataflow_base_folder, \"example-{}.py\".format(str(uuid.uuid4())[-6:])\n", |
310 | | - ")\n", |
311 | | - "script = '''\n", |
312 | | - "from pyspark.sql import SparkSession\n", |
313 | | - "\n", |
314 | | - "def main():\n", |
315 | | - " \n", |
316 | | - " # Create a Spark session\n", |
317 | | - " spark = SparkSession \\\\\n", |
318 | | - " .builder \\\\\n", |
319 | | - " .appName(\"Python Spark SQL basic example\") \\\\\n", |
320 | | - " .getOrCreate()\n", |
321 | | - " \n", |
322 | | - " # Load a csv file from dataflow public storage\n", |
323 | | - " df = spark \\\\\n", |
324 | | - " .read \\\\\n", |
325 | | - " .format(\"csv\") \\\\\n", |
326 | | - " .option(\"header\", \"true\") \\\\\n", |
327 | | - " .option(\"multiLine\", \"true\") \\\\\n", |
328 | | - " .load(\"oci://hosted-ds-datasets@bigdatadatasciencelarge/synthetic/orcl_attrition.csv\")\n", |
329 | | - " \n", |
330 | | - " # Create a temp view and do some SQL operations\n", |
331 | | - " df.createOrReplaceTempView(\"emp_attrition\")\n", |
332 | | - " query_result_df = spark.sql(\"\"\"\n", |
333 | | - " SELECT \n", |
334 | | - " Age,\n", |
335 | | - " MonthlyIncome,\n", |
336 | | - " YearsInIndustry\n", |
337 | | - " FROM emp_attrition \n", |
338 | | - " \"\"\")\n", |
339 | | - " \n", |
340 | | - " # Convert the filtered Apache Spark DataFrame into JSON format\n", |
341 | | - " # Note: we are writing to the Spark stdout log so that we can retrieve the log later at the end of the notebook.\n", |
342 | | - " print('\\\\n'.join(query_result_df.toJSON().collect()))\n", |
343 | | - " \n", |
344 | | - "if __name__ == '__main__':\n", |
345 | | - " main()\n", |
346 | | - "'''\n", |
347 | | - "\n", |
348 | | - "with open(pyspark_file_path, \"w\") as f:\n", |
349 | | - " print(script.strip(), file=f)\n", |
350 | | - "\n", |
351 | | - "print(\"Script path: {}\".format(pyspark_file_path))" |
352 | | - ] |
353 | | - }, |
354 | | - { |
355 | | - "cell_type": "code", |
356 | | - "execution_count": null, |
357 | | - "metadata": {}, |
358 | | - "outputs": [], |
359 | | - "source": [ |
360 | | - "script_bucket = \"test\" # Update the value\n", |
361 | | - "logs_bucket = \"dataflow-log\" # Update the value\n", |
362 | | - "display_name = \"sample_Data_Flow_app\"\n", |
363 | | - "\n", |
364 | | - "app_config = data_flow.prepare_app(\n", |
365 | | - " display_name=display_name,\n", |
366 | | - " script_bucket=script_bucket,\n", |
367 | | - " pyspark_file_path=pyspark_file_path,\n", |
368 | | - " logs_bucket=logs_bucket,\n", |
369 | | - ")\n", |
370 | | - "\n", |
371 | | - "app = data_flow.create_app(app_config)\n", |
372 | | - "\n", |
373 | | - "run_display_name = \"sample_Data_Flow_run\"\n", |
374 | | - "run_config = app.prepare_run(run_display_name=run_display_name)\n", |
375 | | - "\n", |
376 | | - "run = app.run(run_config, save_log_to_local=True)" |
377 | | - ] |
378 | | - }, |
379 | | - { |
380 | | - "cell_type": "code", |
381 | | - "execution_count": null, |
382 | | - "metadata": {}, |
383 | | - "outputs": [], |
384 | | - "source": [ |
385 | | - "run.status" |
386 | | - ] |
387 | | - }, |
388 | | - { |
389 | | - "cell_type": "code", |
390 | | - "execution_count": null, |
391 | | - "metadata": {}, |
392 | | - "outputs": [], |
393 | | - "source": [ |
394 | | - "run.config" |
395 | | - ] |
396 | | - }, |
397 | | - { |
398 | | - "cell_type": "code", |
399 | | - "execution_count": null, |
400 | | - "metadata": {}, |
401 | | - "outputs": [], |
402 | | - "source": [ |
403 | | - "run.oci_link" |
| 293 | + "<a id='df_app'></a>\n", |
| 294 | + "## Create a Data Flow application\n", |
| 295 | + "`oracle-ads` provides different ways to submit your code to Data Flow for workloads that require larger resources. To learn more, read the [user guide](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/apachespark/dataflow.html#)." |
404 | 296 | ] |
405 | 297 | }, |
406 | 298 | { |
| 299 | + "attachments": {}, |
407 | 300 | "cell_type": "markdown", |
408 | 301 | "metadata": {}, |
409 | 302 | "source": [ |
|
0 commit comments