{"id":1364,"date":"2024-11-06T15:43:33","date_gmt":"2024-11-06T07:43:33","guid":{"rendered":"https:\/\/blog.humh.cn\/?p=1364"},"modified":"2025-02-10T11:18:52","modified_gmt":"2025-02-10T03:18:52","slug":"1364","status":"publish","type":"post","link":"https:\/\/blog.humh.cn\/?p=1364","title":{"rendered":"Zeppelin\u591aparagraph\u95f4\u53d8\u91cf\u4f20\u9012"},"content":{"rendered":"\n<p>Zeppelin \u7684\u4e00\u4e2a notebook \u4e2d\u6709\u5f88\u591a paragraph \u90fd\u662f spark \u89e3\u91ca\u5668\u7c7b\u578b\u3002zeppelin \u5b9a\u65f6\u8fd0\u884c\u65f6\uff0c\u4ed6\u4eec\u4f1a\u5728\u4e00\u4e2a spark session \u4e2d\uff0c\u6240\u4ee5 Zeppelin \u652f\u6301\u4e0a\u9762\u5df2\u8fd0\u884c\u7684 paragraph \u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u5728\u4e0b\u9762\u5373\u5c06\u8fd0\u884c\u7684 <meta charset=\"utf-8\">paragraph \u4e2d\u53ef\u7528\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"397\" height=\"269\" class=\"wp-image-1365 lazyload\" title=\"Zeppelin\u591aparagraph\u95f4\u53d8\u91cf\u4f20\u9012\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106150252862.png\" alt=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106150252862.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106150252862.png 794w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106150252862-300x203.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106150252862-768x520.png 768w\" sizes=\"(max-width: 397px) 100vw, 397px\"><\/figure>\n\n\n\n<p>\u4f46\u4e0a\u56fe\u60c5\u51b5\u5c40\u9650\u4e8e\u7b2c\u4e00\u4e2a\u770b\u677f\u8fd0\u884c\u6210\u529f\u65f6\u53d8\u91cf a \u624d\u4f1a\u88ab\u5b9a\u4e49\uff0c\u5426\u5219\u4e0b\u65b9\u7b2c\u4e8c\u4e2a\u770b\u677f\u65e0\u6cd5\u5f97\u77e5\u53d8\u91cf a\u3002\u5177\u4f53\u60c5\u51b5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>\u4e0a\u9762\u672a\u8fd0\u884c\uff1a\u53d8\u91cf\u672a\u5b9a\u4e49<\/li><li>\u4e0a\u9762\u8fd0\u884c\u8fc7\u7b2c\u4e00\u904d\u4f46\u5931\u8d25\u6216\u629b\u5f02\u5e38\uff1a\u53d8\u91cf\u672a\u5b9a\u4e49<\/li><li>\u4e0a\u9762\u8fd0\u884c\u6210\u529f\uff1a\u53d8\u91cf\u6b63\u5e38<\/li><li>\u540c\u4e00\u4e2a session \u7b2c\u4e00\u6b21\u6210\u529f\u7b2c\u4e8c\u6b21\u5931\u8d25\uff08\u5982 spark session \u672a\u5931\u6548\u671f\u95f4\u770b\u677f\u91cd\u8bd5\uff09\uff1a\u53d8\u91cf\u4e3a\u7b2c\u4e00\u6b21\u8fd0\u884c\u65f6\u5b9a\u4e49\u7684\u503c<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"388\" height=\"330\" class=\"wp-image-1366 lazyload\" title=\"Zeppelin\u591aparagraph\u95f4\u53d8\u91cf\u4f20\u9012\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106151007856.png\" alt=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106151007856.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106151007856.png 776w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106151007856-300x255.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106151007856-768x653.png 768w\" sizes=\"(max-width: 388px) 100vw, 388px\"><\/figure>\n\n\n\n<p>\u5982\u4e0a\u56fe\u5c31\u662f\u4e0a\u65b9\u770b\u677f\u8fd0\u884c\u5931\u8d25\u5bfc\u81f4\u53d8\u91cf\u672a\u5b9a\u4e49\uff0c\u4e0b\u65b9\u770b\u677f\u65e0\u6cd5\u4f7f\u7528\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6709\u8fd9\u4e48\u4e00\u4e2a\u573a\u666f\uff1a\u6574\u4e2a notebook \u914d\u7f6e\u4e86\u5b9a\u65f6\u8fd0\u884c\uff0cZeppelin \u4f1a\u5728\u9884\u671f\u65f6\u523b\u4ece\u4e0a\u81ea\u4e0b\u7684\u987a\u5e8f\u4f9d\u6b21\u8fd0\u884c\u6bcf\u4e00\u4e2a <meta charset=\"utf-8\">paragraph\uff0c\u5982\u679c\u5176\u4e2d\u4e00\u4e2a <meta charset=\"utf-8\">paragraph \u5931\u8d25\uff0cZeppelin \u4ecd\u4f1a\u7ee7\u7eed\u6267\u884c\u8be5 notebook \u5269\u4e0b <meta charset=\"utf-8\">paragraph\u3002\u8fd9\u91cc\u5e0c\u671b\u6700\u540e\u4e00\u4e2a\u770b\u677f\u5185\u901a\u8fc7\u4ee3\u7801\u5224\u65ad\u51fa\u4e0a\u65b9\u6240\u6709\u770b\u677f\u662f\u5426\u90fd\u8fd0\u884c\u6210\u529f\uff0c\u628a\u5931\u8d25\u7684 <meta charset=\"utf-8\">paragraph \u53d1\u6d88\u606f\u544a\u8b66\u51fa\u6765\uff0c\u90a3\u4e48\u60f3\u5230\u53ef\u4ee5\u901a\u8fc7\u201c\u6bcf\u4e2a <meta charset=\"utf-8\">paragraph \u5b9a\u4e49\u4e00\u4e2a\u72b6\u6001\u53d8\u91cf\uff0c\u6700\u540e\u4e00\u4e2a <meta charset=\"utf-8\">paragraph \u53bb\u5224\u65ad\u6bcf\u4e2a <meta charset=\"utf-8\">paragraph \u5b9a\u4e49\u7684\u53d8\u91cf\u6765\u5b8c\u6210\u201d\u3002\u4f46\u8fd9\u5c31\u6709\u4e2a\u95ee\u9898\u4e86\uff0c\u5982\u679c\u4e0a\u9762 <meta charset=\"utf-8\">paragraph \u5931\u8d25\u4e86\uff0c\u72b6\u6001\u53d8\u91cf\u4f1a\u662f\u672a\u5b9a\u4e49\u7684\u72b6\u6001\uff0c\u6700\u540e\u4e00\u4e2a <meta charset=\"utf-8\">paragraph \u4f1a\u62a5\u4e0a\u56fe\u7f16\u8bd1\u65f6\u5f02\u5e38\uff0c\u800c\u4e0d\u4f1a\u8fd0\u884c\u6210\u529f\u3002<\/p>\n\n\n\n<p>SparkZeppelinContext \u662f Apache Zeppelin \u4e2d\u7684\u4e00\u4e2a\u7c7b\uff0c\u5b83\u6269\u5c55\u4e86 org.apache.spark.repl.SparkIMain\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e9b\u989d\u5916\u7684\u529f\u80fd\uff0c\u4ee5\u4fbf\u5728 Zeppelin \u73af\u5883\u4e2d\u66f4\u597d\u5730\u4e0e Spark \u8fdb\u884c\u4ea4\u4e92\u3002\u4ee5\u4e0b\u662f SparkZeppelinContext \u7684\u4e3b\u8981\u529f\u80fd\u548c\u7528\u9014\uff1a<\/p>\n\n\n\n<h3>\u4e3b\u8981\u529f\u80fd<\/h3>\n\n\n\n<ol><li>\u53d8\u91cf\u7ba1\u7406\uff1a<br>SparkZeppelinContext \u63d0\u4f9b\u4e86\u65b9\u6cd5\u6765\u7ba1\u7406\u548c\u5171\u4eab\u53d8\u91cf\uff0c\u4f7f\u5f97\u5728\u4e0d\u540c\u7684\u6bb5\u843d\uff08paragraph\uff09\u4e4b\u95f4\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f20\u9012\u548c\u4f7f\u7528\u53d8\u91cf\u3002<\/li><li>\u89e3\u91ca\u5668\u96c6\u6210\uff1a<br>\u5b83\u4e0e Zeppelin \u7684 Spark \u89e3\u91ca\u5668\u7d27\u5bc6\u96c6\u6210\uff0c\u63d0\u4f9b\u4e86\u5bf9 Spark \u4f1a\u8bdd\u7684\u66f4\u7ec6\u7c92\u5ea6\u7684\u63a7\u5236\u3002<\/li><li>\u65e5\u5fd7\u548c\u8f93\u51fa\u7ba1\u7406\uff1a<br>\u63d0\u4f9b\u4e86\u65b9\u6cd5\u6765\u7ba1\u7406\u65e5\u5fd7\u548c\u8f93\u51fa\uff0c\u4f7f\u5f97\u5728 Zeppelin \u4e2d\u8fd0\u884c Spark \u4ee3\u7801\u65f6\u80fd\u591f\u66f4\u597d\u5730\u63a7\u5236\u8f93\u51fa\u5185\u5bb9\u3002<\/li><li>\u52a8\u6001\u7c7b\u52a0\u8f7d\uff1a<br>\u652f\u6301\u52a8\u6001\u52a0\u8f7d\u7c7b\uff0c\u8fd9\u5bf9\u4e8e\u5728 Zeppelin \u4e2d\u8fdb\u884c\u4ea4\u4e92\u5f0f\u5f00\u53d1\u975e\u5e38\u6709\u7528\u3002<\/li><\/ol>\n\n\n\n<h3>\u4e3b\u8981\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b SparkZeppelinContext \u4e2d\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ol><li>put(name: String, v: Any)\uff1a<br>\u5c06\u4e00\u4e2a\u53d8\u91cf\u653e\u5165\u4e0a\u4e0b\u6587\u4e2d\uff0c\u4f7f\u5176\u5728\u5176\u4ed6\u6bb5\u843d\u4e2d\u53ef\u7528\u3002<br><code data-enlighter-language=\"scala\" class=\"EnlighterJSRAW\">z.put(\"myVariable\", \"Hello, World!\")<\/code><\/li><li>get(name: String): Option[Any]\uff1a<br>\u4ece\u4e0a\u4e0b\u6587\u4e2d\u83b7\u53d6\u4e00\u4e2a\u53d8\u91cf\u3002<br><code data-enlighter-language=\"scala\" class=\"EnlighterJSRAW\">val myVariable = z.get(\"myVariable\")<\/code><\/li><li>remove(name: String)\uff1a<br>\u4ece\u4e0a\u4e0b\u6587\u4e2d\u79fb\u9664\u4e00\u4e2a\u53d8\u91cf<br><code data-enlighter-language=\"scala\" class=\"EnlighterJSRAW\">z.remove(\"myVariable\")<\/code><\/li><li>clear()\uff1a<br>\u6e05\u9664\u4e0a\u4e0b\u6587\u4e2d\u7684\u6240\u6709\u53d8\u91cf\u3002<br><code data-enlighter-language=\"scala\" class=\"EnlighterJSRAW\">z.clear()<\/code><\/li><li>&#8230;<\/li><\/ol>\n\n\n\n<p>\u901a\u8fc7 SparkZeppelinContext\uff0c\u53ef\u4ee5\u5728 Zeppelin \u4e2d\u66f4\u7075\u6d3b\u5730\u7ba1\u7406\u548c\u4f7f\u7528\u53d8\u91cf\uff0c\u4ece\u800c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u5982\u4e0b\u56fe\u6240\u793a\u53ef\u5b8c\u6210\u6211\u8fd9\u91cc\u7684\u9700\u6c42<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"438\" height=\"346\" class=\"wp-image-1369 lazyload\" title=\"Zeppelin\u591aparagraph\u95f4\u53d8\u91cf\u4f20\u9012\" src=\"data:image\/gif;base64,R0lGODlhAgABAIAAALGxsQAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==\" data-src=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106152542717.png\" alt=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106152542717.png\" data-srcset=\"https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106152542717.png 876w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106152542717-300x237.png 300w, https:\/\/file.blog.humh.cn\/wp-content\/uploads\/2024\/11\/20241106152542717-768x607.png 768w\" sizes=\"(max-width: 438px) 100vw, 438px\"><\/figure>\n\n\n\n<p>\u540c\u65f6\u53d8\u91cf\u4f9d\u65e7\u4ec5\u5728\u8be5 notebook \u7684 sparkSession \u4e2d\u6709\u6548\u3002<\/p>\n\n\n\n<p>\u9664\u4e86 <meta charset=\"utf-8\">SparkZeppelinContext \u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528 Spark \u7684\u5e7f\u64ad\u53d8\u91cf\uff0c\u4e0d\u8fc7\u5b83\u901a\u5e38\u662f\u5728\u591a\u4e2a\u6bb5\u843d\u4e2d\u5171\u4eab\u4e00\u4e2a\u8f83\u5927\u7684\u6570\u636e\u7ed3\u6784\u65f6\u4f7f\u7528\u3002\u5927\u81f4\u4f7f\u7528\u59ff\u52bf\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"scala\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u7b2c\u4e00\u4e2a\u6bb5\u843d\n%spark\nimport org.apache.spark.broadcast.Broadcast\n\nval data = Array(1, 2, 3, 4, 5)\nval broadcastVar: Broadcast[Array[Int]] = sc.broadcast(data)\n\n\/\/ \u7b2c\u4e8c\u4e2a\u6bb5\u843d\n%spark\nval data = broadcastVar.value\nprintln(data.mkString(\", \"))\n<\/pre>\n\n\n\n<p>\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u518d\u505a\u7814\u7a76\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Zeppelin \u7684\u4e00\u4e2a notebook \u4e2d\u6709\u5f88\u591a paragraph \u90fd\u662f spark \u89e3\u91ca\u5668\u7c7b\u578b\u3002zep [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[129],"tags":[130,135],"_links":{"self":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1364"}],"collection":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1364"}],"version-history":[{"count":3,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1364\/revisions"}],"predecessor-version":[{"id":1401,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/1364\/revisions\/1401"}],"wp:attachment":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}