MaxGekk opened a new pull request #31675:
URL: https://github.com/apache/spark/pull/31675


   ### What changes were proposed in this pull request?
   In the PR, I propose to generate unique attributes in the logical nodes of 
the `SHOW TABLES` command.
   
   ### Why are the changes needed?
   This fixes the issue which is demonstrated by the example below:
   ```scala
   scala> val show1 = sql("SHOW TABLES IN ns1")
   show1: org.apache.spark.sql.DataFrame = [namespace: string, tableName: 
string ... 1 more field]
   
   scala> val show2 = sql("SHOW TABLES IN ns2")
   show2: org.apache.spark.sql.DataFrame = [namespace: string, tableName: 
string ... 1 more field]
   
   scala> show1.show
   +---------+---------+-----------+
   |namespace|tableName|isTemporary|
   +---------+---------+-----------+
   |      ns1|     tbl1|      false|
   +---------+---------+-----------+
   
   
   scala> show2.show
   +---------+---------+-----------+
   |namespace|tableName|isTemporary|
   +---------+---------+-----------+
   |      ns2|     tbl2|      false|
   +---------+---------+-----------+
   
   
   scala> show1.join(show2).where(show1("tableName") =!= 
show2("tableName")).show
   org.apache.spark.sql.AnalysisException: Column tableName#17 are ambiguous. 
It's probably because you joined several Datasets together, and some of these 
Datasets are the same. This column points to one of the Datasets but Spark is 
unable to figure out which one. Please alias the Datasets with different names 
via `Dataset.as` before joining them, and specify the column using qualified 
name, e.g. `df.as("a").join(df.as("b"), $"a.id" > $"b.id")`. You can also set 
spark.sql.analyzer.failAmbiguousSelfJoin to false to disable this check.
     at 
org.apache.spark.sql.execution.analysis.DetectAmbiguousSelfJoin$.apply(DetectAmbiguousSelfJoin.scala:157)
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. After the changes, the example above works as expected:
   ```scala
   scala> show1.join(show2).where(show1("tableName") =!= 
show2("tableName")).show
   +---------+---------+-----------+---------+---------+-----------+
   |namespace|tableName|isTemporary|namespace|tableName|isTemporary|
   +---------+---------+-----------+---------+---------+-----------+
   |      ns1|     tbl1|      false|      ns2|     tbl2|      false|
   +---------+---------+-----------+---------+---------+-----------+
   ```
   
   ### How was this patch tested?
   By running the new test:
   ```
   $  build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *ShowTablesSuite"
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to