Skip to content

Commit

Permalink
Revert "Enhance demo notebook and Cell component for Spark output han…
Browse files Browse the repository at this point in the history
…dling"

This reverts commit 0a10aba.
  • Loading branch information
xuwenyihust committed Dec 10, 2024
1 parent 192195c commit 992bbb5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 43 deletions.
108 changes: 93 additions & 15 deletions examples/[email protected]/demo.ipynb
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
{
"cells": [
{
"cell_type": "markdown",
"isExecuted": true,
"metadata": {},
"source": [
"# Demo Notebook\n",
"\n",
"- This is just a demo notebook\n",
"- For testing only"
]
},
{
"cell_type": "code",
"isExecuted": true,
"lastExecutionResult": "success",
"lastExecutionTime": "2024-12-10 03:35:10",
"lastExecutionTime": "2024-12-10 03:27:50",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -47,7 +36,7 @@
"<pyspark.sql.session.SparkSession at 0x7fffe2dc9ed0>"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -57,7 +46,7 @@
"from pyspark.sql import SparkSession\n",
"\n",
"spark = SparkSession.builder\\\n",
" .appName(\"spark-1733801710265\")\\\n",
" .appName(\"spark-1733801270245\")\\\n",
" .master(\"spark://spark-master:7077\")\\\n",
" .config(\"spark.jars.packages\", \"io.delta:delta-spark_2.12:3.0.0\")\\\n",
" .config(\"spark.sql.extensions\", \"io.delta.sql.DeltaSparkSessionExtension\")\\\n",
Expand All @@ -76,12 +65,101 @@
"spark\n"
]
},
{
"cell_type": "markdown",
"isExecuted": true,
"metadata": {},
"source": [
"# Demo Notebook\n",
"\n",
"- This is just a demo notebook\n",
"- For testing only"
]
},
{
"cell_type": "code",
"execution_count": null,
"isExecuted": false,
"lastExecutionResult": "success",
"lastExecutionTime": "2024-08-04 15:29:17",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div style=\"border: 1px solid #e8e8e8; padding: 10px;\">\n",
" <h3>Spark Session Information</h3>\n",
" <p><strong>Application ID:</strong> app-20240804152430-0000</p>\n",
" <p><strong>Spark UI:</strong> <a href=\"http://localhost:18080/history/app-20240804152430-0000\">http://localhost:18080/history/app-20240804152430-0000</a></p>\n",
" </div>\n",
" "
],
"text/plain": [
"Custom Spark Session (App ID: app-20240804152430-0000) - UI: http://66eef2d0ade3:4040"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# SparkSession is already defined in `spark` variable\n",
"spark"
]
},
{
"cell_type": "code",
"execution_count": 1,
"isExecuted": false,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'a' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ma\u001b[49m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m2233666777888\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mNameError\u001b[0m: name 'a' is not defined"
]
}
],
"source": [
"print(a + \"2233666777888\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"isExecuted": false,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"66\n",
"77\n"
]
}
],
"source": [
"print(66)\n",
"print(77)"
]
},
{
"cell_type": "code",
"execution_count": null,
"isExecuted": false,
"metadata": {},
"outputs": [],
"source": []
"source": [
"spark.stop()"
]
}
],
"metadata": {
Expand Down
38 changes: 10 additions & 28 deletions webapp/src/components/notebook/content/cell/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import TextResult from './result/TextResult';
import ErrorResult from './result/ErrorResult';
import CodeResult from './result/CodeResult';
import DisplayResult from './result/DisplayResult';
import SparkOutputBox from './result/SparkOutputBox';


function Cell({
Expand Down Expand Up @@ -86,32 +85,6 @@ function Cell({
}
}

const renderOutput = (output) => {
let OutputComponent;

if (output.output_type === OutputType.STREAM) {
OutputComponent = TextResult;
} else if (output.output_type === OutputType.ERROR) {
OutputComponent = ErrorResult;
} else if (output.output_type === OutputType.EXECUTE_RESULT ||
output.output_type === OutputType.DISPLAY_DATA) {
if (output.data && output.data['text/html'] &&
(output.data['text/html'].includes('SparkSession') ||
output.data['text/html'].includes('Spark Session Information'))) {
return (
<SparkOutputBox>
<DisplayResult output={output} />
</SparkOutputBox>
);
}
OutputComponent = DisplayResult;
} else {
OutputComponent = CodeResult;
}

return <OutputComponent output={output} />;
};

return (
<div>
<div style={{ display: 'flex', justifyContent: 'flex-start' }}
Expand Down Expand Up @@ -177,7 +150,16 @@ function Cell({
</div>

{cell.outputs && cell.outputs.length > 0 && cell.outputs.map((output, index) =>
renderOutput(output)
output.output_type === OutputType.EXECUTE_RESULT ?
TextResult(output) :
(output.output_type === OutputType.ERROR ? (
ErrorResult(index, isFocused, output)
) : (output.output_type === OutputType.STREAM ? (
CodeResult(index, output)
) : (output.output_type === OutputType.DISPLAY_DATA ? (
DisplayResult(output)
) : null))
)
)}
</div>
)
Expand Down

0 comments on commit 992bbb5

Please sign in to comment.