Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4918#discussion_r25918626
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala 
---
    @@ -1049,4 +1049,14 @@ class SQLQuerySuite extends QueryTest with 
BeforeAndAfterAll {
         rdd.toDF().registerTempTable("distinctData")
         checkAnswer(sql("SELECT COUNT(DISTINCT key,value) FROM distinctData"), 
Row(2))
       }
    +
    +  test("SPARK-6145: ORDER BY test for nested fields") {
    +    jsonRDD(sparkContext.makeRDD(
    +      """{"a": {"b": 1, "a": {"a": 1}}, "c": [{"d": 1}]}""" :: 
Nil)).registerTempTable("nestedOrder")
    +    // These should be successfully analyzed
    +    sql("SELECT 1 FROM nestedOrder ORDER BY a.b").queryExecution.analyzed
    +    sql("SELECT a.b FROM nestedOrder ORDER BY a.b").queryExecution.analyzed
    +    sql("SELECT 1 FROM nestedOrder ORDER BY a.a.a").queryExecution.analyzed
    +    sql("SELECT 1 FROM nestedOrder ORDER BY 
c[0].d").queryExecution.analyzed
    --- End diff --
    
    BTW, In Hive
    ```
    hive> select a.a from struct1 order by a.a;
    FAILED: SemanticException [Error 10042]: Line 1:33 . Operator is only 
supported on struct or list of struct types 'a'
    hive> select 1 from struct1 order by a.a;  
    FAILED: SemanticException [Error 10004]: Line 1:31 Invalid table alias or 
column reference 'a': (possible column names are: _c0)
    hive> select _c0 from struct1 order by a.a;
    FAILED: ParseException line 1:11 missing \' at 'from' near '<EOF>'
    ```
    Seems Hive has bugs on this ambiguous attribute references, that's why I 
think we probably need to change that code:
    
https://github.com/apache/spark/pull/4892/files#diff-27c76f96a7b2733ecfd6f46a1716e153R201


---
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