{"rsdb":{"rid":"309136","subhead":"","postdate":"0","aid":"224298","fid":"116","uid":"1","topic":"1","content":"
\u6b63\u5982\u5728\u4e4b\u524d\u7684\u90a3\u7bc7\u6587\u7ae0\u4e2d Spark Streaming \u8bbe\u8ba1\u539f\u7406<\/a> \u4e2d\u8bf4\u5230 Spark \u56e2\u961f\u4e4b\u540e\u5bf9 Spark Streaming \u7684\u7ef4\u62a4\u53ef\u80fd\u8d8a\u6765\u8d8a\u5c11\uff0cSpark 2.4 \u7248\u672c\u7684 Release Note<\/a> \u91cc\u9762\u679c\u7136\u4e00\u4e2a Spark Streaming \u76f8\u5173\u7684 ticket \u90fd\u6ca1\u6709\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0cStructured Streaming \u6709\u5c06\u8fd1\u5341\u4e2a ticket \u8bf4\u660e\u3002\u6240\u4ee5\u5404\u4f4d\u540c\u5b66\uff0c\u662f\u65f6\u5019\u820d\u5f03 Spark Streaming \u8f6c\u5411 Structured Streaming \u4e86\uff0c\u5f53\u7136\u7406\u7531\u5e76\u4e0d\u6b62\u4e8e\u6b64\u3002\u6211\u4eec\u8fd9\u7bc7\u6587\u7ae0\u5c31\u6765\u5206\u6790\u4e00\u4e0b Spark Streaming \u7684\u4e0d\u8db3\uff0c\u4ee5\u53caStructured Streaming \u7684\u8bbe\u8ba1\u521d\u8877\u548c\u601d\u60f3\u662f\u600e\u4e48\u6837\u7684\u3002\u6587\u7ae0\u4e3b\u8981\u53c2\u8003\u4eca\u5e74\uff082018 \u5e74\uff09sigmod \u4e0a\u9762\u7684\u8fd9\u7bc7\u8bba\u6587\uff1a *Structured Streaming: A Declarative API for Real-Time \u9996\u5148\u53ef\u4ee5\u6ce8\u610f\u5230\u7684\u4e86\u8bba\u6587\u6807\u9898\u4e2d\u7684 Declarative API<\/em><\/strong>\uff0c\u4e2d\u6587\u4e00\u822c\u53eb\u505a\u58f0\u660e\u5f0f\u7f16\u7a0b API\u3002\u4e00\u822c\u76f4\u63a5\u770b\u5230\u8fd9\u4e2a\u8bcd\u53ef\u80fd\u4e0d\u77e5\u9053\u4ec0\u4e48\u610f\u601d\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u5217\u51fa\u4ed6\u7684\u5bf9\u7acb\u5355\u8bcd\uff1aImperative API<\/em><\/strong>\uff0c\u4e2d\u6587\u4e00\u822c\u53eb\u547d\u4ee4\u5f0f\u7f16\u7a0b API\uff0c\u4eff\u4f5b\u4e00\u5207\u90fd\u660e\u4e86\u4e86\u3002\u662f\u7684\uff0c\u6ca1\u9519\uff0cDeclarative<\/em><\/strong> \u53ea\u662f\u8868\u8fbe\u51fa\u6211\u4eec\u60f3\u8981\u4ec0\u4e48\uff0c\u800c Imperative<\/em><\/strong> \u5219\u662f\u8bf4\u4e3a\u4e86\u5f97\u5230\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u505a\u54ea\u4e9b\u4e1c\u897f\u4e00\u4e2a\u4e2a\u8bf4\u660e\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u8981\u4e00\u4e2a\u7cd5\u70b9\uff0c\u53bb\u7cd5\u70b9\u5e97\u76f4\u63a5\u53bb\u5b9a\u505a\u544a\u8bc9\u5e97\u5458\u6211\u4eec\u8981\u4ec0\u4e48\u6837\u5f0f\u7684\u7cd5\u70b9\uff0c\u7136\u540e\u5e97\u5458\u53bb\u7ed9\u6211\u4eec\u505a\u51fa\u6765\uff0c\u8fd9\u5c31\u662f Declarative<\/em><\/strong>\u3002\u800c Imperative<\/em><\/strong> \u5bf9\u5e94\u7684\u5c31\u662f\u9762\u7c89\u5e97\u4e86\u3002<\/p>\n \u5728\u5f00\u59cb\u6b63\u5f0f\u4ecb\u7ecd Structured Streaming \u4e4b\u524d\u6709\u4e00\u4e2a\u95ee\u9898\u8fd8\u9700\u8981\u8bf4\u6e05\u695a\uff0c\u5c31\u662f Spark Streaming \u5b58\u5728\u54ea\u4e9b\u4e0d\u8db3\uff1f\u603b\u7ed3\u4e00\u4e0b\u4e3b\u8981\u6709\u4e0b\u9762\u51e0\u70b9\uff1a<\/p>\n \u4f7f\u7528 Processing Time \u800c\u4e0d\u662f Event Time<\/strong>\u3002\u9996\u5148\u89e3\u91ca\u4e00\u4e0b\uff0cProcessing Time \u662f\u6570\u636e\u5230\u8fbe Spark \u88ab\u5904\u7406\u7684\u65f6\u95f4\uff0c\u800c Event Time \u662f\u6570\u636e\u81ea\u5e26\u7684\u5c5e\u6027\uff0c\u4e00\u822c\u8868\u793a\u6570\u636e\u4ea7\u751f\u4e8e\u6570\u636e\u6e90\u7684\u65f6\u95f4\u3002\u6bd4\u5982 IoT \u4e2d\uff0c\u4f20\u611f\u5668\u5728 12:00:00 \u4ea7\u751f\u4e00\u6761\u6570\u636e\uff0c\u7136\u540e\u5728 12:00:05 \u6570\u636e\u4f20\u9001\u5230 Spark\uff0c\u90a3\u4e48 Event Time \u5c31\u662f 12:00:00\uff0c\u800c Processing Time \u5c31\u662f 12:00:05\u3002\u6211\u4eec\u77e5\u9053 Spark Streaming \u662f\u57fa\u4e8e DStream \u6a21\u578b\u7684 micro-batch \u6a21\u5f0f\uff0c\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u5c06\u4e00\u4e2a\u5fae\u5c0f\u65f6\u95f4\u6bb5\uff0c\u6bd4\u5982\u8bf4 1s\uff0c\u7684\u6d41\u6570\u636e\u5f53\u524d\u6279\u6570\u636e\u6765\u5904\u7406\u3002\u5982\u679c\u6211\u4eec\u8981\u7edf\u8ba1\u67d0\u4e2a\u65f6\u95f4\u6bb5\u7684\u4e00\u4e9b\u6570\u636e\u7edf\u8ba1\uff0c\u6beb\u65e0\u7591\u95ee\u5e94\u8be5\u4f7f\u7528 Event Time\uff0c\u4f46\u662f\u56e0\u4e3a Spark Streaming \u7684\u6570\u636e\u5207\u5272\u662f\u57fa\u4e8e Processing Time\uff0c\u8fd9\u6837\u5c31\u5bfc\u81f4\u4f7f\u7528 Event Time \u7279\u522b\u7684\u56f0\u96be\u3002<\/p>\n Complex, low-level api<\/strong>\u3002\u8fd9\u70b9\u6bd4\u8f83\u597d\u7406\u89e3\uff0cDStream \uff08Spark Streaming \u7684\u6570\u636e\u6a21\u578b\uff09\u63d0\u4f9b\u7684 API \u7c7b\u4f3c RDD \u7684 API \u7684\uff0c\u975e\u5e38\u7684 low level\u3002\u5f53\u6211\u4eec\u7f16\u5199 Spark Streaming \u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u672c\u8d28\u4e0a\u5c31\u662f\u8981\u53bb\u6784\u9020 RDD \u7684 DAG \u6267\u884c\u56fe\uff0c\u7136\u540e\u901a\u8fc7 Spark Engine \u8fd0\u884c\u3002\u8fd9\u6837\u5bfc\u81f4\u4e00\u4e2a\u95ee\u9898\u662f\uff0cDAG \u53ef\u80fd\u4f1a\u56e0\u4e3a\u5f00\u53d1\u8005\u7684\u6c34\u5e73\u53c2\u5dee\u4e0d\u9f50\u800c\u5bfc\u81f4\u6267\u884c\u6548\u7387\u4e0a\u7684\u5929\u58e4\u4e4b\u522b\u3002\u8fd9\u6837\u5bfc\u81f4\u5f00\u53d1\u8005\u7684\u4f53\u9a8c\u975e\u5e38\u4e0d\u597d\uff0c\u4e5f\u662f\u4efb\u4f55\u4e00\u4e2a\u57fa\u7840\u6846\u67b6\u4e0d\u60f3\u770b\u5230\u7684\uff08\u57fa\u7840\u6846\u67b6\u7684\u53e3\u53f7\u4e00\u822c\u90fd\u662f\uff1a\u4f60\u4eec\u4e13\u6ce8\u4e8e\u81ea\u5df1\u7684\u4e1a\u52a1\u903b\u8f91\u5c31\u597d\uff0c\u5176\u4ed6\u7684\u4ea4\u7ed9\u6211\uff09\u3002\u8fd9\u4e5f\u662f\u5f88\u591a\u57fa\u7840\u7cfb\u7edf\u5f3a\u8c03 Declarative<\/em><\/strong> \u7684\u4e00\u4e2a\u539f\u56e0\u3002<\/p>\n reason about end-to-end application<\/strong>\u3002\u8fd9\u91cc\u7684 end-to-end \u6307\u7684\u662f\u76f4\u63a5 input \u5230 out\uff0c\u6bd4\u5982 Kafka \u63a5\u5165 Spark Streaming \u7136\u540e\u518d\u5bfc\u51fa\u5230 HDFS \u4e2d\u3002DStream \u53ea\u80fd\u4fdd\u8bc1\u81ea\u5df1\u7684\u4e00\u81f4\u6027\u8bed\u4e49\u662f exactly-once \u7684\uff0c\u800c input \u63a5\u5165 Spark Streaming \u548c Spark Straming \u8f93\u51fa\u5230\u5916\u90e8\u5b58\u50a8\u7684\u8bed\u4e49\u5f80\u5f80\u9700\u8981\u7528\u6237\u81ea\u5df1\u6765\u4fdd\u8bc1\u3002\u800c\u8fd9\u4e2a\u8bed\u4e49\u4fdd\u8bc1\u5199\u8d77\u6765\u4e5f\u662f\u975e\u5e38\u6709\u6311\u6218\u6027\uff0c\u6bd4\u5982\u4e3a\u4e86\u4fdd\u8bc1 output \u7684\u8bed\u4e49\u662f exactly-once \u8bed\u4e49\u9700\u8981 output \u7684\u5b58\u50a8\u7cfb\u7edf\u5177\u6709\u5e42\u7b49\u7684\u7279\u6027\uff0c\u6216\u8005\u652f\u6301\u4e8b\u52a1\u6027\u5199\u5165\uff0c\u8fd9\u4e2a\u5bf9\u4e8e\u5f00\u53d1\u8005\u6765\u8bf4\u90fd\u4e0d\u662f\u4e00\u4ef6\u5bb9\u6613\u7684\u4e8b\u60c5\u3002<\/p>\n \u6279\u6d41\u4ee3\u7801\u4e0d\u7edf\u4e00<\/strong>\u3002\u5c3d\u7ba1\u6279\u6d41\u672c\u662f\u4e24\u5957\u7cfb\u7edf\uff0c\u4f46\u662f\u8fd9\u4e24\u5957\u7cfb\u7edf\u7edf\u4e00\u8d77\u6765\u786e\u5b9e\u5f88\u6709\u5fc5\u8981\uff0c\u6211\u4eec\u6709\u65f6\u5019\u786e\u5b9e\u9700\u8981\u5c06\u6211\u4eec\u7684\u6d41\u5904\u7406\u903b\u8f91\u8fd0\u884c\u5230\u6279\u6570\u636e\u4e0a\u9762\u3002\u5173\u4e8e\u8fd9\u4e00\u70b9\uff0c\u6700\u65e9\u5728 2014 \u5e74 Google \u63d0\u51fa Dataflow \u8ba1\u7b97\u670d\u52a1\u7684\u65f6\u5019\u5c31\u6279\u5224\u4e86 streaming\/batch \u8fd9\u79cd\u53eb\u6cd5\uff0c\u800c\u662f\u63d0\u51fa\u4e86 unbounded\/bounded data \u7684\u8bf4\u6cd5\u3002DStream \u5c3d\u7ba1\u662f\u5bf9 RDD \u7684\u5c01\u88c5\uff0c\u4f46\u662f\u6211\u4eec\u8981\u5c06 DStream \u4ee3\u7801\u5b8c\u5168\u8f6c\u6362\u6210 RDD \u8fd8\u662f\u6709\u4e00\u70b9\u5de5\u4f5c\u91cf\u7684\uff0c\u66f4\u4f55\u51b5\u73b0\u5728 Spark \u7684\u6279\u5904\u7406\u90fd\u7528 DataSet\/DataFrame API \u4e86\u3002<\/p>\n Structured Streaming \u5728 Spark 2.0 \u7248\u672c\u4e8e 2016 \u5e74\u5f15\u5165\uff0c\u8bbe\u8ba1\u601d\u60f3\u53c2\u8003\u5f88\u591a\u5176\u4ed6\u7cfb\u7edf\u7684\u601d\u60f3\uff0c\u6bd4\u5982\u533a\u5206 processing time \u548c event time\uff0c\u4f7f\u7528 relational \u6267\u884c\u5f15\u64ce\u63d0\u9ad8\u6027\u80fd\u7b49\u3002\u540c\u65f6\u4e5f\u8003\u8651\u4e86\u548c Spark \u5176\u4ed6\u7ec4\u4ef6\u66f4\u597d\u7684\u96c6\u6210\u3002Structured Streaming \u548c\u5176\u4ed6\u7cfb\u7edf\u7684\u663e\u8457\u533a\u522b\u4e3b\u8981\u5982\u4e0b\uff1a<\/p>\n <\/p>\n \u4e0b\u9762\u6211\u4eec\u770b\u4e00\u4e0b Structured Streaming \u7684\u6838\u5fc3\u8bbe\u8ba1\u3002<\/p>\n Input and Output<\/strong>: Structured Streaming \u5185\u7f6e\u4e86\u5f88\u591a connector \u6765\u4fdd\u8bc1 input \u6570\u636e\u6e90\u548c output sink \u4fdd\u8bc1 exactly-once \u8bed\u4e49\u3002\u800c\u5b9e\u73b0 exactly-once \u8bed\u4e49\u7684\u524d\u63d0\u662f\uff1a<\/p>\n \u53ef\u80fd\u662f\u53d7\u5230 Google Dataflow \u7684\u6279\u6d41\u7edf\u4e00\u7684\u601d\u60f3\u7684\u5f71\u54cd\uff0cStructured Streaming \u5c06\u6d41\u5f0f\u6570\u636e\u5f53\u6210\u4e00\u4e2a\u4e0d\u65ad\u589e\u957f\u7684 table\uff0c\u7136\u540e\u4f7f\u7528\u548c\u6279\u5904\u7406\u540c\u4e00\u5957 API\uff0c\u90fd\u662f\u57fa\u4e8e DataSet\/DataFrame \u7684\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u901a\u8fc7\u5c06\u6d41\u5f0f\u6570\u636e\u7406\u89e3\u6210\u4e00\u5f20\u4e0d\u65ad\u589e\u957f\u7684\u8868\uff0c\u4ece\u800c\u5c31\u53ef\u4ee5\u50cf\u64cd\u4f5c\u6279\u7684\u9759\u6001\u6570\u636e\u4e00\u6837\u6765\u64cd\u4f5c\u6d41\u6570\u636e\u4e86\u3002 \u5728\u8fd9\u4e2a\u6a21\u578b\u4e2d\uff0c\u4e3b\u8981\u5b58\u5728\u4e0b\u9762\u51e0\u4e2a\u7ec4\u6210\u90e8\u5206\uff1a<\/p>\n <\/p>\n \u4e0b\u9762\u4e3e\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\uff0cNetworkWordCount\uff0c\u4ee3\u7801\u5982\u4e0b:<\/p>\n \u4ee3\u7801\u5b9e\u9645\u6267\u884c\u6d41\u7a0b\u53ef\u4ee5\u7528\u4e0b\u56fe\u6765\u8868\u793a\u3002\u628a\u6d41\u5f0f\u6570\u636e\u5f53\u6210\u4e00\u5f20\u4e0d\u65ad\u589e\u957f\u7684 table\uff0c\u4e5f\u5c31\u662f\u56fe\u4e2d\u7684 Unbounded table of all input\u3002\u7136\u540e\u6bcf\u79d2 trigger \u4e00\u6b21\uff0c\u5728 trigger \u7684\u65f6\u5019\u5c06 query \u5e94\u7528\u5230 input table \u4e2d\u65b0\u589e\u7684\u6570\u636e\u4e0a\uff0c\u6709\u65f6\u5019\u8fd8\u9700\u8981\u548c\u4e4b\u524d\u7684\u9759\u6001\u6570\u636e\u4e00\u8d77\u7ec4\u5408\u6210\u7ed3\u679c\u3002query \u4ea7\u751f\u7684\u7ed3\u679c\u6210\u4e3a Result Table\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u5c06 Result Table \u8f93\u51fa\u5230\u5916\u90e8\u5b58\u50a8\u3002\u8f93\u51fa\u6a21\u5f0f\u6709\u4e09\u79cd\uff1a<\/p>\n <\/p>\n \u548c batch \u6a21\u5f0f\u76f8\u6bd4\uff0cstreaming \u6a21\u5f0f\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7279\u6709\u7684\u7b97\u5b50\u64cd\u4f5c\uff0c\u6bd4\u5982 window, watermark, statefaul oprator \u7b49\u3002<\/p>\n window<\/strong>\uff0c\u4e0b\u56fe\u662f\u4e00\u4e2a\u57fa\u4e8e event-time \u7edf\u8ba1 window \u5185\u4e8b\u4ef6\u7684\u4f8b\u5b50\u3002<\/p>\n \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u7a97\u53e3\u5927\u5c0f\u4e3a 10 \u5206\u949f\uff0c\u6bcf 5 \u5206\u949f trigger \u4e00\u6b21\u3002\u5728 12:11 \u65f6\u5019\u6536\u5230\u4e86\u4e00\u6761 12:04 \u7684\u6570\u636e\uff0c\u4e5f\u5c31\u662f late data \uff08\u4ec0\u4e48\u53eb late data \u5462\uff1f\u5c31\u662f Processing Time \u6bd4 Event Time \u8981\u665a\uff09\uff0c\u7136\u540e\u53bb\u66f4\u65b0\u5176\u5bf9\u5e94\u7684 Result Table \u7684\u8bb0\u5f55\u3002<\/p>\n <\/p>\n watermark<\/strong>\uff0c\u662f\u4e5f\u4e3a\u4e86\u5904\u7406 \uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\u5bf9\u4e8e\u8fd9\u79cd late data \u7684\u65f6\u6548\u6570\u636e\u5e76\u6ca1\u6709\u5fc5\u8981\u4e00\u76f4\u4fdd\u7559\u592a\u4e45\u3002\u6bd4\u5982\u8bf4\uff0c\u6570\u636e\u665a\u4e86 10 \u5206\u949f\u6216\u8005\u8fd8\u6709\u70b9\u6709\uff0c\u4f46\u662f\u665a\u4e86 1 \u4e2a\u5c0f\u65f6\u5c31\u6ca1\u6709\u7528\u4e86\uff0c\u53e6\u5916\u8fd9\u6837\u8bbe\u8ba1\u8fd8\u6709\u4e00\u4e2a\u597d\u5904\u5c31\u662f\u4e2d\u95f4\u72b6\u6001\u6ca1\u6709\u5fc5\u8981\u7ef4\u62a4\u90a3\u4e48\u591a\u3002watermark \u7684\u5f62\u5f0f\u5316\u5b9a\u4e49\u4e3a max(eventTime) - threshold\uff0c\u65e9\u4e8e watermark \u7684\u6570\u636e\u76f4\u63a5\u4e22\u5f03\u3002<\/p>\n \u7528\u4e0b\u56fe\u8868\u793a\u66f4\u52a0\u5f62\u8c61\u3002\u5728 12:15 trigger \u65f6 watermark \u4e3a 12:14 - 10m = 12:04\uff0c\u6240\u4ee5 late date (12:08, dog; 12:13, owl) \u90fd\u88ab\u63a5\u6536\u4e86\u3002\u5728 12:20 trigger \u65f6 watermark \u4e3a 12:21 - 10m = 12:11\uff0c\u6240\u4ee5 late data (12:04, donkey) \u90fd\u4e22\u5f03\u4e86\u3002<\/p>\n <\/p>\n \u9664\u6b64\u4e4b\u540e Structured Streaming \u8fd8\u63d0\u4f9b\u4e86\u7528\u6237\u53ef\u4ee5\u81ea\u5b9a\u4e49\u72b6\u6001\u8ba1\u7b97\u903b\u8f91\u7684\u7b97\u5b50\uff1a<\/p>\n \u770b\u540d\u5b57\u5927\u6982\u4e5f\u80fd\u770b\u51fa\u6765 mapGroupsWithState<\/strong> \u662f one -> one\uff0cflatMapGroupsWithState \u662f one -> multi\u3002\u8fd9\u4e24\u4e2a\u7b97\u5b50\u7684\u5e95\u5c42\u90fd\u662f\u57fa\u4e8e Spark Streaming \u7684 updateStateByKey\u3002<\/p>\n \u597d\uff0c\u7ec8\u4e8e\u8981\u4ecb\u7ecd\u5230\u201c\u771f\u6b63\u201d\u7684\u6d41\u5904\u7406\u4e86\uff0c\u6211\u4e4b\u6240\u4ee5\u8bf4\u201c\u771f\u6b63\u201d\u662f\u56e0\u4e3a continuous mode \u662f\u4f20\u7edf\u7684\u6d41\u5904\u7406\u6a21\u5f0f\uff0c\u901a\u8fc7\u8fd0\u884c\u4e00\u4e2a long-running \u7684 operator \u7528\u6765\u5904\u7406\u6570\u636e\u3002\u4e4b\u524d Spark \u662f\u57fa\u4e8e micro-batch \u6a21\u5f0f\u7684\uff0c\u5c31\u88ab\u5f88\u591a\u4eba\u8bdf\u75c5\u4e0d\u662f\u201c\u771f\u6b63\u7684\u201d\u6d41\u5f0f\u5904\u7406\u3002continuous mode \u8fd9\u79cd\u5904\u7406\u6a21\u5f0f\u53ea\u8981\u4e00\u6709\u6570\u636e\u53ef\u7528\u5c31\u4f1a\u8fdb\u884c\u5904\u7406\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002epoch \u662f input \u4e2d\u6570\u636e\u88ab\u53d1\u9001\u7ed9 operator \u5904\u7406\u7684\u6700\u5c0f\u5355\u4f4d\uff0c\u5728\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0cepoch \u7684 offset \u4f1a\u88ab\u8bb0\u5f55\u5230 wal \u4e2d\u3002\u53e6\u5916 continuous \u6a21\u5f0f\u4e0b\u7684 snapshot \u5b58\u50a8\u4f7f\u7528\u7684\u4e00\u81f4\u6027\u7b97\u6cd5\u662f Chandy-Lamport \u7b97\u6cd5\u3002<\/p>\n <\/p>\n \u8fd9\u79cd\u6a21\u5f0f\u76f8\u6bd4\u4e0e micro-batch \u6a21\u5f0f\u7f3a\u70b9\u548c\u4f18\u70b9\u90fd\u5f88\u660e\u663e\u3002<\/p>\n \u5173\u4e8e\u4e3a\u4ec0\u4e48\u5ef6\u8fdf\u66f4\u4f4e\uff0c\u4e0b\u9762\u4e24\u5e45\u56fe\u53ef\u4ee5\u505a\u5230\u4e00\u76ee\u4e86\u7136\u3002 \u5bf9\u4e8e Structured Streaming \u6765\u8bf4\uff0c\u56e0\u4e3a\u6709\u4e24\u79cd\u6a21\u5f0f\uff0c\u6240\u4ee5\u6211\u4eec\u5206\u5f00\u8ba8\u8bba\u3002<\/p>\n micro-batch<\/strong> \u6a21\u5f0f\u53ef\u4ee5\u63d0\u4f9b end-to-end \u7684 exactly-once \u8bed\u4e49\u3002\u539f\u56e0\u662f\u56e0\u4e3a\u5728 input \u7aef\u548c output \u7aef\u90fd\u505a\u4e86\u5f88\u591a\u5de5\u4f5c\u6765\u8fdb\u884c\u4fdd\u8bc1\uff0c\u6bd4\u5982 input \u7aef replayable + wal\uff0coutput \u7aef\u5199\u5165\u5e42\u7b49\u3002<\/p>\n continuous mode<\/strong> \u53ea\u80fd\u63d0\u4f9b at-least-once \u8bed\u4e49\u3002\u5173\u4e8e continuous mode \u7684\u5b98\u65b9\u8ba8\u8bba\u7684\u5b9e\u5728\u592a\u5c11\uff0c\u751a\u81f3\u53ea\u662f\u63d0\u4e86\u4e00\u4e0b\u3002\u5728\u548c @\u674e\u5448\u7965 \u8ba8\u8bba\u4e4b\u540e\u89c9\u5f97\u5e94\u8be5\u8fd8\u662f continuous mode \u7531\u4e8e\u8981\u5c3d\u53ef\u80fd\u4fdd\u8bc1\u4f4e\u5ef6\u8fdf\uff0c\u6240\u4ee5\u5728 sink \u7aef\u6ca1\u6709\u505a\u4e00\u81f4\u6027\u4fdd\u8bc1\u3002<\/p>\n Structured Streming \u7684\u5b98\u65b9\u8bba\u6587\u91cc\u9762\u7ed9\u51fa\u4e86 Yahoo! Streaming Benchmark \u7684\u7ed3\u679c\uff0cStructured Streaming \u7684 throughput \u5927\u6982\u662f Flink \u7684 2 \u500d\u548c Kafka Streaming \u7684 90 \u591a\u500d\u3002<\/p>\n \u603b\u7ed3\u4e00\u4e0b\uff0cStructured Streaming \u901a\u8fc7\u63d0\u4f9b\u4e00\u5957 high-level \u7684 declarative api \u4f7f\u5f97\u6d41\u5f0f\u8ba1\u7b97\u7684\u7f16\u5199\u76f8\u6bd4 Spark Streaming \u7b80\u5355\u5bb9\u6613\u4e0d\u5c11\uff0c\u540c\u65f6\u901a\u8fc7\u63d0\u4f9b end-to-end \u7684 exactly-once \u8bed\u4e49<\/p>\n \u6700\u540e\uff0c\u95f2\u626f\u4e00\u70b9\u522b\u7684\u3002Spark \u5728 5 \u5e74\u63a8\u51fa\u57fa\u4e8e micro-batch \u6a21\u5f0f\u7684 Spark Streaming \u5fc5\u7136\u662f\u57fa\u4e8e\u5f53\u65f6 Spark Engine \u6700\u5feb\u7684\u65b9\u5f0f\uff0c\u5c3d\u7ba1\u4e0d\u662f\u771f\u6b63\u7684\u6d41\u5904\u7406\uff0c\u4f46\u662f\u5728\u541e\u5410\u91cf\u66f4\u91cd\u8981\u7684\u5e74\u4ee3\uff0c\u8fd8\u662f\u5c1d\u5c3d\u4e86\u751c\u5934\u3002\u800c Spark \u7684\u771f\u6b63\u57fa\u4e8e continuous \u5904\u7406\u6a21\u5f0f\u7684 Structured Streaming \u76f4\u5230 Spark 2.3 \u7248\u672c\u624d\u771f\u6b63\u63a8\u51fa\uff0c\u4ece\u800c\u5bfc\u81f4\u8fd1\u4e24\u5e74\u8ba9 Flink \u5c1d\u5c3d\u4e86\u751c\u5934\uff08\u5f53\u7136\u548c Flink \u7684\u4f18\u79c0\u7684\u8bed\u4e49\u6a21\u578b\u5b58\u5728\u5f88\u5927\u7684\u5173\u7cfb\uff09\u3002\u5728\u5b9e\u65f6\u8ba1\u7b97\u9886\u57df\uff0c\u7531 Spark \u7684\u5353\u8d8a\u6838\u5fc3 SQL Engine \u52a9\u529b\u7684 Structured Streaming\uff0c\u8fd8\u662f\u98ce\u5934\u6b63\u52b2\u7684 Flink\uff0c\u4ea6\u6216\u662f\u5176\u4ed6\u6d41\u5904\u7406\u5f15\u64ce\uff0c\u7a76\u7adf\u8c01\u5c06\u5360\u9886\u7edf\u6cbb\u5730\u4f4d\uff0c\u8fd8\u662f\u503c\u5f97\u671f\u5f85\u4e00\u4e0b\u7684\u3002<\/p>\n
Applications in Apache Spark *\u3002<\/p>\n0. Spark Streaming \u4e0d\u8db3<\/h2>\n
1. Structured Streaming \u4ecb\u7ecd<\/h2>\n
2. Structured Streaming \u6838\u5fc3\u8bbe\u8ba1<\/h2>\n
3. Structured Streaming \u7f16\u7a0b\u6a21\u578b<\/h2>\n
<\/p>\n\/\/ Create DataFrame representing the stream of input lines from connection to localhost:9999\nval lines = spark.readStream\n .format(\"socket\")\n .option(\"host\", \"localhost\")\n .option(\"port\", 9999)\n .load()\n\n\/\/ Split the lines into words\nval words = lines.as[String].flatMap(_.split(\" \"))\n\n\/\/ Generate running word count\nval wordCounts = words.groupBy(\"value\").count()\n\n\/\/ Start running the query that prints the running counts to the console\nval query = wordCounts.writeStream\n .outputMode(\"complete\")\n .format(\"console\")\n .start()<\/code><\/pre>\n
import spark.implicits._\n\nval words = ... \/\/ streaming DataFrame of schema { timestamp: Timestamp, word: String }\n\n\/\/ Group the data by window and word and compute the count of each group\nval windowedCounts = words.groupBy(\n window(\"eventTime\", \"10 minutes\", \"5 minutes\"),\n $\"word\"\n).count()<\/code><\/pre>\n
import spark.implicits._\n\nval words = ... \/\/ streaming DataFrame of schema { timestamp: Timestamp, word: String }\n\n\/\/ Group the data by window and word and compute the count of each group\nval windowedCounts = words\n .withWatermark(\"eventTime\", \"10 minutes\")\n .groupBy(\n window(\"eventTime\", \"10 minutes\", \"5 minutes\"),\n $\"word\")\n .count()<\/code><\/pre>\n
4. Continuous Processing Mode<\/h2>\n
<\/p>\n5. \u4e00\u81f4\u6027\u8bed\u4e49<\/h2>\n
6. Benchmark<\/h2>\n
7. \u603b\u7ed3<\/h2>\n
8. \u95f2\u626f<\/h2>\n
9. Reference<\/h2>\n