From 992bbb5a5e6cf6d6e30fcb79d8a9c2e176588a1c Mon Sep 17 00:00:00 2001 From: Wenyi Xu Date: Tue, 10 Dec 2024 12:11:23 +0800 Subject: [PATCH] Revert "Enhance demo notebook and Cell component for Spark output handling" This reverts commit 0a10abaff5e5e3576a1549b7e310422e152356f0. --- examples/user_0@gmail.com/demo.ipynb | 108 +++++++++++++++--- .../components/notebook/content/cell/Cell.js | 38 ++---- 2 files changed, 103 insertions(+), 43 deletions(-) diff --git a/examples/user_0@gmail.com/demo.ipynb b/examples/user_0@gmail.com/demo.ipynb index a4a633b..9fb949e 100644 --- a/examples/user_0@gmail.com/demo.ipynb +++ b/examples/user_0@gmail.com/demo.ipynb @@ -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": [ { @@ -47,7 +36,7 @@ "" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -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", @@ -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", + "
\n", + "

Spark Session Information

\n", + "

Application ID: app-20240804152430-0000

\n", + "

Spark UI: http://localhost:18080/history/app-20240804152430-0000

\n", + "
\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": { diff --git a/webapp/src/components/notebook/content/cell/Cell.js b/webapp/src/components/notebook/content/cell/Cell.js index b322991..0014156 100644 --- a/webapp/src/components/notebook/content/cell/Cell.js +++ b/webapp/src/components/notebook/content/cell/Cell.js @@ -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({ @@ -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 ( - - - - ); - } - OutputComponent = DisplayResult; - } else { - OutputComponent = CodeResult; - } - - return ; - }; - return (
{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)) + ) )}
)