Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __debug_bin
.idea/
.DS_Store
.swp
.venv
*~

# Python cache files
Expand Down
190 changes: 190 additions & 0 deletions examples/spark/spark_job.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "04811973",
"metadata": {},
"source": [
"<!--\n",
"Copyright The Kubeflow Authors.\n",
"\n",
"Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"you may not use this file except in compliance with the License.\n",
"You may obtain a copy of the License at\n",
"\n",
"http://www.apache.org/licenses/LICENSE-2.0\n",
"\n",
"Unless required by applicable law or agreed to in writing, software\n",
"distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"-->"
]
},
{
"cell_type": "markdown",
"id": "a9138435",
"metadata": {},
"source": [
"# Spark Batch Job Example\n",
"\n",
"The notebook walks through the following steps:\n",
"\n",
"- Create a Spark session.\n",
"- Create a sample DataFrame.\n",
"- Apply a simple transformation.\n",
"- Display the results.\n",
"- Compute summary statistics.\n",
"- Stop the Spark session."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "425cb2b5",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"from pyspark.sql import SparkSession\n",
"from pyspark.sql.functions import col"
]
},
{
"cell_type": "markdown",
"id": "b556d547",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"source": [
"## Create a Spark Session\n",
"\n",
"Create a Spark session that will be used to execute the example."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edc8006e",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"spark = SparkSession.builder.appName(\n",
" \"KubeflowSparkExample\"\n",
").getOrCreate()"
]
},
{
"cell_type": "markdown",
"id": "beb30ac6",
"metadata": {},
"source": [
"## Create a DataFrame\n",
"\n",
"Create a small DataFrame containing integers and compute the square of each value."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1a5e19e1",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"df = spark.range(10).withColumn(\"square\", col(\"id\") * col(\"id\"))"
]
},
{
"cell_type": "markdown",
"id": "fb926d44",
"metadata": {},
"source": [
"## Display the DataFrame"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "acd0752d",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"print(\"Input DataFrame:\")\n",
"df.show()"
]
},
{
"cell_type": "markdown",
"id": "e9d53ba9",
"metadata": {},
"source": [
"## Compute Summary Statistics"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1eb8438",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"count = df.count()\n",
"total = df.agg({\"square\": \"sum\"}).collect()[0][0]\n",
"\n",
"print(f\"Row count: {count}\")\n",
"print(f\"Sum of squares: {total}\")"
]
},
{
"cell_type": "markdown",
"id": "df932d3d",
"metadata": {},
"source": [
"## Stop the Spark Session\n",
"\n",
"Release the Spark resources after the example finishes."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "802518dd",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"spark.stop()"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
36 changes: 0 additions & 36 deletions examples/spark/spark_job.py

This file was deleted.