Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11557#discussion_r57281018
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ng/PlanParserSuite.scala
 ---
    @@ -0,0 +1,408 @@
    +/*
    + * 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.catalyst.parser.ng
    +
    +import org.apache.spark.sql.Row
    +import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.plans._
    +import org.apache.spark.sql.catalyst.plans.logical._
    +import org.apache.spark.sql.types.IntegerType
    +
    +class PlanParserSuite extends PlanTest {
    +  import CatalystSqlParser._
    +  import org.apache.spark.sql.catalyst.dsl.expressions._
    +  import org.apache.spark.sql.catalyst.dsl.plans._
    +
    +  def assertEqual(sqlCommand: String, plan: LogicalPlan): Unit = {
    +    comparePlans(parsePlan(sqlCommand), plan)
    +  }
    +
    +  def intercept(sqlCommand: String, messages: String*): Unit = {
    +    val e = intercept[ParseException](parsePlan(sqlCommand))
    +    messages.foreach { message =>
    +      assert(e.message.contains(message))
    +    }
    +  }
    +
    +  test("case insensitive") {
    +    val plan = table("a").select(star())
    +    assertEqual("sELEct * FroM a", plan)
    +    assertEqual("select * fRoM a", plan)
    +    assertEqual("SELECT * FROM a", plan)
    +  }
    +
    +  test("show functions") {
    +    assertEqual("show functions", ShowFunctions(None, None))
    +    assertEqual("show functions foo", ShowFunctions(None, Some("foo")))
    +    assertEqual("show functions foo.bar", ShowFunctions(Some("foo"), 
Some("bar")))
    +    assertEqual("show functions 'foo\\\\.*'", ShowFunctions(None, 
Some("foo\\.*")))
    +    intercept("show functions foo.bar.baz", "SHOW FUNCTIONS unsupported 
name")
    +  }
    +
    +  test("describe function") {
    +    assertEqual("describe function bar", DescribeFunction("bar", 
isExtended = false))
    +    assertEqual("describe function extended bar", DescribeFunction("bar", 
isExtended = true))
    +    assertEqual("describe function foo.bar", DescribeFunction("foo.bar", 
isExtended = false))
    +    assertEqual("describe function extended f.bar", 
DescribeFunction("f.bar", isExtended = true))
    +  }
    +
    +  test("set operations") {
    +    val a = table("a").select(star())
    +    val b = table("b").select(star())
    +
    +    assertEqual("select * from a union select * from b", 
Distinct(a.unionAll(b)))
    +    assertEqual("select * from a union distinct select * from b", 
Distinct(a.unionAll(b)))
    +    assertEqual("select * from a union all select * from b", a.unionAll(b))
    +    assertEqual("select * from a except select * from b", a.except(b))
    +    intercept("select * from a except all select * from b", "EXCEPT ALL is 
not supported.")
    +    assertEqual("select * from a except distinct select * from b", 
a.except(b))
    +    assertEqual("select * from a intersect select * from b", 
a.intersect(b))
    +    intercept("select * from a intersect all select * from b", "INTERSECT 
ALL is not supported.")
    +    assertEqual("select * from a intersect distinct select * from b", 
a.intersect(b))
    +  }
    +
    +  test("common table expressions") {
    +    def cte(plan: LogicalPlan, namedPlans: (String, LogicalPlan)*): With = 
{
    +      val ctes = namedPlans.map {
    +        case (name, cte) =>
    +          name -> SubqueryAlias(name, cte)
    +      }.toMap
    +      With(plan, ctes)
    +    }
    +    assertEqual(
    +      "with cte1 as (select * from a) select * from cte1",
    +      cte(table("cte1").select(star()), "cte1" -> 
table("a").select(star())))
    +    assertEqual(
    +      "with cte1 (select 1) select * from cte1",
    +      cte(table("cte1").select(star()), "cte1" -> 
OneRowRelation.select(1)))
    +    assertEqual(
    +      "with cte1 (select 1), cte2 as (select * from cte1) select * from 
cte2",
    +      cte(table("cte2").select(star()),
    +        "cte1" -> OneRowRelation.select(1),
    +        "cte2" -> table("cte1").select(star())))
    +    intercept(
    +      "with cte1 (select 1), cte1 as (select 1 from cte1) select * from 
cte1",
    +      "Name 'cte1' is used for multiple common table expressions")
    +  }
    +
    +  test("simple select query") {
    +    assertEqual("select 1", OneRowRelation.select(1))
    +    assertEqual("select a, b", OneRowRelation.select('a, 'b))
    +    assertEqual("select a, b from db.c", table("db", "c").select('a, 'b))
    +    assertEqual("select a, b from db.c where x < 1", table("db", 
"c").where('x < 1).select('a, 'b))
    +    assertEqual("select a, b from db.c having x < 1", table("db", 
"c").select('a, 'b).where('x < 1))
    --- End diff --
    
    Throwing an exception during analysis would actually be a regression. I am 
pretty sure that we support this in HiveQl for 1.6.
    
    I am also not sure if we should be that struct. HAVING only means (IMHO) 
that a filter is applied after a potential aggregation.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to