{"id":88188,"date":"2020-02-08T08:06:26","date_gmt":"2020-02-08T00:06:26","guid":{"rendered":"http:\/\/4563.org\/?p=88188"},"modified":"2020-02-08T08:06:26","modified_gmt":"2020-02-08T00:06:26","slug":"%e5%85%b3%e4%ba%8e-spark-sql-parser-%e7%9a%84%e6%ba%90%e7%a0%81-%e7%9c%8b%e4%b8%8d%e6%87%82%ef%bc%8c%e6%b1%82%e6%8c%87%e5%af%bc","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=88188","title":{"rendered":"\u5173\u4e8e spark sql parser \u7684\u6e90\u7801, \u770b\u4e0d\u61c2\uff0c\u6c42\u6307\u5bfc"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5173\u4e8e spark sql parser \u7684\u6e90\u7801, \u770b\u4e0d\u61c2\uff0c\u6c42\u6307\u5bfc               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : scalaer <\/span>  <span><i><\/i> 25<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code> class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging {  ...      override def visitSingleStatement(ctx: SingleStatementContext): LogicalPlan = withOrigin(ctx) {            visit(ctx.statement).asInstanceOf[LogicalPlan]     }  } <\/code><\/pre>\n<p><code>visit<\/code>\u662f antlr \u7684<code>AbstractParseTreeVisitor<\/code>\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c \u8fd4\u56de\u7c7b\u578b\u662f T, \u51fd\u6570\u7b7e\u540d\u5982\u4e0b<\/p>\n<pre><code>public T visit(ParseTree tree) {     return tree.accept(this); } <\/code><\/pre>\n<p>\u6211\u7684\u7591\u95ee\u662f\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u5c06\u8fd4\u56de\u7c7b\u578b\u8f6c\u6210 <code>LogicalPlan<\/code>, \u8fd9\u4e2a\u8fc7\u7a0b\u53d1\u751f\u4e86\u5565??<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1135070\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whwlsfb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             T \u662f\u6cdb\u578b\uff0c\u53ef\u4ee5\u4ee3\u8868\u4efb\u4f55\u7c7b\u578b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1135071\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : billlee <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u56e0\u4e3a visit(ctx.statement) \u4f1a\u8c03\u7528\u5176\u5b83 visit&#8230; \u65b9\u6cd5\u5e76\u628a\u8fd4\u56de\u503c\u4f20\u4e0a\u6765\u3002spark \u5b9e\u73b0\u7684\u8fd9\u4e9b visit&#8230; \u903b\u8f91\u4fdd\u8bc1\u4e86\u8fd9\u4e2a\u60c5\u51b5\u4e0b\u8fd4\u56de\u503c\u4e00\u5b9a\u4f1a\u662f LogicalPlan.<\/p>\n<p>\u8fd9\u4e2a Visitor \u8981\u7ed3\u5408\u8bed\u6cd5\u6587\u4ef6\u770b\u7684\uff0c\u5efa\u8bae\u8bfb\u4e00\u8bfb The Definitive ANTLR 4 Reference, \u8ddf\u7740\u4e66\u7528\u7528 ANTLR \u5199\u4e2a\u8ba1\u7b97\u5668\u4ec0\u4e48\u7684\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1135072\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zoowii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sql \u8bed\u53e5\u88ab\u89e3\u6790\u6210\u8bed\u6cd5\u6811\uff0c\u4e00\u6761 sql \u8bed\u53e5\u5bf9\u5e94\u7684\u8bed\u6cd5\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u88ab visitor \u89e3\u6790\u4e3a\u4e00\u4e2a\u7b97\u5b50\uff0c\u9876\u5c42\u88ab visitor \u89e3\u6790\u4e3a LogicalPlan. visitSingleStatement \u662f visitor \u8bbf\u95ee\u5355\u72ec\u4e00\u6761 SQL \u8bed\u53e5\u7684\uff0c\u9876\u5c42 visitor \u7ed3\u679c\u80af\u5b9a\u662f LogicalPlan \u7c7b\u578b\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1135073\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MarsBar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u8fd1\u521a\u597d\u5728\u5199\u7f16\u8bd1\u5668\u7684\u4f5c\u4e1a\u5199\u5230\u8fd9\u4e2a\u7c7b\u4f3c\u7684<br \/>\u91cd\u70b9\uff1a \u8bbf\u95ee\u8005\u6a21\u5f0f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1135074\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : scalaer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @billlee \u611f\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1135075\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : scalaer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zoowii \u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1135076\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : scalaer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @MarsBar \u6211\u6700\u8fd1\u6253\u7b97\u91cd\u65b0\u5b66\u7f16\u8bd1\u539f\u7406, \u6709\u673a\u4f1a\u80fd\u4ea4\u6d41\u4e0b\u5c31\u597d\u4e86                                                             <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e spark sql pars&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/88188"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88188"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/88188\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88188"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}