Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.plans.logical.EventTimeWatermark
import org.apache.spark.sql.catalyst.trees.TreePattern
import org.apache.spark.sql.catalyst.trees.TreePattern._
import org.apache.spark.sql.catalyst.util.{quoteIfNeeded, METADATA_COL_ATTR_KEY}
import org.apache.spark.sql.catalyst.util._
import org.apache.spark.sql.types._
import org.apache.spark.util.collection.BitSet
import org.apache.spark.util.collection.ImmutableBitSet
Expand Down Expand Up @@ -190,7 +190,10 @@ case class Alias(child: Expression, name: String)(

override def toAttribute: Attribute = {
if (resolved) {
AttributeReference(name, child.dataType, child.nullable, metadata)(exprId, qualifier)
val a = AttributeReference(name, child.dataType, child.nullable, metadata)(exprId, qualifier)
// Alias has its own qualifier. It doesn't make sense to still restrict the hidden columns
// of natural/using join to be accessed by qualified name only.
if (a.qualifiedAccessOnly) a.markAsAllowAnyAccess() else a
} else {
UnresolvedAttribute.quoted(name)
}
Expand Down
2 changes: 2 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/natural-join.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ SELECT nt1.k, nt2.k FROM nt1 natural join nt2;

SELECT k FROM (SELECT nt2.k FROM nt1 natural join nt2);

SELECT nt2.k AS key FROM nt1 natural join nt2 ORDER BY key;

SELECT nt1.k, nt2.k FROM nt1 natural join nt2 where k = "one";

SELECT * FROM (SELECT * FROM nt1 natural join nt2);
Expand Down
8 changes: 8 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/using-join.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ SELECT nt1.k, nt2.k FROM nt1 left outer join nt2 using (k);

SELECT k FROM (SELECT nt2.k FROM nt1 left outer join nt2 using (k));

SELECT nt2.k AS key FROM nt1 left outer join nt2 using (k) ORDER BY key;

SELECT nt1.k, nt2.k FROM nt1 left outer join nt2 using (k) ORDER BY nt2.k;

SELECT k, nt1.k FROM nt1 left outer join nt2 using (k);
Expand All @@ -47,6 +49,8 @@ SELECT nt1.k, nt2.k FROM nt1 right outer join nt2 using (k);

SELECT k FROM (SELECT nt1.k FROM nt1 right outer join nt2 using (k));

SELECT nt1.k AS key FROM nt1 right outer join nt2 using (k) ORDER BY key;

SELECT k, nt1.k FROM nt1 right outer join nt2 using (k);

SELECT k, nt2.k FROM nt1 right outer join nt2 using (k);
Expand All @@ -61,6 +65,8 @@ SELECT nt1.k, nt2.k FROM nt1 full outer join nt2 using (k);

SELECT k FROM (SELECT nt2.k FROM nt1 full outer join nt2 using (k));

SELECT nt2.k AS key FROM nt1 full outer join nt2 using (k) ORDER BY key;

SELECT k, nt1.k FROM nt1 full outer join nt2 using (k);

SELECT k, nt2.k FROM nt1 full outer join nt2 using (k);
Expand All @@ -75,6 +81,8 @@ SELECT nt1.k, nt2.k FROM nt1 inner join nt2 using (k);

SELECT k FROM (SELECT nt2.k FROM nt1 inner join nt2 using (k));

SELECT nt2.k AS key FROM nt1 inner join nt2 using (k) ORDER BY key;

SELECT k, nt1.k FROM nt1 inner join nt2 using (k);

SELECT k, nt2.k FROM nt1 inner join nt2 using (k);
10 changes: 10 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/natural-join.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ one
two


-- !query
SELECT nt2.k AS key FROM nt1 natural join nt2 ORDER BY key
-- !query schema
struct<key:string>
-- !query output
one
one
two


-- !query
SELECT nt1.k, nt2.k FROM nt1 natural join nt2 where k = "one"
-- !query schema
Expand Down
44 changes: 44 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/using-join.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ one
two


-- !query
SELECT nt2.k AS key FROM nt1 left outer join nt2 using (k) ORDER BY key
-- !query schema
struct<key:string>
-- !query output
NULL
one
one
two


-- !query
SELECT nt1.k, nt2.k FROM nt1 left outer join nt2 using (k) ORDER BY nt2.k
-- !query schema
Expand Down Expand Up @@ -212,6 +223,17 @@ one
two


-- !query
SELECT nt1.k AS key FROM nt1 right outer join nt2 using (k) ORDER BY key
-- !query schema
struct<key:string>
-- !query output
NULL
one
one
two


-- !query
SELECT k, nt1.k FROM nt1 right outer join nt2 using (k)
-- !query schema
Expand Down Expand Up @@ -294,6 +316,18 @@ one
two


-- !query
SELECT nt2.k AS key FROM nt1 full outer join nt2 using (k) ORDER BY key
-- !query schema
struct<key:string>
-- !query output
NULL
four
one
one
two


-- !query
SELECT k, nt1.k FROM nt1 full outer join nt2 using (k)
-- !query schema
Expand Down Expand Up @@ -370,6 +404,16 @@ one
two


-- !query
SELECT nt2.k AS key FROM nt1 inner join nt2 using (k) ORDER BY key
-- !query schema
struct<key:string>
-- !query output
one
one
two


-- !query
SELECT k, nt1.k FROM nt1 inner join nt2 using (k)
-- !query schema
Expand Down