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

    https://github.com/apache/spark/pull/11815#discussion_r56783037
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala 
---
    @@ -2156,6 +2158,47 @@ class SQLQuerySuite extends QueryTest with 
SharedSQLContext {
         }
       }
     
    +  test("order by ordinal number") {
    +    checkAnswer(
    +      sql("SELECT * FROM testData2 ORDER BY 1 DESC"),
    +      sql("SELECT * FROM testData2 ORDER BY a DESC"))
    +    // If the position is not an integer, ignore it.
    +    checkAnswer(
    +      sql("SELECT * FROM testData2 ORDER BY 1 + 0 DESC, b ASC"),
    +      sql("SELECT * FROM testData2 ORDER BY b ASC"))
    +
    +    checkAnswer(
    +      sql("SELECT * FROM testData2 ORDER BY 1 DESC, b ASC"),
    +      sql("SELECT * FROM testData2 ORDER BY a DESC, b ASC"))
    +    checkAnswer(
    +      sql("SELECT * FROM testData2 SORT BY 1 DESC, 2"),
    +      sql("SELECT * FROM testData2 SORT BY a DESC, b ASC"))
    +    checkAnswer(
    +      sql("SELECT * FROM testData2 ORDER BY 1 ASC, b ASC"),
    +      Seq(Row(1, 1), Row(1, 2), Row(2, 1), Row(2, 2), Row(3, 1), Row(3, 
2)))
    +  }
    +
    +  test("order by ordinal number - negative cases") {
    +    intercept[UnresolvedException[SortOrder]] {
    +      sql("SELECT * FROM testData2 ORDER BY 0").collect()
    +    }
    +    intercept[UnresolvedException[SortOrder]] {
    +      sql("SELECT * FROM testData2 ORDER BY -1 DESC, b ASC").collect()
    +    }
    +    intercept[UnresolvedException[SortOrder]] {
    +      sql("SELECT * FROM testData2 ORDER BY 3 DESC, b ASC").collect()
    +    }
    +  }
    +
    +  test("order by ordinal number with conf spark.sql.orderByOrdinal=false") 
{
    +    withSQLConf(SQLConf.ORDER_BY_ORDINAL.key -> "false") {
    +      // If spark.sql.orderByOrdinal=false, ignore the position number.
    +      checkAnswer(
    +        sql("SELECT * FROM testData2 ORDER BY 1 DESC, b ASC"),
    +        Seq(Row(1, 1), Row(2, 1), Row(3, 1), Row(1, 2), Row(2, 2), Row(3, 
2)))
    --- End diff --
    
    Sure, let me fix it. 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 [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