{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/30962409","id":30962409,"diff_hunk":"@@ -1321,3 +1201,137 @@ object SQLContext {\n     }\n   }\n }\n+\n+\n+\n+/**\n+ * :: DeveloperApi ::\n+ * The primary workflow for executing relational queries using Spark.  Designed to allow easy\n+ * access to the intermediate phases of query execution for developers.\n+ */\n+@DeveloperApi\n+class QueryExecution(val sqlContext: SQLContext, val logical: LogicalPlan) {\n+  val analyzer  = sqlContext.analyzer\n+  val optimizer = sqlContext.optimizer\n+  val planner   = sqlContext.planner\n+  val cacheManager = sqlContext.cacheManager\n+  val prepareForExecution = sqlContext.prepareForExecution\n+\n+  def assertAnalyzed(): Unit = analyzer.checkAnalysis(analyzed)\n+\n+  lazy val analyzed: LogicalPlan = analyzer.execute(logical)\n+  lazy val withCachedData: LogicalPlan = {\n+    assertAnalyzed()\n+    cacheManager.useCachedData(analyzed)\n+  }\n+  lazy val optimizedPlan: LogicalPlan = optimizer.execute(withCachedData)\n+\n+  // TODO: Don't just pick the first one...\n+  lazy val sparkPlan: SparkPlan = {\n+    SparkPlan.currentContext.set(sqlContext)\n+    planner.plan(optimizedPlan).next()\n+  }\n+  // executedPlan should not be used to initialize any SparkPlan. It should be\n+  // only used for execution.\n+  lazy val executedPlan: SparkPlan = prepareForExecution.execute(sparkPlan)\n+\n+  /** Internal version of the RDD. Avoids copies and has no schema */\n+  lazy val toRdd: RDD[Row] = executedPlan.execute()\n+\n+  protected def stringOrError[A](f: => A): String =\n+    try f.toString catch { case e: Throwable => e.toString }\n+\n+  def simpleString: String =\n+    s\"\"\"== Physical Plan ==\n+       |${stringOrError(executedPlan)}\n+      \"\"\".stripMargin.trim\n+\n+  override def toString: String = {\n+    def output =\n+      analyzed.output.map(o => s\"${o.name}: ${o.dataType.simpleString}\").mkString(\", \")\n+\n+    // TODO previously will output RDD details by run (${stringOrError(toRdd.toDebugString)})\n+    // however, the `toRdd` will cause the real execution, which is not what we want.\n+    // We need to think about how to avoid the side effect.\n+    s\"\"\"== Parsed Logical Plan ==\n+       |${stringOrError(logical)}\n+        |== Analyzed Logical Plan ==\n+        |${stringOrError(output)}\n+        |${stringOrError(analyzed)}\n+        |== Optimized Logical Plan ==\n+        |${stringOrError(optimizedPlan)}\n+        |== Physical Plan ==\n+        |${stringOrError(executedPlan)}\n+        |Code Generation: ${stringOrError(executedPlan.codegenEnabled)}\n+        |== RDD ==\n+      \"\"\".stripMargin.trim\n+  }\n+}\n+\n+\n+class SparkPlanner(val sqlContext: SQLContext) extends org.apache.spark.sql.execution.SparkStrategies {\n+  val sparkContext: SparkContext = sqlContext.sparkContext\n+\n+  def codegenEnabled: Boolean = sqlContext.conf.codegenEnabled\n+\n+  def unsafeEnabled: Boolean = sqlContext.conf.unsafeEnabled\n+\n+  def numPartitions: Int = sqlContext.conf.numShufflePartitions\n+\n+  def strategies: Seq[Strategy] =\n+    sqlContext.experimental.extraStrategies ++ (\n+      DataSourceStrategy ::\n+        DDLStrategy ::\n+        TakeOrdered ::\n+        HashAggregation ::\n+        LeftSemiJoin ::\n+        HashJoin ::\n+        InMemoryScans ::\n+        ParquetOperations ::\n+        BasicOperators ::\n+        CartesianProduct ::\n+        BroadcastNestedLoopJoin :: Nil)\n+\n+  /**\n+   * Used to build table scan operators where complex projection and filtering are done using\n+   * separate physical operators.  This function returns the given scan operator with Project and\n+   * Filter nodes added only when needed.  For example, a Project operator is only used when the\n+   * final desired output requires complex expressions to be evaluated or when columns can be\n+   * further eliminated out after filtering has been done.\n+   *\n+   * The `prunePushedDownFilters` parameter is used to remove those filters that can be optimized\n+   * away by the filter pushdown optimization.\n+   *\n+   * The required attributes for both filtering and expression evaluation are passed to the\n+   * provided `scanBuilder` function so that it can avoid unnecessary column materialization.\n+   */\n+  def pruneFilterProject(\n+                          projectList: Seq[NamedExpression],","path":"sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala","position":268,"original_position":268,"commit_id":"b0877705072dadc1d16da061db2b226cc47b2165","original_commit_id":"b0877705072dadc1d16da061db2b226cc47b2165","user":{"login":"chenghao-intel","id":2367031,"avatar_url":"https://avatars.githubusercontent.com/u/2367031?v=3","gravatar_id":"","url":"https://api.github.com/users/chenghao-intel","html_url":"https://github.com/chenghao-intel","followers_url":"https://api.github.com/users/chenghao-intel/followers","following_url":"https://api.github.com/users/chenghao-intel/following{/other_user}","gists_url":"https://api.github.com/users/chenghao-intel/gists{/gist_id}","starred_url":"https://api.github.com/users/chenghao-intel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenghao-intel/subscriptions","organizations_url":"https://api.github.com/users/chenghao-intel/orgs","repos_url":"https://api.github.com/users/chenghao-intel/repos","events_url":"https://api.github.com/users/chenghao-intel/events{/privacy}","received_events_url":"https://api.github.com/users/chenghao-intel/received_events","type":"User","site_admin":false},"body":"4 spaces indent","created_at":"2015-05-25T05:11:15Z","updated_at":"2015-05-25T05:11:15Z","html_url":"https://github.com/apache/spark/pull/6356#discussion_r30962409","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6356","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/30962409"},"html":{"href":"https://github.com/apache/spark/pull/6356#discussion_r30962409"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6356"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6356","id":36032712,"html_url":"https://github.com/apache/spark/pull/6356","diff_url":"https://github.com/apache/spark/pull/6356.diff","patch_url":"https://github.com/apache/spark/pull/6356.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6356","number":6356,"state":"open","locked":false,"title":"[SQL] SPARK-6981: Factor out SparkPlanner and QueryExecution from SQLContext","user":{"login":"evacchi","id":380791,"avatar_url":"https://avatars.githubusercontent.com/u/380791?v=3","gravatar_id":"","url":"https://api.github.com/users/evacchi","html_url":"https://github.com/evacchi","followers_url":"https://api.github.com/users/evacchi/followers","following_url":"https://api.github.com/users/evacchi/following{/other_user}","gists_url":"https://api.github.com/users/evacchi/gists{/gist_id}","starred_url":"https://api.github.com/users/evacchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evacchi/subscriptions","organizations_url":"https://api.github.com/users/evacchi/orgs","repos_url":"https://api.github.com/users/evacchi/repos","events_url":"https://api.github.com/users/evacchi/events{/privacy}","received_events_url":"https://api.github.com/users/evacchi/received_events","type":"User","site_admin":false},"body":"Alternative to PR #6122; in this case the refactored out classes are replaced by inner classes with the same name for backwards binary compatibility\r\n\r\n   * process in a lighter-weight, backwards-compatible way","created_at":"2015-05-22T13:53:24Z","updated_at":"2015-05-25T05:11:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f42929d33a5b97d5d504cdfef489e3560c0412fc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6356/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6356/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6356/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/b0877705072dadc1d16da061db2b226cc47b2165","head":{"label":"evacchi:sqlctx-refactoring-lite","ref":"sqlctx-refactoring-lite","sha":"b0877705072dadc1d16da061db2b226cc47b2165","user":{"login":"evacchi","id":380791,"avatar_url":"https://avatars.githubusercontent.com/u/380791?v=3","gravatar_id":"","url":"https://api.github.com/users/evacchi","html_url":"https://github.com/evacchi","followers_url":"https://api.github.com/users/evacchi/followers","following_url":"https://api.github.com/users/evacchi/following{/other_user}","gists_url":"https://api.github.com/users/evacchi/gists{/gist_id}","starred_url":"https://api.github.com/users/evacchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evacchi/subscriptions","organizations_url":"https://api.github.com/users/evacchi/orgs","repos_url":"https://api.github.com/users/evacchi/repos","events_url":"https://api.github.com/users/evacchi/events{/privacy}","received_events_url":"https://api.github.com/users/evacchi/received_events","type":"User","site_admin":false},"repo":{"id":34118615,"name":"spark","full_name":"evacchi/spark","owner":{"login":"evacchi","id":380791,"avatar_url":"https://avatars.githubusercontent.com/u/380791?v=3","gravatar_id":"","url":"https://api.github.com/users/evacchi","html_url":"https://github.com/evacchi","followers_url":"https://api.github.com/users/evacchi/followers","following_url":"https://api.github.com/users/evacchi/following{/other_user}","gists_url":"https://api.github.com/users/evacchi/gists{/gist_id}","starred_url":"https://api.github.com/users/evacchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evacchi/subscriptions","organizations_url":"https://api.github.com/users/evacchi/orgs","repos_url":"https://api.github.com/users/evacchi/repos","events_url":"https://api.github.com/users/evacchi/events{/privacy}","received_events_url":"https://api.github.com/users/evacchi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/evacchi/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/evacchi/spark","forks_url":"https://api.github.com/repos/evacchi/spark/forks","keys_url":"https://api.github.com/repos/evacchi/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/evacchi/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/evacchi/spark/teams","hooks_url":"https://api.github.com/repos/evacchi/spark/hooks","issue_events_url":"https://api.github.com/repos/evacchi/spark/issues/events{/number}","events_url":"https://api.github.com/repos/evacchi/spark/events","assignees_url":"https://api.github.com/repos/evacchi/spark/assignees{/user}","branches_url":"https://api.github.com/repos/evacchi/spark/branches{/branch}","tags_url":"https://api.github.com/repos/evacchi/spark/tags","blobs_url":"https://api.github.com/repos/evacchi/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/evacchi/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/evacchi/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/evacchi/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/evacchi/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/evacchi/spark/languages","stargazers_url":"https://api.github.com/repos/evacchi/spark/stargazers","contributors_url":"https://api.github.com/repos/evacchi/spark/contributors","subscribers_url":"https://api.github.com/repos/evacchi/spark/subscribers","subscription_url":"https://api.github.com/repos/evacchi/spark/subscription","commits_url":"https://api.github.com/repos/evacchi/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/evacchi/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/evacchi/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/evacchi/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/evacchi/spark/contents/{+path}","compare_url":"https://api.github.com/repos/evacchi/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/evacchi/spark/merges","archive_url":"https://api.github.com/repos/evacchi/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/evacchi/spark/downloads","issues_url":"https://api.github.com/repos/evacchi/spark/issues{/number}","pulls_url":"https://api.github.com/repos/evacchi/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/evacchi/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/evacchi/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/evacchi/spark/labels{/name}","releases_url":"https://api.github.com/repos/evacchi/spark/releases{/id}","created_at":"2015-04-17T13:37:25Z","updated_at":"2015-04-23T08:02:24Z","pushed_at":"2015-05-22T13:51:43Z","git_url":"git://github.com/evacchi/spark.git","ssh_url":"git@github.com:evacchi/spark.git","clone_url":"https://github.com/evacchi/spark.git","svn_url":"https://github.com/evacchi/spark","homepage":null,"size":108170,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"4e5220c3171b6a2f4970409bd16be2db930df65d","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-05-25T02:54:11Z","pushed_at":"2015-05-25T05:10:13Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1725519,"stargazers_count":4080,"watchers_count":4080,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3585,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":313,"forks":3585,"open_issues":313,"watchers":4080,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6356"},"html":{"href":"https://github.com/apache/spark/pull/6356"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6356"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6356/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6356/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6356/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/b0877705072dadc1d16da061db2b226cc47b2165"}}}}