You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by liancheng <gi...@git.apache.org> on 2015/12/31 13:50:53 UTC

[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

GitHub user liancheng opened a pull request:

    https://github.com/apache/spark/pull/10541

    [SPARK-12592][SQL][WIP] Converts resolved logical plan back to SQL

    This PR tries to enable Spark SQL to convert resolved logical plans back to SQL query strings.  For now, the major use case is to canonicalize Spark SQL native view support.
    
    The major entry point is `SQLBuilder.toSQL`, which returns an `Option[String]` if the logical plan is recognized.
    
    The current version is still in WIP status, and is quite limited.  Known limitations include:
    
    1.  The logical plan must be analyzed but not optimized
    
        The optimizer erases `Subquery` operators, which contain necessary scope information for SQL generation.  Future versions should be able to recover erased scope information by inserting subqueries when necessary.
    
    1.  The logical plan must be created using HiveQL query string
    
        Query plans generated by composing arbitrary DataFrame API combinations are not supported yet.  Operators within these query plans need to be rearranged into a canonical form that is more suitable for direct SQL generation.  For example, the following query plan
    
        ```
        Filter (a#1 < 10)
         +- MetastoreRelation default, src, None
        ```
    
        need to be canonicalized into the following form before SQL generation:
    
        ```
        Project [a#1, b#2, c#3]
         +- Filter (a#1 < 10)
             +- MetastoreRelation default, src, None
        ```
    
        Otherwise, the SQL generation process will have to handle a large number of special cases.
    
    1.  Only a fraction of expressions and basic logical plan operators are supported in this PR
    
        Support for window functions, generators, and cubes etc. will be added in follow-up PRs.
    
    This PR leverages `HiveCompatibilitySuite` for testing SQL generation in a "round-trip" manner:
    
    *   For all select queries, we try to convert it back to SQL
    *   If the query plan is convertible, we parse the generated SQL into a new logical plan
    *   Run the new logical plan instead of the original one
    
    If the query plan is inconvertible, the test case simply falls back to the original logic.
    
    TODO
    
    - [ ] Fix failed test cases
    - [ ] Support for more basic expressions and logical plan operators (e.g. distinct aggregation etc.)

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/liancheng/spark sql-generation

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/10541.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #10541
    
----
commit 17e8fba3484d19e7ca7a993359fdc28004f9dfb8
Author: Cheng Lian <li...@databricks.com>
Date:   2015-12-28T10:12:10Z

    WIP: Converting resolved logical plan back to SQL

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168684642
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169822690
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169695823
  
    **[Test build #48940 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48940/consoleFull)** for PR 10541 at commit [`a304392`](https://github.com/apache/spark/commit/a304392602160ac5cf84b83eda60170842e85200).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169395222
  
    **[Test build #48860 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48860/consoleFull)** for PR 10541 at commit [`2e784b9`](https://github.com/apache/spark/commit/2e784b93c677b833695694186fefcc9d94555e6f).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169213939
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49040262
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala ---
    @@ -226,6 +234,11 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with
           }
          """
       }
    +
    +  override def sql: Option[String] = for {
    +    valueSQL <- child.sql
    +    listSQL <- sequenceOption(hset.toSeq.map(Literal(_).sql))
    +  } yield s"($valueSQL IN (${listSQL.mkString(", ")}))"
    --- End diff --
    
    Maybe we do not need to support InSet right now? It is only created by the optimizer. Also, values in the set are in our internal type, I am not sure if using `toString` works.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169216410
  
    test this please


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49043914
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -214,6 +214,41 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case (_, NullType | _: ArrayType | _: MapType | _: StructType) if value == null =>
    +      "NULL"
    --- End diff --
    
    HiveQL doesn't allow casting to complex types.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168194610
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48554/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169822693
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48974/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168684647
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48660/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48739252
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,176 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    --- End diff --
    
    I believe we need it later when dealing with more complex scenarios. For example, we may want to add `SELECT *` over a raw `MetastoreRelation`. Then we need `sqlContext` to resolve the `*`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168384367
  
    @liancheng this looks cool!
    
    I was wondering why we are bound to SQL? Is this because of Hive? I was thinking of the following, we could also store the logical plan's json representation. This should alot easier to (de)serialize. Could we store that in the Hive metadata store?
    
    Another idea I was having. If a view is defined in HQL, we could also store that in some way with the query execution. This saves us a serialization/deserialization trip, and allows the user to recognize his own query.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169563760
  
    @yhuai For data source tables, I only explicitly supported Parquet tables. Other data sources can be added in follow-up PRs. And yes, I forgot to move `ComputeCurrentTime` to the optimizer. Thanks for reminding.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169885951
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48996/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169866012
  
    test this please


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169133557
  
    **[Test build #48779 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48779/consoleFull)** for PR 10541 at commit [`1796540`](https://github.com/apache/spark/commit/17965405ce2599554c6eef6d1365ec287fa3b0eb).
     * This patch **fails Spark unit tests**.
     * This patch **does not merge cleanly**.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49045875
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala ---
    @@ -206,6 +212,25 @@ case class CaseWhen(branches: Seq[Expression]) extends CaseWhenLike {
           case Seq(elseValue) => s" ELSE $elseValue"
         }.mkString
       }
    +
    +  override def sql: Option[String] = {
    +    sequenceOption(branches.map(_.sql)).map {
    +      case branchesSQL =>
    --- End diff --
    
    Thanks, removed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49075834
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUDFs.scala ---
    @@ -137,7 +133,8 @@ private[hive] class HiveFunctionRegistry(
       }
     }
     
    -private[hive] case class HiveSimpleUDF(funcWrapper: HiveFunctionWrapper, children: Seq[Expression])
    +private[hive] case class HiveSimpleUDF(
    +    name: String, funcWrapper: HiveFunctionWrapper, children: Seq[Expression])
    --- End diff --
    
    No, we can't. `funcWrapper` only contains class name.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169571248
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49039209
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala ---
    @@ -931,6 +931,14 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression {
             $evPrim = $result.copy();
           """
       }
    +
    +  override def sql: Option[String] = {
    +    if (foldable) {
    +      Literal.create(eval(), dataType).sql
    +    } else {
    +      child.sql.map(childSQL => s"CAST($childSQL AS ${dataType.sql})")
    --- End diff --
    
    How about we do not evaluate the expr if it is foldable? I think it does not really give us any benefit if we evaluate it at here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49044032
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRelation.scala ---
    @@ -140,6 +140,12 @@ private[sql] class ParquetRelation(
         .get(ParquetRelation.METASTORE_SCHEMA)
         .map(DataType.fromJson(_).asInstanceOf[StructType])
     
    +  // If this relation is converted from a Hive metastore table, this method returns the name of the
    +  // original Hive metastore table.
    +  private[sql] def metastoreTableName: Option[TableIdentifier] = {
    --- End diff --
    
    This is used to handle Parquet relations converted from metastore Parquet tables.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49045205
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala ---
    @@ -74,6 +74,12 @@ case class If(predicate: Expression, trueValue: Expression, falseValue: Expressi
       }
     
       override def toString: String = s"if ($predicate) $trueValue else $falseValue"
    +
    +  override def sql: Option[String] = for {
    +    predicateSQL <- predicate.sql
    +    trueSQL <- trueValue.sql
    +    falseSQL <- falseValue.sql
    +  } yield s"(IF($predicateSQL, $trueSQL, $falseSQL))"
     }
     
     trait CaseWhenLike extends Expression {
    --- End diff --
    
    Added support for case when expressions.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49052692
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala ---
    @@ -1026,4 +1112,8 @@ case class FormatNumber(x: Expression, d: Expression)
       }
     
       override def prettyName: String = "format_number"
    +
    +  override def sql: Option[String] = for {
    +    childrenSQL <- sequenceOption(children.map(_.sql))
    +  } yield s"$prettyName(${childrenSQL.mkString(", ")})"
    --- End diff --
    
    Should we create a trait to implement sql string for all function like expressions? It's a lot of duplicated code here...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48799678
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -213,6 +215,34 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case _ if value == null =>
    +      "NULL"
    --- End diff --
    
    Good idea.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48879512
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -213,6 +215,34 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case _ if value == null =>
    +      "NULL"
    +
    +    case (v: UTF8String, StringType) =>
    +      "\"" + v.toString.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
    +
    +    case (v: Byte, ByteType) =>
    +      s"CAST($v AS ${ByteType.simpleString.toUpperCase})"
    +
    +    case (v: Short, ShortType) =>
    +      s"CAST($v AS ${ShortType.simpleString.toUpperCase})"
    +
    +    case (v: Long, LongType) =>
    +      s"CAST($v AS ${LongType.simpleString.toUpperCase})"
    +
    +    case (v: Float, FloatType) =>
    +      s"CAST($v AS ${FloatType.simpleString.toUpperCase})"
    +
    +    case (v: Decimal, DecimalType.Fixed(precision, scale)) =>
    +      s"CAST($v AS ${DecimalType.simpleString.toUpperCase}($precision, $scale))"
    +
    +    case (v: Int, DateType) =>
    +      s"DATE '${DateTimeUtils.toJavaDate(v)}'"
    --- End diff --
    
    Done.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49229854
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRelation.scala ---
    @@ -147,6 +147,12 @@ private[sql] class ParquetRelation(
         .get(ParquetRelation.METASTORE_SCHEMA)
         .map(DataType.fromJson(_).asInstanceOf[StructType])
     
    +  // If this relation is converted from a Hive metastore table, this method returns the name of the
    +  // original Hive metastore table.
    +  private[sql] def metastoreTableName: Option[TableIdentifier] = {
    +    parameters.get(ParquetRelation.METASTORE_TABLE_NAME).map(SqlParser.parseTableIdentifier)
    --- End diff --
    
    I am wondering if we can provide a general mechanism to handle all data source tables (even the table is converted from metastore).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49040368
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/randomExpressions.scala ---
    @@ -49,6 +49,8 @@ abstract class RDG extends LeafExpression with Nondeterministic {
       override def nullable: Boolean = false
     
       override def dataType: DataType = DoubleType
    +
    +  override def sql: Option[String] = Some(s"${prettyName.toUpperCase}($seed)")
    --- End diff --
    
    Just a note at here. Even if a user uses `rand()`, we will put a seed at here. (no need to make any change for this right now)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169567023
  
    Moved `ComputeCurrentTime` to the optimizer.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169696245
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48940/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169562830
  
    **[Test build #48894 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48894/consoleFull)** for PR 10541 at commit [`c118a35`](https://github.com/apache/spark/commit/c118a354a43f0f9eef83ed92b01f754936c9dfa6).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169213941
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48822/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169563178
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48802965
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -1,9 +1,9 @@
     /**
    -   Licensed to the Apache Software Foundation (ASF) under one or more 
    -   contributor license agreements.  See the NOTICE file distributed with 
    +   Licensed to the Apache Software Foundation (ASF) under one or more
    +   contributor license agreements.  See the NOTICE file distributed with
        this work for additional information regarding copyright ownership.
        The ASF licenses this file to You under the Apache License, Version 2.0
    -   (the "License"); you may not use this file except in compliance with 
    +   (the "License"); you may not use this file except in compliance with
    --- End diff --
    
    I think we should remove these trailing spaces anyway?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168468512
  
    @hvanhovell the problem with the json representation is stability. The json one is pretty tied to our internal implementation, and as a result would be hard to stabilize. Of course, we can also design our own stable json representation, but at that point we are really just re-inventing the SQL wheel.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48728103
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -637,7 +637,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
       // counter to generate unique union aliases
       private int aliasCounter;
       private String generateUnionAlias() {
    -    return "_u" + (++aliasCounter);
    +    return "u_" + (++aliasCounter);
    --- End diff --
    
    Yes. `_u` appears as an alias of a subquery. I hit this issue while trying to fix `HiveQuerySuite.CTE feature #2`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169122807
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49040759
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRelation.scala ---
    @@ -140,6 +140,12 @@ private[sql] class ParquetRelation(
         .get(ParquetRelation.METASTORE_SCHEMA)
         .map(DataType.fromJson(_).asInstanceOf[StructType])
     
    +  // If this relation is converted from a Hive metastore table, this method returns the name of the
    +  // original Hive metastore table.
    +  private[sql] def metastoreTableName: Option[TableIdentifier] = {
    --- End diff --
    
    Where do we use it?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168670159
  
    **[Test build #48660 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48660/consoleFull)** for PR 10541 at commit [`4963676`](https://github.com/apache/spark/commit/4963676874b06549e0d344ed91966b0c25670773).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168220603
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169885943
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168676146
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49039342
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala ---
    @@ -356,6 +359,8 @@ abstract class UnaryExpression extends Expression {
           """
         }
       }
    +
    +  override def sql: Option[String] = child.sql.map(childSQL => s"($prettyName($childSQL))")
    --- End diff --
    
    Maybe it is good to add doc in the code to mention that `prettyName` should match the name registered in function registry.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169809906
  
    **[Test build #48949 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48949/consoleFull)** for PR 10541 at commit [`2073e30`](https://github.com/apache/spark/commit/2073e305f994d1f3b850fcf18e37002761979670).
     * This patch **fails from timeout after a configured wait of \`250m\`**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `class ComputeCurrentTimeSuite extends PlanTest `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168756348
  
    **[Test build #48667 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48667/consoleFull)** for PR 10541 at commit [`1d5dd3b`](https://github.com/apache/spark/commit/1d5dd3b9fd9e64de517d87e854460da877bd66a2).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791064
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala ---
    @@ -74,6 +74,12 @@ case class If(predicate: Expression, trueValue: Expression, falseValue: Expressi
       }
     
       override def toString: String = s"if ($predicate) $trueValue else $falseValue"
    +
    +  override def sql: Option[String] = for {
    +    predicateSQL <- predicate.sql
    +    trueSQL <- trueValue.sql
    +    falseSQL <- falseValue.sql
    +  } yield s"(IF($predicateSQL, $trueSQL, $falseSQL))"
     }
     
     trait CaseWhenLike extends Expression {
    --- End diff --
    
    Do we support case when?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168982479
  
    **[Test build #48763 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48763/consoleFull)** for PR 10541 at commit [`1e50288`](https://github.com/apache/spark/commit/1e50288d6f956608b53554d31bd394bf919812e0).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49045649
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala ---
    @@ -226,6 +234,11 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with
           }
          """
       }
    +
    +  override def sql: Option[String] = for {
    +    valueSQL <- child.sql
    +    listSQL <- sequenceOption(hset.toSeq.map(Literal(_).sql))
    +  } yield s"($valueSQL IN (${listSQL.mkString(", ")}))"
    --- End diff --
    
    yeah. But, does `Literal(_)` work if hset's elements are in internal types (e.g. UTF8String)?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49079379
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -333,6 +335,39 @@ object ProjectCollapsing extends Rule[LogicalPlan] {
             )
             Project(cleanedProjection, child)
           }
    +
    +    // TODO Eliminate duplicate code
    +    // This clause is identical to the one above except that the inner operator is an `Aggregate`
    +    // rather than a `Project`.
    +    case p @ Project(projectList1, agg @ Aggregate(_, projectList2, child)) =>
    --- End diff --
    
    makes sense, thanks for the explanation!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168194609
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169240324
  
    **[Test build #48828 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48828/consoleFull)** for PR 10541 at commit [`83e28fc`](https://github.com/apache/spark/commit/83e28fca84aa2c5a78af301df2b3d618b537be45).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49044241
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/LogicalPlanSQLBuilderSuite.scala ---
    @@ -0,0 +1,57 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.catalyst.plans.logical.OneRowRelation
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.test.SQLTestUtils
    +
    +// All test cases in this test suite are ignored for now because currently `SQLBuilder` only handles
    +// resolved logical plans parsed directly from HiveQL query strings.
    +class LogicalPlanSQLBuilderSuite extends SQLBuilderTest with SQLTestUtils {
    +  import hiveContext.implicits._
    +
    +  protected override def beforeAll(): Unit = {
    +    super.beforeAll()
    +
    +    sqlContext.range(10).select('id alias "a").registerTempTable("t0")
    +    sqlContext.range(10).select('id alias "b").registerTempTable("t1")
    +  }
    +
    +  protected override def afterAll(): Unit = {
    +    sqlContext.dropTempTable("t0")
    +    sqlContext.dropTempTable("t1")
    +
    +    super.afterAll()
    +  }
    +
    +  ignore("single row project") {
    +    checkSQL(OneRowRelation.select(lit(1)), "SELECT 1 AS `1`")
    +    checkSQL(OneRowRelation.select(lit(1) as 'a), "SELECT 1 AS `a`")
    --- End diff --
    
    In this case these are identical. I probably should just remove this test suite since now we have `HiveQLSQLBuilderSuite`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49039615
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala ---
    @@ -163,6 +173,12 @@ sealed abstract class AggregateFunction extends Expression with ImplicitCastInpu
       def toAggregateExpression(isDistinct: Boolean): AggregateExpression = {
         AggregateExpression(aggregateFunction = this, mode = Complete, isDistinct = isDistinct)
       }
    +
    +  override def sql: Option[String] = argumentsSQL.map(sql => s"${prettyName.toUpperCase}($sql)")
    --- End diff --
    
    Do we need to make them upper case? Seems at other places, we do not do it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168713552
  
    **[Test build #48665 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48665/consoleFull)** for PR 10541 at commit [`70af178`](https://github.com/apache/spark/commit/70af178e1d734e9df74eba71f3d2c4426d56dfbb).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168220278
  
    **[Test build #48558 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48558/consoleFull)** for PR 10541 at commit [`af865a9`](https://github.com/apache/spark/commit/af865a9d5c3b4a7a3ba9af856c4f19250b004e4b).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `abstract sealed class SortDirection `
      * `sealed abstract class JoinType `
      * `case class Subquery(alias: String, child: LogicalPlan)`
      * `case class NamedRelation(databaseName: String, tableName: String, output: Seq[Attribute])`
      * `class QueryNormalizer(sqlContext: SQLContext) extends RuleExecutor[LogicalPlan] `
      * `class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169563183
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48894/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791979
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -1,9 +1,9 @@
     /**
    -   Licensed to the Apache Software Foundation (ASF) under one or more 
    -   contributor license agreements.  See the NOTICE file distributed with 
    +   Licensed to the Apache Software Foundation (ASF) under one or more
    +   contributor license agreements.  See the NOTICE file distributed with
        this work for additional information regarding copyright ownership.
        The ASF licenses this file to You under the Apache License, Version 2.0
    -   (the "License"); you may not use this file except in compliance with 
    +   (the "License"); you may not use this file except in compliance with
    --- End diff --
    
    Revert these?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169809983
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49229231
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -63,7 +63,9 @@ abstract class Optimizer extends RuleExecutor[LogicalPlan] {
           RemoveDispensableExpressions,
           SimplifyFilters,
           SimplifyCasts,
    -      SimplifyCaseConversionExpressions) ::
    +      SimplifyCaseConversionExpressions,
    +      // Nondeterministic
    +      ComputeCurrentTime) ::
    --- End diff --
    
    Yea, I think we need to make it evaluated before this batch. Otherwise, constant folding rules will fire first, which can potentially introduce problem (multiple CurrentTimestamps returns different answers in a query).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169817788
  
    test this please


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169122517
  
    **[Test build #48781 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48781/consoleFull)** for PR 10541 at commit [`a8805dd`](https://github.com/apache/spark/commit/a8805dd36dbe8094351a90d3e00a22ca6ebc8ddc).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791866
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala ---
    @@ -458,7 +458,9 @@ case class Limit(limitExpr: Expression, child: LogicalPlan) extends UnaryNode {
       }
     }
     
    -case class Subquery(alias: String, child: LogicalPlan) extends UnaryNode {
    +case class Subquery(alias: String, child: LogicalPlan)
    +  extends UnaryNode {
    --- End diff --
    
    Need this change?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48799646
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala ---
    @@ -74,6 +74,12 @@ case class If(predicate: Expression, trueValue: Expression, falseValue: Expressi
       }
     
       override def toString: String = s"if ($predicate) $trueValue else $falseValue"
    +
    +  override def sql: Option[String] = for {
    +    predicateSQL <- predicate.sql
    +    trueSQL <- trueValue.sql
    +    falseSQL <- falseValue.sql
    +  } yield s"(IF($predicateSQL, $trueSQL, $falseSQL))"
     }
     
     trait CaseWhenLike extends Expression {
    --- End diff --
    
    Not yet, support for more expressions and operators is still ongoing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169372469
  
    @rxin SQL generation dedicated test cases are added in `HiveQLSQLBuilderSuite`. Bugs found by round-trip tests in `HiveCompatibilitySuite` are covered there.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169809987
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48949/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49229591
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala ---
    @@ -75,8 +75,7 @@ class FilterPushdownSuite extends PlanTest {
         val correctAnswer =
           testRelation
             .select('a)
    -        .groupBy('a)('a)
    -        .select('a).analyze
    +        .groupBy('a)('a).analyze
    --- End diff --
    
    why change this?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49052923
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala ---
    @@ -1026,4 +1112,8 @@ case class FormatNumber(x: Expression, d: Expression)
       }
     
       override def prettyName: String = "format_number"
    +
    +  override def sql: Option[String] = for {
    +    childrenSQL <- sequenceOption(children.map(_.sql))
    +  } yield s"$prettyName(${childrenSQL.mkString(", ")})"
    --- End diff --
    
    see discussion above https://github.com/apache/spark/pull/10541/files#r49045492


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170139387
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168211120
  
    **[Test build #48558 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48558/consoleFull)** for PR 10541 at commit [`af865a9`](https://github.com/apache/spark/commit/af865a9d5c3b4a7a3ba9af856c4f19250b004e4b).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49043955
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala ---
    @@ -226,6 +234,11 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with
           }
          """
       }
    +
    +  override def sql: Option[String] = for {
    +    valueSQL <- child.sql
    +    listSQL <- sequenceOption(hset.toSeq.map(Literal(_).sql))
    +  } yield s"($valueSQL IN (${listSQL.mkString(", ")}))"
    --- End diff --
    
    We don't call `toString` here. `Literal.sql` handles internal types.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49232235
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -63,7 +63,9 @@ abstract class Optimizer extends RuleExecutor[LogicalPlan] {
           RemoveDispensableExpressions,
           SimplifyFilters,
           SimplifyCasts,
    -      SimplifyCaseConversionExpressions) ::
    +      SimplifyCaseConversionExpressions,
    +      // Nondeterministic
    +      ComputeCurrentTime) ::
    --- End diff --
    
    Good catch, thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169122812
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48781/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49054699
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -333,6 +335,39 @@ object ProjectCollapsing extends Rule[LogicalPlan] {
             )
             Project(cleanedProjection, child)
           }
    +
    +    // TODO Eliminate duplicate code
    +    // This clause is identical to the one above except that the inner operator is an `Aggregate`
    +    // rather than a `Project`.
    +    case p @ Project(projectList1, agg @ Aggregate(_, projectList2, child)) =>
    --- End diff --
    
    If we don't do this, then we will generate something like:
    `select i + 1 from (select sum(b) as i from tbl group by a) t`.
    
    Actually it's same with `select sum(b) + 1 from tbl group by a`, although these 2 sql string doesn't equal. I think our goal is to generate "semantically right" sql string,  not "exactly same" sql string. Please correct me if I missed something here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49040050
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -214,6 +214,41 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case (_, NullType | _: ArrayType | _: MapType | _: StructType) if value == null =>
    +      "NULL"
    --- End diff --
    
    any particular reason that we do not cast null to a complex type?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48738171
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/LogicalPlanSQLGenerationSuite.scala ---
    @@ -0,0 +1,57 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.catalyst.plans.logical.OneRowRelation
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.test.SQLTestUtils
    +
    +// All test cases in this test suite are ignored for now because currently `SQLBuilder` only handles
    +// resolved logical plans parsed directly from HiveQL query strings.
    +class LogicalPlanSQLGenerationSuite extends SQLGenerationTest with SQLTestUtils {
    +  import hiveContext.implicits._
    +
    +  protected override def beforeAll(): Unit = {
    +    super.beforeAll()
    +
    +    sqlContext.range(10).select('id alias "a").registerTempTable("t0")
    +    sqlContext.range(10).select('id alias "b").registerTempTable("t1")
    +  }
    +
    +  protected override def afterAll(): Unit = {
    +    sqlContext.dropTempTable("t0")
    +    sqlContext.dropTempTable("t1")
    +
    +    super.afterAll()
    +  }
    +
    +  ignore("single row project") {
    +    checkSQL(OneRowRelation.select(lit(1)), "SELECT 1 AS `1`")
    +    checkSQL(OneRowRelation.select(lit(1) as 'a), "SELECT 1 AS `a`")
    +  }
    +
    +  ignore("project with limit") {
    +    checkSQL(OneRowRelation.select(lit(1)).limit(1), "SELECT 1 AS `1` LIMIT 1")
    +    checkSQL(OneRowRelation.select(lit(1) as 'a).limit(1), "SELECT 1 AS `a` LIMIT 1")
    +  }
    +
    +  ignore("table lookup") {
    +    checkSQL(sqlContext.table("t0"), "SELECT `t0`.`a` FROM `t0`")
    +    checkSQL(sqlContext.table("t1").select('b alias "c"), "SELECT `t1`.`id` AS `c` FROM `t1`")
    +  }
    +}
    --- End diff --
    
    I think we need some complex test cases like subquery


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169046409
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48763/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169544370
  
    **[Test build #48894 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48894/consoleFull)** for PR 10541 at commit [`c118a35`](https://github.com/apache/spark/commit/c118a354a43f0f9eef83ed92b01f754936c9dfa6).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168220607
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48558/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48739082
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,176 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +
    +    logDebug(
    +      s"""Building SQL query string from given logical plan:
    +         |
    +         |# Original logical plan:
    +         |${logicalPlan.treeString}
    +         |# Canonicalized logical plan:
    +         |${canonicalizedPlan.treeString}
    +       """.stripMargin)
    +
    +    toSQL(canonicalizedPlan)
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case plan @ Project(list, child) =>
    +      for {
    +        listSQL <- sequenceOption(list.map(_.sql))
    +        childSQL <- toSQL(child)
    --- End diff --
    
    Good catch! But `getOrElse` isn't applicable here, because `child` may be some complex query plan other than `OneRowRelation` but we don't support (e.g. a `LocalRelation` built from local Scala `Seq`). I'd add a branch for `OneRowRelation` that returns `Some("")`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49040868
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -2386,8 +2386,8 @@ setColumnsClause
        KW_SET columnAssignmentClause (COMMA columnAssignmentClause)* -> ^(TOK_SET_COLUMNS_CLAUSE columnAssignmentClause* )
        ;
     
    -/* 
    -  UPDATE <table> 
    +/*
    +  UPDATE <table>
    --- End diff --
    
    For these white space things, maybe it is better to not change anything because it may be easy to cause conflict (if we are pretty active on updating the grammar).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49031526
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveQLSQLBuilderSuite.scala ---
    @@ -0,0 +1,129 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.test.SQLTestUtils
    +import org.apache.spark.sql.functions._
    +
    +class HiveQLSQLBuilderSuite extends SQLBuilderTest with SQLTestUtils {
    --- End diff --
    
    The name is mostly because currently we can only process logical plans directly translated from HiveQL query strings. Moving to sql/core sounds good.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168211126
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48556/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48727289
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -637,7 +637,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
       // counter to generate unique union aliases
       private int aliasCounter;
       private String generateUnionAlias() {
    -    return "_u" + (++aliasCounter);
    +    return "u_" + (++aliasCounter);
    --- End diff --
    
    This change is because Hive lexer doesn't allow identifiers starting with underscore.
    
    (All other changes in this file are caused by removing training spaces.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169046403
  
    Build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48738778
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/LogicalPlanSQLGenerationSuite.scala ---
    @@ -0,0 +1,57 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.catalyst.plans.logical.OneRowRelation
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.test.SQLTestUtils
    +
    +// All test cases in this test suite are ignored for now because currently `SQLBuilder` only handles
    +// resolved logical plans parsed directly from HiveQL query strings.
    +class LogicalPlanSQLGenerationSuite extends SQLGenerationTest with SQLTestUtils {
    +  import hiveContext.implicits._
    +
    +  protected override def beforeAll(): Unit = {
    +    super.beforeAll()
    +
    +    sqlContext.range(10).select('id alias "a").registerTempTable("t0")
    +    sqlContext.range(10).select('id alias "b").registerTempTable("t1")
    +  }
    +
    +  protected override def afterAll(): Unit = {
    +    sqlContext.dropTempTable("t0")
    +    sqlContext.dropTempTable("t1")
    +
    +    super.afterAll()
    +  }
    +
    +  ignore("single row project") {
    +    checkSQL(OneRowRelation.select(lit(1)), "SELECT 1 AS `1`")
    +    checkSQL(OneRowRelation.select(lit(1) as 'a), "SELECT 1 AS `a`")
    +  }
    +
    +  ignore("project with limit") {
    +    checkSQL(OneRowRelation.select(lit(1)).limit(1), "SELECT 1 AS `1` LIMIT 1")
    +    checkSQL(OneRowRelation.select(lit(1) as 'a).limit(1), "SELECT 1 AS `a` LIMIT 1")
    +  }
    +
    +  ignore("table lookup") {
    +    checkSQL(sqlContext.table("t0"), "SELECT `t0`.`a` FROM `t0`")
    +    checkSQL(sqlContext.table("t1").select('b alias "c"), "SELECT `t1`.`id` AS `c` FROM `t1`")
    +  }
    +}
    --- End diff --
    
    Currently I mostly use the existing `HiveCompatibilitySuite` for testing SQL generation.  This test suite meant to test query plans built by arbitrary DataFrame API call combinations, which are not supported for now. That's why all test cases are ignored.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168684434
  
    **[Test build #48660 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48660/consoleFull)** for PR 10541 at commit [`4963676`](https://github.com/apache/spark/commit/4963676874b06549e0d344ed91966b0c25670773).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49236301
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -37,6 +37,8 @@ abstract class Optimizer extends RuleExecutor[LogicalPlan] {
         // SubQueries are only needed for analysis and can be removed before execution.
         Batch("Remove SubQueries", FixedPoint(100),
           EliminateSubQueries) ::
    +    Batch("Compute Current Time", Once,
    +      ComputeCurrentTime) ::
    --- End diff --
    
    Let's add a comment to explain it in the follow-up pr.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169097360
  
    **[Test build #48781 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48781/consoleFull)** for PR 10541 at commit [`a8805dd`](https://github.com/apache/spark/commit/a8805dd36dbe8094351a90d3e00a22ca6ebc8ddc).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169240459
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48828/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168194592
  
    **[Test build #48554 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48554/consoleFull)** for PR 10541 at commit [`17e8fba`](https://github.com/apache/spark/commit/17e8fba3484d19e7ca7a993359fdc28004f9dfb8).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `abstract sealed class SortDirection `
      * `sealed abstract class JoinType `
      * `case class Subquery(alias: String, child: LogicalPlan)`
      * `case class NamedRelation(databaseName: String, tableName: String, output: Seq[Attribute])`
      * `class QueryNormalizer(sqlContext: SQLContext) extends RuleExecutor[LogicalPlan] `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169600591
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48906/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791550
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/package.scala ---
    @@ -130,6 +130,17 @@ package object util {
         ret
       }
     
    +  def sequenceOption[T](seq: Seq[Option[T]]): Option[Seq[T]] = seq match {
    --- End diff --
    
    add doc?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49045865
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala ---
    @@ -340,6 +369,12 @@ case class FindInSet(left: Expression, right: Expression) extends BinaryExpressi
       }
     
       override def dataType: DataType = IntegerType
    +
    +  override def prettyName: String = "find_in_set"
    +
    +  override def sql: Option[String] = for {
    --- End diff --
    
    Then maybe simply returns a `String` and throw an exception if the expression is either not supported yet or inherently doesn't have a SQL representation (e.g. ScalaUDF)?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168728499
  
    The following two test cases always fail when executed with other test cases, but always pass when executed separately:
    
    - `HiveCompatibilitySuite.select_as_omitted`
    - `HiveCompatibilitySuite.router_join_ppr`
    
    Both test cases complain table `src` not found when failing. Probably because of side effects done in test cases executed earlier. Still investigating.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48736586
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,176 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    --- End diff --
    
    seems `sqlContext` is un-used?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49044160
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,236 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.catalyst.expressions.{Expression, Attribute, NamedExpression, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +import org.apache.spark.sql.execution.datasources.LogicalRelation
    +import org.apache.spark.sql.execution.datasources.parquet.ParquetRelation
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def this(df: DataFrame) = this(df.queryExecution.analyzed, df.sqlContext)
    +
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +    val maybeSQL = toSQL(canonicalizedPlan)
    +
    +    if (maybeSQL.isDefined) {
    +      logDebug(
    +        s"""Built SQL query string successfully from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +           |# Built SQL query string:
    +           |${maybeSQL.get}
    +         """.stripMargin)
    +    } else {
    +      logDebug(
    +        s"""Failed to build SQL query string from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +         """.stripMargin)
    +    }
    +
    +    maybeSQL
    +  }
    +
    +  private def projectToSQL(
    +      projectList: Seq[NamedExpression],
    +      child: LogicalPlan,
    +      isDistinct: Boolean): Option[String] = {
    +    for {
    +      listSQL <- sequenceOption(projectList.map(_.sql))
    +      childSQL <- toSQL(child)
    +      from = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      distinct = if (isDistinct) " DISTINCT" else ""
    +    } yield s"SELECT$distinct ${listSQL.mkString(", ")}$from$childSQL"
    +  }
    +
    +  private def aggregateToSQL(
    +      groupingExprs: Seq[Expression],
    +      aggExprs: Seq[Expression],
    +      child: LogicalPlan): Option[String] = {
    +    for {
    +      aggSQL <- sequenceOption(aggExprs.map(_.sql))
    +      groupingSQL <- sequenceOption(groupingExprs.map(_.sql))
    +      maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +      maybeFrom = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      childSQL <- toSQL(child).map(maybeFrom + _)
    +    } yield {
    +      s"SELECT ${aggSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +    }
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case Distinct(Project(list, child)) =>
    +      projectToSQL(list, child, isDistinct = true)
    +
    +    case Project(list, child) =>
    +      projectToSQL(list, child, isDistinct = false)
    +
    +    case Aggregate(groupingExprs, aggExprs, Aggregate(_, _, Expand(_, _, child))) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Aggregate(groupingExprs, aggExprs, child) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    +          case _ => "WHERE"
    +        }
    +      } yield s"$childSQL $whereOrHaving $conditionSQL"
    +
    +    case Union(left, right) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +      } yield s"$leftSQL UNION ALL $rightSQL"
    +
    +    // ParquetRelation converted from Hive metastore table
    +    case Subquery(alias, LogicalRelation(r: ParquetRelation, _)) =>
    +      Some(s"`$alias`")
    --- End diff --
    
    (Here I meant to use `ParquetRelation.metastoreTableName`, which includes database name.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48737118
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,176 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +
    +    logDebug(
    +      s"""Building SQL query string from given logical plan:
    +         |
    +         |# Original logical plan:
    +         |${logicalPlan.treeString}
    +         |# Canonicalized logical plan:
    +         |${canonicalizedPlan.treeString}
    +       """.stripMargin)
    +
    +    toSQL(canonicalizedPlan)
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case plan @ Project(list, child) =>
    +      for {
    +        listSQL <- sequenceOption(list.map(_.sql))
    +        childSQL <- toSQL(child)
    --- End diff --
    
    if `child` is `OneRowRelation`, will `toSQL(child)` return `None`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48792162
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,176 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    --- End diff --
    
    How about we add it back when we need it later?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169736701
  
    **[Test build #48949 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48949/consoleFull)** for PR 10541 at commit [`2073e30`](https://github.com/apache/spark/commit/2073e305f994d1f3b850fcf18e37002761979670).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168676148
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48657/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49039562
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Count.scala ---
    @@ -19,6 +19,7 @@ package org.apache.spark.sql.catalyst.expressions.aggregate
     
     import org.apache.spark.sql.catalyst.dsl.expressions._
     import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    --- End diff --
    
    Remove it?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48792346
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,180 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +
    +    logDebug(
    +      s"""Building SQL query string from given logical plan:
    +         |
    +         |# Original logical plan:
    +         |${logicalPlan.treeString}
    +         |# Canonicalized logical plan:
    +         |${canonicalizedPlan.treeString}
    +       """.stripMargin)
    +
    +    toSQL(canonicalizedPlan)
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case plan @ Project(list, child) =>
    +      for {
    +        listSQL <- sequenceOption(list.map(_.sql))
    +        childSQL <- toSQL(child)
    +        from = child match {
    +          case OneRowRelation => ""
    +          case _ => " FROM "
    +        }
    +      } yield s"SELECT ${listSQL.mkString(", ")}$from$childSQL"
    +
    +    case plan @ Aggregate(groupingExpressions, aggregateExpressions, child) =>
    +      for {
    +        aggregateSQL <- sequenceOption(aggregateExpressions.map(_.sql))
    +        groupingSQL <- sequenceOption(groupingExpressions.map(_.sql))
    +        maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +        maybeFrom = child match {
    +          case OneRowRelation => ""
    +          case _ => " FROM "
    +        }
    +        childSQL <- toSQL(child).map(maybeFrom + _)
    +      } yield {
    +        s"SELECT ${aggregateSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +      }
    +
    +    case plan @ Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case plan @ Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    --- End diff --
    
    Is it guaranteed that this agg is the child of this filter for having? Should we always use where and put childSql in a subquery block?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169373304
  
    **[Test build #48860 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48860/consoleFull)** for PR 10541 at commit [`2e784b9`](https://github.com/apache/spark/commit/2e784b93c677b833695694186fefcc9d94555e6f).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168729284
  
    According to local testing result, now 75% query plans in `HiveCompatibilitySuite` can be successfully converted to SQL query strings.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49041161
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,236 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.catalyst.expressions.{Expression, Attribute, NamedExpression, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +import org.apache.spark.sql.execution.datasources.LogicalRelation
    +import org.apache.spark.sql.execution.datasources.parquet.ParquetRelation
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def this(df: DataFrame) = this(df.queryExecution.analyzed, df.sqlContext)
    +
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +    val maybeSQL = toSQL(canonicalizedPlan)
    +
    +    if (maybeSQL.isDefined) {
    +      logDebug(
    +        s"""Built SQL query string successfully from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +           |# Built SQL query string:
    +           |${maybeSQL.get}
    +         """.stripMargin)
    +    } else {
    +      logDebug(
    +        s"""Failed to build SQL query string from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +         """.stripMargin)
    +    }
    +
    +    maybeSQL
    +  }
    +
    +  private def projectToSQL(
    +      projectList: Seq[NamedExpression],
    +      child: LogicalPlan,
    +      isDistinct: Boolean): Option[String] = {
    +    for {
    +      listSQL <- sequenceOption(projectList.map(_.sql))
    +      childSQL <- toSQL(child)
    +      from = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      distinct = if (isDistinct) " DISTINCT" else ""
    +    } yield s"SELECT$distinct ${listSQL.mkString(", ")}$from$childSQL"
    +  }
    +
    +  private def aggregateToSQL(
    +      groupingExprs: Seq[Expression],
    +      aggExprs: Seq[Expression],
    +      child: LogicalPlan): Option[String] = {
    +    for {
    +      aggSQL <- sequenceOption(aggExprs.map(_.sql))
    +      groupingSQL <- sequenceOption(groupingExprs.map(_.sql))
    +      maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +      maybeFrom = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      childSQL <- toSQL(child).map(maybeFrom + _)
    +    } yield {
    +      s"SELECT ${aggSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +    }
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case Distinct(Project(list, child)) =>
    +      projectToSQL(list, child, isDistinct = true)
    +
    +    case Project(list, child) =>
    +      projectToSQL(list, child, isDistinct = false)
    +
    +    case Aggregate(groupingExprs, aggExprs, Aggregate(_, _, Expand(_, _, child))) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Aggregate(groupingExprs, aggExprs, child) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    +          case _ => "WHERE"
    +        }
    +      } yield s"$childSQL $whereOrHaving $conditionSQL"
    +
    +    case Union(left, right) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +      } yield s"$leftSQL UNION ALL $rightSQL"
    +
    +    // ParquetRelation converted from Hive metastore table
    +    case Subquery(alias, LogicalRelation(r: ParquetRelation, _)) =>
    +      Some(s"`$alias`")
    +
    +    case Subquery(alias, child) =>
    +      toSQL(child).map(childSQL => s"($childSQL) AS $alias")
    +
    +    case Join(left, right, joinType, condition) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +        joinTypeSQL = joinType.sql
    +        conditionSQL = condition.flatMap(_.sql).map(" ON " + _).getOrElse("")
    +      } yield s"$leftSQL $joinTypeSQL JOIN $rightSQL$conditionSQL"
    +
    +    case MetastoreRelation(database, table, alias) =>
    +      val aliasSQL = alias.map(a => s" AS `$a`").getOrElse("")
    +      Some(s"`$database`.`$table`$aliasSQL")
    +
    +    case Sort(orders, _, RepartitionByExpression(partitionExprs, child, _))
    +        if orders.map(_.child) == partitionExprs =>
    +      for {
    +        partitionExprsSQL <- sequenceOption(partitionExprs.map(_.sql))
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL CLUSTER BY ${partitionExprsSQL.mkString(", ")}"
    +
    +    case Sort(orders, global, child) =>
    +      for {
    +        childSQL <- toSQL(child)
    +        ordersSQL <- sequenceOption(orders.map { case SortOrder(e, dir) =>
    +          e.sql.map(sql => s"$sql ${dir.sql}")
    +        })
    +        orderOrSort = if (global) "ORDER" else "SORT"
    +      } yield s"$childSQL $orderOrSort BY ${ordersSQL.mkString(", ")}"
    +
    +    case RepartitionByExpression(partitionExprs, child, _) =>
    +      for {
    +        partitionExprsSQL <- sequenceOption(partitionExprs.map(_.sql))
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL DISTRIBUTE BY ${partitionExprsSQL.mkString(", ")}"
    +
    +    case OneRowRelation =>
    +      Some("")
    +
    +    case _ => None
    +  }
    +
    +  object Canonicalizer extends RuleExecutor[LogicalPlan] {
    +    override protected def batches: Seq[Batch] = Seq(
    +      Batch("Normalizer", FixedPoint(100),
    +        // The `WidenSetOperationTypes` analysis rule may introduce extra `Project`s over
    +        // `Aggregate`s to perform type casting.  This rule merges these `Project`s into
    +        // `Aggregate`s.
    +        ProjectCollapsing,
    --- End diff --
    
    Do we have to have this rule? I mean should we just create a sub-query block to wrap the aggregate?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49040375
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/randomExpressions.scala ---
    @@ -49,6 +49,8 @@ abstract class RDG extends LeafExpression with Nondeterministic {
       override def nullable: Boolean = false
     
       override def dataType: DataType = DoubleType
    +
    +  override def sql: Option[String] = Some(s"${prettyName.toUpperCase}($seed)")
    --- End diff --
    
    it is good to add a doc at here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169573436
  
    **[Test build #48906 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48906/consoleFull)** for PR 10541 at commit [`11807bd`](https://github.com/apache/spark/commit/11807bdaaedc836da0a75ff2dc6c5efde9d62e9e).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48728134
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -637,7 +637,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
       // counter to generate unique union aliases
       private int aliasCounter;
       private String generateUnionAlias() {
    -    return "_u" + (++aliasCounter);
    +    return "u_" + (++aliasCounter);
    --- End diff --
    
    Ok, perfect!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170139094
  
    **[Test build #49026 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/49026/consoleFull)** for PR 10541 at commit [`97cd39e`](https://github.com/apache/spark/commit/97cd39e146ce1a4b49e3ca01b8a44906d7b19351).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170143505
  
    Thanks all for the review!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48796917
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicOperators.scala ---
    @@ -458,7 +458,9 @@ case class Limit(limitExpr: Expression, child: LogicalPlan) extends UnaryNode {
       }
     }
     
    -case class Subquery(alias: String, child: LogicalPlan) extends UnaryNode {
    +case class Subquery(alias: String, child: LogicalPlan)
    +  extends UnaryNode {
    --- End diff --
    
    I had once modified `Subquery` and then reverted the essential change. Will revert this one.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168191248
  
    **[Test build #48554 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48554/consoleFull)** for PR 10541 at commit [`17e8fba`](https://github.com/apache/spark/commit/17e8fba3484d19e7ca7a993359fdc28004f9dfb8).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by hvanhovell <gi...@git.apache.org>.
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48727799
  
    --- Diff: sql/hive/src/main/antlr3/org/apache/spark/sql/parser/SparkSqlParser.g ---
    @@ -637,7 +637,7 @@ import org.apache.hadoop.hive.conf.HiveConf;
       // counter to generate unique union aliases
       private int aliasCounter;
       private String generateUnionAlias() {
    -    return "_u" + (++aliasCounter);
    +    return "u_" + (++aliasCounter);
    --- End diff --
    
    Am I correct to say that this only happens in the following (test) scenario?
    ```HQL Statement -> Logical Plan -> HQL Statement (with generated names) -> Logical Plan```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48988896
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveQLSQLBuilderSuite.scala ---
    @@ -0,0 +1,129 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.test.SQLTestUtils
    +import org.apache.spark.sql.functions._
    +
    +class HiveQLSQLBuilderSuite extends SQLBuilderTest with SQLTestUtils {
    --- End diff --
    
    why is this called HiveQLSQLBuilderSuite? 
    
    We should move this to sql/core after https://github.com/apache/spark/pull/10583


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169240458
  
    Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48988990
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveQLSQLBuilderSuite.scala ---
    @@ -0,0 +1,129 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.test.SQLTestUtils
    +import org.apache.spark.sql.functions._
    +
    +class HiveQLSQLBuilderSuite extends SQLBuilderTest with SQLTestUtils {
    --- End diff --
    
    We can call this LogicalPlanToSQLSuite


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49043511
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala ---
    @@ -931,6 +931,14 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression {
             $evPrim = $result.copy();
           """
       }
    +
    +  override def sql: Option[String] = {
    +    if (foldable) {
    +      Literal.create(eval(), dataType).sql
    +    } else {
    +      child.sql.map(childSQL => s"CAST($childSQL AS ${dataType.sql})")
    --- End diff --
    
    Yeah, I also found this change introduced a bug and caused test failure. Actually the major concern here is casting to complex types. HiveQL doesn't allow casting to complex types.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168733598
  
    **[Test build #48667 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48667/consoleFull)** for PR 10541 at commit [`1d5dd3b`](https://github.com/apache/spark/commit/1d5dd3b9fd9e64de517d87e854460da877bd66a2).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49039679
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala ---
    @@ -163,6 +173,12 @@ sealed abstract class AggregateFunction extends Expression with ImplicitCastInpu
       def toAggregateExpression(isDistinct: Boolean): AggregateExpression = {
         AggregateExpression(aggregateFunction = this, mode = Complete, isDistinct = isDistinct)
       }
    +
    +  override def sql: Option[String] = argumentsSQL.map(sql => s"${prettyName.toUpperCase}($sql)")
    --- End diff --
    
    Actually, do we need to define it at here? We always have an `AggregateExpression` wrapping an `AggregateFunction`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168338815
  
    The jira ticket is linked incorrectly I think.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791158
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -213,6 +215,34 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case _ if value == null =>
    +      "NULL"
    +
    +    case (v: UTF8String, StringType) =>
    +      "\"" + v.toString.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
    +
    +    case (v: Byte, ByteType) =>
    +      s"CAST($v AS ${ByteType.simpleString.toUpperCase})"
    +
    +    case (v: Short, ShortType) =>
    +      s"CAST($v AS ${ShortType.simpleString.toUpperCase})"
    +
    +    case (v: Long, LongType) =>
    +      s"CAST($v AS ${LongType.simpleString.toUpperCase})"
    +
    +    case (v: Float, FloatType) =>
    +      s"CAST($v AS ${FloatType.simpleString.toUpperCase})"
    +
    +    case (v: Decimal, DecimalType.Fixed(precision, scale)) =>
    +      s"CAST($v AS ${DecimalType.simpleString.toUpperCase}($precision, $scale))"
    +
    +    case (v: Int, DateType) =>
    +      s"DATE '${DateTimeUtils.toJavaDate(v)}'"
    --- End diff --
    
    Also add timestamp?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168756600
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791281
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -213,6 +215,34 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case _ if value == null =>
    +      "NULL"
    --- End diff --
    
    Will we lose data type for this null literal? Should we create a cast if the data type is not `NullType`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169133875
  
    Build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169371791
  
    Added support for more expressions and logical plans. Now 94.2% queries in `HiveCompatibilitySuite` are covered (window functions are not included in this suite). Unsupported expressions and logical plans are listed in the PR description, and can be done in follow-up PRs.
    
    cc @yhuai


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169675535
  
    **[Test build #48940 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48940/consoleFull)** for PR 10541 at commit [`a304392`](https://github.com/apache/spark/commit/a304392602160ac5cf84b83eda60170842e85200).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169549618
  
    The framework of generating sql looks good. We can use follow-up prs to support more operators.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169395616
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169571252
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48904/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49228304
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -63,7 +63,9 @@ abstract class Optimizer extends RuleExecutor[LogicalPlan] {
           RemoveDispensableExpressions,
           SimplifyFilters,
           SimplifyCasts,
    -      SimplifyCaseConversionExpressions) ::
    +      SimplifyCaseConversionExpressions,
    +      // Nondeterministic
    +      ComputeCurrentTime) ::
    --- End diff --
    
    Should it be the first batch after the batch of `Remove SubQueries`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49041307
  
    --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/LogicalPlanSQLBuilderSuite.scala ---
    @@ -0,0 +1,57 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import org.apache.spark.sql.catalyst.plans.logical.OneRowRelation
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.test.SQLTestUtils
    +
    +// All test cases in this test suite are ignored for now because currently `SQLBuilder` only handles
    +// resolved logical plans parsed directly from HiveQL query strings.
    +class LogicalPlanSQLBuilderSuite extends SQLBuilderTest with SQLTestUtils {
    +  import hiveContext.implicits._
    +
    +  protected override def beforeAll(): Unit = {
    +    super.beforeAll()
    +
    +    sqlContext.range(10).select('id alias "a").registerTempTable("t0")
    +    sqlContext.range(10).select('id alias "b").registerTempTable("t1")
    +  }
    +
    +  protected override def afterAll(): Unit = {
    +    sqlContext.dropTempTable("t0")
    +    sqlContext.dropTempTable("t1")
    +
    +    super.afterAll()
    +  }
    +
    +  ignore("single row project") {
    +    checkSQL(OneRowRelation.select(lit(1)), "SELECT 1 AS `1`")
    +    checkSQL(OneRowRelation.select(lit(1) as 'a), "SELECT 1 AS `a`")
    --- End diff --
    
    So, the analyzed plan of ```"SELECT 1 AS `a`"``` is different from `OneRowRelation.select(lit(1) as 'a)`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168190691
  
    When running any test suite that extends `HiveComparisonTest`, detail logs can be found in `sql/hive/target/unit-tests.log`.  If a query string is convertible, we may see something like this (the triple-braces are added so that Vim recognizes them as fold marks.):
    
    ```
    ### Running SQL generation round-trip test {{{
    Project [key#357,value#358,ds#356]
    +- MetastoreRelation default, add_part_test, None
    
    Original SQL:
    select * from add_part_test
    
    Generated SQL:
    SELECT `add_part_test`.`key`, `add_part_test`.`value`, `add_part_test`.`ds` FROM `default`.`add_part_test`
    }}}
    ```
    
    Otherwise, we may see something like this:
    
    ```
    ### Cannot convert the following logical plan back to SQL {{{
    Aggregate [(sum(cast(HiveGenericUDF#org.apache.hadoop.hive.ql.udf.generic.GenericUDFHash(key#2853,value#2854) as bigint)),mode=Complete,isDistinct=false) AS _c0#2855L]
    +- MetastoreRelation default, dest_j1, None
    
    Original SQL:
    SELECT sum(hash(dest_j1.key,dest_j1.value)) FROM dest_j1
    }}}
    ```
    
    In this way we can figure out the percentage of convertible query plans. Ideally the percentage should be calculated automatically.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169696240
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49045425
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala ---
    @@ -206,6 +212,25 @@ case class CaseWhen(branches: Seq[Expression]) extends CaseWhenLike {
           case Seq(elseValue) => s" ELSE $elseValue"
         }.mkString
       }
    +
    +  override def sql: Option[String] = {
    +    sequenceOption(branches.map(_.sql)).map {
    +      case branchesSQL =>
    --- End diff --
    
    why "case" here? maybe put this on the previous line to save one level of indentation.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168756602
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48667/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169600275
  
    **[Test build #48906 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48906/consoleFull)** for PR 10541 at commit [`11807bd`](https://github.com/apache/spark/commit/11807bdaaedc836da0a75ff2dc6c5efde9d62e9e).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168702388
  
    Hm, seems that my last fixes introduced bug related to UDF handling. Looking into it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170096777
  
    Let's also create a jira for supporting persisted data source tables.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168211125
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49045492
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala ---
    @@ -340,6 +369,12 @@ case class FindInSet(left: Expression, right: Expression) extends BinaryExpressi
       }
     
       override def dataType: DataType = IntegerType
    +
    +  override def prettyName: String = "find_in_set"
    +
    +  override def sql: Option[String] = for {
    --- End diff --
    
    Can you see how many expressions don't support sql? It is pretty silly to duplicate so much code that does the same thing (option.map(..))


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169547329
  
    Does this version support data source tables? Also, we need to move `ComputeCurrentTime` to optimizer, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169867422
  
    **[Test build #48996 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48996/consoleFull)** for PR 10541 at commit [`2073e30`](https://github.com/apache/spark/commit/2073e305f994d1f3b850fcf18e37002761979670).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49044197
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,236 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.catalyst.expressions.{Expression, Attribute, NamedExpression, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +import org.apache.spark.sql.execution.datasources.LogicalRelation
    +import org.apache.spark.sql.execution.datasources.parquet.ParquetRelation
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def this(df: DataFrame) = this(df.queryExecution.analyzed, df.sqlContext)
    +
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +    val maybeSQL = toSQL(canonicalizedPlan)
    +
    +    if (maybeSQL.isDefined) {
    +      logDebug(
    +        s"""Built SQL query string successfully from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +           |# Built SQL query string:
    +           |${maybeSQL.get}
    +         """.stripMargin)
    +    } else {
    +      logDebug(
    +        s"""Failed to build SQL query string from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +         """.stripMargin)
    +    }
    +
    +    maybeSQL
    +  }
    +
    +  private def projectToSQL(
    +      projectList: Seq[NamedExpression],
    +      child: LogicalPlan,
    +      isDistinct: Boolean): Option[String] = {
    +    for {
    +      listSQL <- sequenceOption(projectList.map(_.sql))
    +      childSQL <- toSQL(child)
    +      from = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      distinct = if (isDistinct) " DISTINCT" else ""
    +    } yield s"SELECT$distinct ${listSQL.mkString(", ")}$from$childSQL"
    +  }
    +
    +  private def aggregateToSQL(
    +      groupingExprs: Seq[Expression],
    +      aggExprs: Seq[Expression],
    +      child: LogicalPlan): Option[String] = {
    +    for {
    +      aggSQL <- sequenceOption(aggExprs.map(_.sql))
    +      groupingSQL <- sequenceOption(groupingExprs.map(_.sql))
    +      maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +      maybeFrom = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      childSQL <- toSQL(child).map(maybeFrom + _)
    +    } yield {
    +      s"SELECT ${aggSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +    }
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case Distinct(Project(list, child)) =>
    +      projectToSQL(list, child, isDistinct = true)
    +
    +    case Project(list, child) =>
    +      projectToSQL(list, child, isDistinct = false)
    +
    +    case Aggregate(groupingExprs, aggExprs, Aggregate(_, _, Expand(_, _, child))) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Aggregate(groupingExprs, aggExprs, child) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    +          case _ => "WHERE"
    +        }
    +      } yield s"$childSQL $whereOrHaving $conditionSQL"
    +
    +    case Union(left, right) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +      } yield s"$leftSQL UNION ALL $rightSQL"
    +
    +    // ParquetRelation converted from Hive metastore table
    +    case Subquery(alias, LogicalRelation(r: ParquetRelation, _)) =>
    +      Some(s"`$alias`")
    +
    +    case Subquery(alias, child) =>
    +      toSQL(child).map(childSQL => s"($childSQL) AS $alias")
    +
    +    case Join(left, right, joinType, condition) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +        joinTypeSQL = joinType.sql
    +        conditionSQL = condition.flatMap(_.sql).map(" ON " + _).getOrElse("")
    +      } yield s"$leftSQL $joinTypeSQL JOIN $rightSQL$conditionSQL"
    +
    +    case MetastoreRelation(database, table, alias) =>
    +      val aliasSQL = alias.map(a => s" AS `$a`").getOrElse("")
    +      Some(s"`$database`.`$table`$aliasSQL")
    +
    +    case Sort(orders, _, RepartitionByExpression(partitionExprs, child, _))
    +        if orders.map(_.child) == partitionExprs =>
    +      for {
    +        partitionExprsSQL <- sequenceOption(partitionExprs.map(_.sql))
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL CLUSTER BY ${partitionExprsSQL.mkString(", ")}"
    +
    +    case Sort(orders, global, child) =>
    +      for {
    +        childSQL <- toSQL(child)
    +        ordersSQL <- sequenceOption(orders.map { case SortOrder(e, dir) =>
    +          e.sql.map(sql => s"$sql ${dir.sql}")
    +        })
    +        orderOrSort = if (global) "ORDER" else "SORT"
    +      } yield s"$childSQL $orderOrSort BY ${ordersSQL.mkString(", ")}"
    +
    +    case RepartitionByExpression(partitionExprs, child, _) =>
    +      for {
    +        partitionExprsSQL <- sequenceOption(partitionExprs.map(_.sql))
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL DISTRIBUTE BY ${partitionExprsSQL.mkString(", ")}"
    +
    +    case OneRowRelation =>
    +      Some("")
    +
    +    case _ => None
    +  }
    +
    +  object Canonicalizer extends RuleExecutor[LogicalPlan] {
    +    override protected def batches: Seq[Batch] = Seq(
    +      Batch("Normalizer", FixedPoint(100),
    +        // The `WidenSetOperationTypes` analysis rule may introduce extra `Project`s over
    +        // `Aggregate`s to perform type casting.  This rule merges these `Project`s into
    +        // `Aggregate`s.
    +        ProjectCollapsing,
    --- End diff --
    
    This isn't absolutely necessary, but would simplify generated SQL in many cases.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170141389
  
    Merging to master.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49225349
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,244 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression, NamedExpression, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.execution.datasources.LogicalRelation
    +import org.apache.spark.sql.execution.datasources.parquet.ParquetRelation
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +/**
    + * A builder class used to convert a resolved logical plan into a SQL query string.  Note that this
    + * all resolved logical plan are convertible.  They either don't have corresponding SQL
    + * representations (e.g. logical plans that operate on local Scala collections), or are simply not
    + * supported by this builder (yet).
    + */
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def this(df: DataFrame) = this(df.queryExecution.analyzed, df.sqlContext)
    +
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +    val maybeSQL = try {
    +      toSQL(canonicalizedPlan)
    +    } catch { case cause: UnsupportedOperationException =>
    +      logInfo(s"Failed to build SQL query string because: ${cause.getMessage}")
    +      None
    +    }
    +
    +    if (maybeSQL.isDefined) {
    +      logDebug(
    +        s"""Built SQL query string successfully from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +           |# Built SQL query string:
    +           |${maybeSQL.get}
    +         """.stripMargin)
    +    } else {
    +      logDebug(
    +        s"""Failed to build SQL query string from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +         """.stripMargin)
    +    }
    +
    +    maybeSQL
    +  }
    +
    +  private def projectToSQL(
    +      projectList: Seq[NamedExpression],
    +      child: LogicalPlan,
    +      isDistinct: Boolean): Option[String] = {
    +    for {
    +      childSQL <- toSQL(child)
    +      listSQL = projectList.map(_.sql).mkString(", ")
    +      maybeFrom = child match {
    +        case OneRowRelation => " "
    +        case _ => " FROM "
    +      }
    +      distinct = if (isDistinct) " DISTINCT " else " "
    +    } yield s"SELECT$distinct$listSQL$maybeFrom$childSQL"
    +  }
    +
    +  private def aggregateToSQL(
    +      groupingExprs: Seq[Expression],
    +      aggExprs: Seq[Expression],
    +      child: LogicalPlan): Option[String] = {
    +    val aggSQL = aggExprs.map(_.sql).mkString(", ")
    +    val groupingSQL = groupingExprs.map(_.sql).mkString(", ")
    +    val maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +    val maybeFrom = child match {
    +      case OneRowRelation => " "
    +      case _ => " FROM "
    +    }
    +
    +    toSQL(child).map { childSQL =>
    +      s"SELECT $aggSQL$maybeFrom$childSQL$maybeGroupBy$groupingSQL"
    +    }
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case Distinct(Project(list, child)) =>
    +      projectToSQL(list, child, isDistinct = true)
    +
    +    case Project(list, child) =>
    +      projectToSQL(list, child, isDistinct = false)
    +
    +    case Aggregate(groupingExprs, aggExprs, child) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Limit(limit, child) =>
    +      for {
    +        childSQL <- toSQL(child)
    +        limitSQL = limit.sql
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case Filter(condition, child) =>
    +      for {
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    +          case _ => "WHERE"
    +        }
    +        conditionSQL = condition.sql
    +      } yield s"$childSQL $whereOrHaving $conditionSQL"
    +
    +    case Union(left, right) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +      } yield s"$leftSQL UNION ALL $rightSQL"
    +
    +    // ParquetRelation converted from Hive metastore table
    +    case Subquery(alias, LogicalRelation(r: ParquetRelation, _)) =>
    +      // There seems to be a bug related to `ParquetConversions` analysis rule.  The problem is
    +      // that, the metastore database name and table name are not always propagated to converted
    +      // `ParquetRelation` instances via data source options.  Here we use subquery alias as a
    +      // workaround.
    +      Some(s"`$alias`")
    --- End diff --
    
    Let's create a jira for this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169133877
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48779/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49041044
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,236 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.catalyst.expressions.{Expression, Attribute, NamedExpression, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +import org.apache.spark.sql.execution.datasources.LogicalRelation
    +import org.apache.spark.sql.execution.datasources.parquet.ParquetRelation
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def this(df: DataFrame) = this(df.queryExecution.analyzed, df.sqlContext)
    +
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +    val maybeSQL = toSQL(canonicalizedPlan)
    +
    +    if (maybeSQL.isDefined) {
    +      logDebug(
    +        s"""Built SQL query string successfully from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +           |# Built SQL query string:
    +           |${maybeSQL.get}
    +         """.stripMargin)
    +    } else {
    +      logDebug(
    +        s"""Failed to build SQL query string from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +         """.stripMargin)
    +    }
    +
    +    maybeSQL
    +  }
    +
    +  private def projectToSQL(
    +      projectList: Seq[NamedExpression],
    +      child: LogicalPlan,
    +      isDistinct: Boolean): Option[String] = {
    +    for {
    +      listSQL <- sequenceOption(projectList.map(_.sql))
    +      childSQL <- toSQL(child)
    +      from = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      distinct = if (isDistinct) " DISTINCT" else ""
    +    } yield s"SELECT$distinct ${listSQL.mkString(", ")}$from$childSQL"
    +  }
    +
    +  private def aggregateToSQL(
    +      groupingExprs: Seq[Expression],
    +      aggExprs: Seq[Expression],
    +      child: LogicalPlan): Option[String] = {
    +    for {
    +      aggSQL <- sequenceOption(aggExprs.map(_.sql))
    +      groupingSQL <- sequenceOption(groupingExprs.map(_.sql))
    +      maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +      maybeFrom = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      childSQL <- toSQL(child).map(maybeFrom + _)
    +    } yield {
    +      s"SELECT ${aggSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +    }
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case Distinct(Project(list, child)) =>
    +      projectToSQL(list, child, isDistinct = true)
    +
    +    case Project(list, child) =>
    +      projectToSQL(list, child, isDistinct = false)
    +
    +    case Aggregate(groupingExprs, aggExprs, Aggregate(_, _, Expand(_, _, child))) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Aggregate(groupingExprs, aggExprs, child) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    +          case _ => "WHERE"
    +        }
    +      } yield s"$childSQL $whereOrHaving $conditionSQL"
    +
    +    case Union(left, right) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +      } yield s"$leftSQL UNION ALL $rightSQL"
    +
    +    // ParquetRelation converted from Hive metastore table
    +    case Subquery(alias, LogicalRelation(r: ParquetRelation, _)) =>
    +      Some(s"`$alias`")
    --- End diff --
    
    Looks like we are losing the db name?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49231991
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala ---
    @@ -75,8 +75,7 @@ class FilterPushdownSuite extends PlanTest {
         val correctAnswer =
           testRelation
             .select('a)
    -        .groupBy('a)('a)
    -        .select('a).analyze
    +        .groupBy('a)('a).analyze
    --- End diff --
    
    Because now `ProjectCollapsing` is able to remove the redundant projection at the top.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169600590
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48737999
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -333,6 +333,39 @@ object ProjectCollapsing extends Rule[LogicalPlan] {
             )
             Project(cleanedProjection, child)
           }
    +
    +    // TODO Eliminate duplicate code
    +    // This clause is identical to the one above except that the inner operator is an `Aggregate`
    +    // rather than a `Project`.
    +    case p @ Project(projectList1, agg @ Aggregate(_, projectList2, child)) =>
    --- End diff --
    
    Will it increase the aggregation buffer? cc @yhuai 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170139390
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/49026/
    Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49043705
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/interfaces.scala ---
    @@ -163,6 +173,12 @@ sealed abstract class AggregateFunction extends Expression with ImplicitCastInpu
       def toAggregateExpression(isDistinct: Boolean): AggregateExpression = {
         AggregateExpression(aggregateFunction = this, mode = Complete, isDistinct = isDistinct)
       }
    +
    +  override def sql: Option[String] = argumentsSQL.map(sql => s"${prettyName.toUpperCase}($sql)")
    --- End diff --
    
    Sounds reasonable. I'm removing `sql` and `argumentsSQL` in `AggregateFunction`. Also removing `toUpperCase` calls.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168737620
  
    Merged build finished. Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170113799
  
    **[Test build #49026 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/49026/consoleFull)** for PR 10541 at commit [`97cd39e`](https://github.com/apache/spark/commit/97cd39e146ce1a4b49e3ca01b8a44906d7b19351).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169046102
  
    **[Test build #48763 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48763/consoleFull)** for PR 10541 at commit [`1e50288`](https://github.com/apache/spark/commit/1e50288d6f956608b53554d31bd394bf919812e0).
     * This patch **fails Spark unit tests**.
     * This patch **does not merge cleanly**.
     * This patch adds the following public classes _(experimental)_:
      * `case class Subquery(alias: String, child: LogicalPlan) extends UnaryNode `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48803221
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,180 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.expressions.{NamedExpression, Attribute, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +
    +    logDebug(
    +      s"""Building SQL query string from given logical plan:
    +         |
    +         |# Original logical plan:
    +         |${logicalPlan.treeString}
    +         |# Canonicalized logical plan:
    +         |${canonicalizedPlan.treeString}
    +       """.stripMargin)
    +
    +    toSQL(canonicalizedPlan)
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case plan @ Project(list, child) =>
    +      for {
    +        listSQL <- sequenceOption(list.map(_.sql))
    +        childSQL <- toSQL(child)
    +        from = child match {
    +          case OneRowRelation => ""
    +          case _ => " FROM "
    +        }
    +      } yield s"SELECT ${listSQL.mkString(", ")}$from$childSQL"
    +
    +    case plan @ Aggregate(groupingExpressions, aggregateExpressions, child) =>
    +      for {
    +        aggregateSQL <- sequenceOption(aggregateExpressions.map(_.sql))
    +        groupingSQL <- sequenceOption(groupingExpressions.map(_.sql))
    +        maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +        maybeFrom = child match {
    +          case OneRowRelation => ""
    +          case _ => " FROM "
    +        }
    +        childSQL <- toSQL(child).map(maybeFrom + _)
    +      } yield {
    +        s"SELECT ${aggregateSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +      }
    +
    +    case plan @ Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case plan @ Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    --- End diff --
    
    For query plans translated directly from HiveSQL, `Filter`s always stay directly above `Aggregate`s. But there might be analysis rules that insert extra auxiliary operators (e.g. `Project`s for type casting). Using subqueries might be a good idea. Need more investigation. Thanks for the suggestion!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48796988
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala ---
    @@ -226,6 +234,10 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with
           }
          """
       }
    +
    +  override def sql: Option[String] = for {
    +    valueSQL :: listSQL <- sequenceOption(children.map(_.sql))
    +  } yield s"($valueSQL IN (${listSQL.mkString(", ")}))"
    --- End diff --
    
    Good catch!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168737378
  
    **[Test build #48665 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48665/consoleFull)** for PR 10541 at commit [`70af178`](https://github.com/apache/spark/commit/70af178e1d734e9df74eba71f3d2c4426d56dfbb).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168737626
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48665/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49044129
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/SQLBuilder.scala ---
    @@ -0,0 +1,236 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.util.concurrent.atomic.AtomicLong
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.sql.catalyst.expressions.{Expression, Attribute, NamedExpression, SortOrder}
    +import org.apache.spark.sql.catalyst.optimizer.ProjectCollapsing
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.catalyst.rules.{Rule, RuleExecutor}
    +import org.apache.spark.sql.catalyst.util.sequenceOption
    +import org.apache.spark.sql.execution.datasources.LogicalRelation
    +import org.apache.spark.sql.execution.datasources.parquet.ParquetRelation
    +import org.apache.spark.sql.{DataFrame, SQLContext}
    +
    +class SQLBuilder(logicalPlan: LogicalPlan, sqlContext: SQLContext) extends Logging {
    +  def this(df: DataFrame) = this(df.queryExecution.analyzed, df.sqlContext)
    +
    +  def toSQL: Option[String] = {
    +    val canonicalizedPlan = Canonicalizer.execute(logicalPlan)
    +    val maybeSQL = toSQL(canonicalizedPlan)
    +
    +    if (maybeSQL.isDefined) {
    +      logDebug(
    +        s"""Built SQL query string successfully from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +           |# Built SQL query string:
    +           |${maybeSQL.get}
    +         """.stripMargin)
    +    } else {
    +      logDebug(
    +        s"""Failed to build SQL query string from given logical plan:
    +           |
    +           |# Original logical plan:
    +           |${logicalPlan.treeString}
    +           |# Canonicalized logical plan:
    +           |${canonicalizedPlan.treeString}
    +         """.stripMargin)
    +    }
    +
    +    maybeSQL
    +  }
    +
    +  private def projectToSQL(
    +      projectList: Seq[NamedExpression],
    +      child: LogicalPlan,
    +      isDistinct: Boolean): Option[String] = {
    +    for {
    +      listSQL <- sequenceOption(projectList.map(_.sql))
    +      childSQL <- toSQL(child)
    +      from = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      distinct = if (isDistinct) " DISTINCT" else ""
    +    } yield s"SELECT$distinct ${listSQL.mkString(", ")}$from$childSQL"
    +  }
    +
    +  private def aggregateToSQL(
    +      groupingExprs: Seq[Expression],
    +      aggExprs: Seq[Expression],
    +      child: LogicalPlan): Option[String] = {
    +    for {
    +      aggSQL <- sequenceOption(aggExprs.map(_.sql))
    +      groupingSQL <- sequenceOption(groupingExprs.map(_.sql))
    +      maybeGroupBy = if (groupingSQL.isEmpty) "" else " GROUP BY "
    +      maybeFrom = child match {
    +        case OneRowRelation => ""
    +        case _ => " FROM "
    +      }
    +      childSQL <- toSQL(child).map(maybeFrom + _)
    +    } yield {
    +      s"SELECT ${aggSQL.mkString(", ")}$childSQL$maybeGroupBy${groupingSQL.mkString(", ")}"
    +    }
    +  }
    +
    +  private def toSQL(node: LogicalPlan): Option[String] = node match {
    +    case Distinct(Project(list, child)) =>
    +      projectToSQL(list, child, isDistinct = true)
    +
    +    case Project(list, child) =>
    +      projectToSQL(list, child, isDistinct = false)
    +
    +    case Aggregate(groupingExprs, aggExprs, Aggregate(_, _, Expand(_, _, child))) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Aggregate(groupingExprs, aggExprs, child) =>
    +      aggregateToSQL(groupingExprs, aggExprs, child)
    +
    +    case Limit(limit, child) =>
    +      for {
    +        limitSQL <- limit.sql
    +        childSQL <- toSQL(child)
    +      } yield s"$childSQL LIMIT $limitSQL"
    +
    +    case Filter(condition, child) =>
    +      for {
    +        conditionSQL <- condition.sql
    +        childSQL <- toSQL(child)
    +        whereOrHaving = child match {
    +          case _: Aggregate => "HAVING"
    +          case _ => "WHERE"
    +        }
    +      } yield s"$childSQL $whereOrHaving $conditionSQL"
    +
    +    case Union(left, right) =>
    +      for {
    +        leftSQL <- toSQL(left)
    +        rightSQL <- toSQL(right)
    +      } yield s"$leftSQL UNION ALL $rightSQL"
    +
    +    // ParquetRelation converted from Hive metastore table
    +    case Subquery(alias, LogicalRelation(r: ParquetRelation, _)) =>
    +      Some(s"`$alias`")
    --- End diff --
    
    Oh yeah. I probably hit a bug related to Parquet table conversion. In some cases the original database and table names are not passed to `ParquetRelation` via data source options correctly. Haven't investigated this issue yet. I'm using subquery alias as a workaround here. Will add a comment.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169092952
  
    **[Test build #48779 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48779/consoleFull)** for PR 10541 at commit [`1796540`](https://github.com/apache/spark/commit/17965405ce2599554c6eef6d1365ec287fa3b0eb).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49053218
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUDFs.scala ---
    @@ -137,7 +133,8 @@ private[hive] class HiveFunctionRegistry(
       }
     }
     
    -private[hive] case class HiveSimpleUDF(funcWrapper: HiveFunctionWrapper, children: Seq[Expression])
    +private[hive] case class HiveSimpleUDF(
    +    name: String, funcWrapper: HiveFunctionWrapper, children: Seq[Expression])
    --- End diff --
    
    can't we get the function name from `funcWrapper`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168669586
  
    @rxin Thanks for helping explaining this.
    
    @hvanhovell Would also like to add that, once fully implemented, SQL statement generation itself can be quite useful, and not limited to native view support. One example is random query generation in integration tests.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169395619
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48860/
    Test FAILed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/spark/pull/10541


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791317
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala ---
    @@ -213,6 +215,34 @@ case class Literal protected (value: Any, dataType: DataType)
           }
         }
       }
    +
    +  override def sql: Option[String] = Option((value, dataType) match {
    +    case _ if value == null =>
    +      "NULL"
    +
    +    case (v: UTF8String, StringType) =>
    +      "\"" + v.toString.replace("\\", "\\\\").replace("\"", "\\\"") + "\""
    --- End diff --
    
    Add a comment to explain what this line is doing?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r48791753
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala ---
    @@ -226,6 +234,10 @@ case class InSet(child: Expression, hset: Set[Any]) extends UnaryExpression with
           }
          """
       }
    +
    +  override def sql: Option[String] = for {
    +    valueSQL :: listSQL <- sequenceOption(children.map(_.sql))
    +  } yield s"($valueSQL IN (${listSQL.mkString(", ")}))"
    --- End diff --
    
    Where is `hset`? Seems `children` only has 1 element.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168781095
  
    @liancheng 
    
    One thing about testing infrastructure: It is a good idea to use the existing Hive compatibility tests to bootstrap your test coverage. However, for every test failure that you find, we should create unit tests specifically built for the SQL conversion and increase the coverage of that. In the long run, we should not depend on the Hive compatibility tests.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169217026
  
    **[Test build #48828 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48828/consoleFull)** for PR 10541 at commit [`83e28fc`](https://github.com/apache/spark/commit/83e28fca84aa2c5a78af301df2b3d618b537be45).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49039738
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala ---
    @@ -91,6 +95,8 @@ case class Abs(child: Expression) extends UnaryExpression with ExpectsInputTypes
       }
     
       protected override def nullSafeEval(input: Any): Any = numeric.abs(input)
    +
    +  override def sql: Option[String] = child.sql.map(sql => s"(ABS($sql))")
    --- End diff --
    
    should we just rely on the prettyName?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12592][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168191297
  
    I found SQL generation in Slick can be a good reference for attacking limitations mentioned in the PR description. But the current approach should be enough for native view.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168676004
  
    **[Test build #48657 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48657/consoleFull)** for PR 10541 at commit [`ef5dac2`](https://github.com/apache/spark/commit/ef5dac21d09fe549e37c62d4ea25e7dcd062b9a7).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169186628
  
    Tests finally pass! (The last build failure was actually triggered by an older commit.)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL][WIP] Converts resolved logi...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-168659455
  
    **[Test build #48657 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48657/consoleFull)** for PR 10541 at commit [`ef5dac2`](https://github.com/apache/spark/commit/ef5dac21d09fe549e37c62d4ea25e7dcd062b9a7).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49046118
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala ---
    @@ -340,6 +369,12 @@ case class FindInSet(left: Expression, right: Expression) extends BinaryExpressi
       }
     
       override def dataType: DataType = IntegerType
    +
    +  override def prettyName: String = "find_in_set"
    +
    +  override def sql: Option[String] = for {
    --- End diff --
    
    Yea that seems a lot simpler to me (assuming majority of expressions do support sql string).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169885459
  
    **[Test build #48996 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/48996/consoleFull)** for PR 10541 at commit [`2073e30`](https://github.com/apache/spark/commit/2073e305f994d1f3b850fcf18e37002761979670).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `class ComputeCurrentTimeSuite extends PlanTest `


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-169372017
  
    Removed the WIP tag.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by yhuai <gi...@git.apache.org>.
Github user yhuai commented on the pull request:

    https://github.com/apache/spark/pull/10541#issuecomment-170118973
  
    LGTM pending jenkins.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request: [SPARK-12593][SQL] Converts resolved logical p...

Posted by liancheng <gi...@git.apache.org>.
Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10541#discussion_r49076368
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -333,6 +335,39 @@ object ProjectCollapsing extends Rule[LogicalPlan] {
             )
             Project(cleanedProjection, child)
           }
    +
    +    // TODO Eliminate duplicate code
    +    // This clause is identical to the one above except that the inner operator is an `Aggregate`
    +    // rather than a `Project`.
    +    case p @ Project(projectList1, agg @ Aggregate(_, projectList2, child)) =>
    --- End diff --
    
    You're right, but I'd also like to make the query string as simple as possible. Also this optimization is useful in general since it removes a redundant projection.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org