Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10649#discussion_r49777022
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystQlSuite.scala 
---
    @@ -17,36 +17,157 @@
     
     package org.apache.spark.sql.catalyst
     
    +import org.apache.spark.sql.AnalysisException
    +import org.apache.spark.sql.catalyst.analysis.{UnresolvedAlias, 
UnresolvedAttribute, UnresolvedFunction}
    +import org.apache.spark.sql.catalyst.expressions._
     import org.apache.spark.sql.catalyst.plans.PlanTest
    +import org.apache.spark.sql.catalyst.plans.logical.{OneRowRelation, 
Project}
    +import org.apache.spark.unsafe.types.CalendarInterval
     
     class CatalystQlSuite extends PlanTest {
       val parser = new CatalystQl()
     
    +  test("test case insensitive") {
    +    val result = Project(UnresolvedAlias(Literal(1)):: Nil, OneRowRelation)
    +    assert(result === parser.parsePlan("seLect 1"))
    +    assert(result === parser.parsePlan("select 1"))
    +    assert(result === parser.parsePlan("SELECT 1"))
    +  }
    +
    +  test("test NOT operator with comparison operations") {
    +    val parsed = parser.parsePlan("SELECT NOT TRUE > TRUE")
    +    val expected = Project(
    +      UnresolvedAlias(
    +        Not(
    +          GreaterThan(Literal(true), Literal(true)))
    +      ) :: Nil,
    +      OneRowRelation)
    +    comparePlans(parsed, expected)
    +  }
    +
    +  test("support hive interval literal") {
    +    def checkInterval(sql: String, result: CalendarInterval): Unit = {
    +      val parsed = parser.parsePlan(sql)
    +      val expected = Project(
    +        UnresolvedAlias(
    +          Literal(result)
    +        ) :: Nil,
    +        OneRowRelation)
    +      comparePlans(parsed, expected)
    +    }
    +
    +    def checkYearMonth(lit: String): Unit = {
    +      checkInterval(
    +        s"SELECT INTERVAL '$lit' YEAR TO MONTH",
    +        CalendarInterval.fromYearMonthString(lit))
    +    }
    +
    +    def checkDayTime(lit: String): Unit = {
    +      checkInterval(
    +        s"SELECT INTERVAL '$lit' DAY TO SECOND",
    +        CalendarInterval.fromDayTimeString(lit))
    +    }
    +
    +    def checkSingleUnit(lit: String, unit: String): Unit = {
    +      checkInterval(
    +        s"SELECT INTERVAL '$lit' $unit",
    +        CalendarInterval.fromSingleUnitString(unit, lit))
    +    }
    +
    +    checkYearMonth("123-10")
    +    checkYearMonth("496-0")
    +    checkYearMonth("-2-3")
    +    checkYearMonth("-123-0")
    +
    +    checkDayTime("99 11:22:33.123456789")
    +    checkDayTime("-99 11:22:33.123456789")
    +    checkDayTime("10 9:8:7.123456789")
    +    checkDayTime("1 0:0:0")
    +    checkDayTime("-1 0:0:0")
    +    checkDayTime("1 0:0:1")
    +
    +    for (unit <- Seq("year", "month", "day", "hour", "minute", "second")) {
    +      checkSingleUnit("7", unit)
    +      checkSingleUnit("-7", unit)
    +      checkSingleUnit("0", unit)
    +    }
    +
    +    checkSingleUnit("13.123456789", "second")
    +    checkSingleUnit("-13.123456789", "second")
    +  }
    +
    +  test("support scientific notation") {
    +    def assertRight(input: String, output: Double): Unit = {
    +      val parsed = parser.parsePlan("SELECT " + input)
    +      val expected = Project(
    +        UnresolvedAlias(
    +          Literal(output)
    +        ) :: Nil,
    +        OneRowRelation)
    +      comparePlans(parsed, expected)
    +    }
    +
    +    assertRight("9.0e1", 90)
    +    assertRight("0.9e+2", 90)
    +    assertRight("900e-1", 90)
    +    assertRight("900.0E-1", 90)
    +    assertRight("9.e+1", 90)
    +
    +    intercept[AnalysisException](parser.parsePlan("SELECT .e3"))
    +  }
    +
    +  test("parse expressions") {
    +    compareExpressions(
    +      parser.parseExpression("prinln('hello', 'world')"),
    +      UnresolvedFunction(
    +        "prinln", Literal("hello") :: Literal("world") :: Nil, false))
    +
    +    compareExpressions(
    +      parser.parseExpression("1 + r.r As q"),
    +      Alias(Add(Literal(1), UnresolvedAttribute("r.r")), "q")())
    +
    +    compareExpressions(
    +      parser.parseExpression("1 - f('o', o(bar))"),
    +      Subtract(Literal(1),
    +        UnresolvedFunction("f",
    +          Literal("o") ::
    +          UnresolvedFunction("o", UnresolvedAttribute("bar") :: Nil, 
false) ::
    +          Nil, false)))
    +  }
    +
    +  test("table identifier") {
    +    assert(TableIdentifier("q") === parser.parseTableIdentifier("q"))
    +    assert(TableIdentifier("q", Some("d")) === 
parser.parseTableIdentifier("d.q"))
    +    intercept[AnalysisException](parser.parseTableIdentifier(""))
    +    // TODO parser swallows third identifier.
    +    // intercept[AnalysisException](parser.parseTableIdentifier("d.q.g"))
    --- End diff --
    
    yea, throw exception seems reasonable to me


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to