@@ -64,50 +64,49 @@ abstract class RemoveRedundantSortsSuiteBase
6464 withTempView(" t1" , " t2" ) {
6565 spark.range(1000 ).select(' id as " key" ).createOrReplaceTempView(" t1" )
6666 spark.range(1000 ).select(' id as " key" ).createOrReplaceTempView(" t2" )
67+
6768 val queryTemplate = """
68- |SELECT t1.key FROM
69+ |SELECT /*+ BROADCAST(%s) */ t1.key FROM
6970 | (SELECT key FROM t1 WHERE key > 10 ORDER BY key DESC LIMIT 10) t1
70- |%s
71+ |JOIN
7172 | (SELECT key FROM t2 WHERE key > 50 ORDER BY key DESC LIMIT 100) t2
7273 |ON t1.key = t2.key
7374 |ORDER BY %s
7475 """ .stripMargin
7576
76- val innerJoinAsc = queryTemplate.format(" JOIN " , " t2.key ASC" )
77+ val innerJoinAsc = queryTemplate.format(" t1 " , " t2.key ASC" )
7778 checkSorts(innerJoinAsc, 1 , 1 )
7879
79- val innerJoinDesc = queryTemplate.format(" JOIN " , " t2.key DESC" )
80+ val innerJoinDesc = queryTemplate.format(" t1 " , " t2.key DESC" )
8081 checkSorts(innerJoinDesc, 0 , 1 )
8182
82- val innerJoinDesc1 = queryTemplate.format(" JOIN " , " t1.key DESC" )
83+ val innerJoinDesc1 = queryTemplate.format(" t1 " , " t1.key DESC" )
8384 checkSorts(innerJoinDesc1, 1 , 1 )
8485
85- val leftOuterJoinDesc = queryTemplate.format(" LEFT JOIN " , " t1.key DESC" )
86+ val leftOuterJoinDesc = queryTemplate.format(" t2 " , " t1.key DESC" )
8687 checkSorts(leftOuterJoinDesc, 0 , 1 )
8788 }
8889 }
8990
9091 test(" remove redundant sorts with sort merge join" ) {
91- withSQLConf(SQLConf .AUTO_BROADCASTJOIN_THRESHOLD .key -> " -1" ) {
92- withTempView(" t1" , " t2" ) {
93- spark.range(1000 ).select(' id as " key" ).createOrReplaceTempView(" t1" )
94- spark.range(1000 ).select(' id as " key" ).createOrReplaceTempView(" t2" )
95- val query = """
96- |SELECT t1.key FROM
97- | (SELECT key FROM t1 WHERE key > 10 ORDER BY key DESC LIMIT 10) t1
98- |JOIN
99- | (SELECT key FROM t2 WHERE key > 50 ORDER BY key DESC LIMIT 100) t2
100- |ON t1.key = t2.key
101- |ORDER BY t1.key
102- """ .stripMargin
103-
104- val queryAsc = query + " ASC"
105- checkSorts(queryAsc, 2 , 3 )
106-
107- // Top level sort should only be eliminated if it's order is descending with SMJ.
108- val queryDesc = query + " DESC"
109- checkSorts(queryDesc, 3 , 3 )
110- }
92+ withTempView(" t1" , " t2" ) {
93+ spark.range(1000 ).select(' id as " key" ).createOrReplaceTempView(" t1" )
94+ spark.range(1000 ).select(' id as " key" ).createOrReplaceTempView(" t2" )
95+ val query = """
96+ |SELECT /*+ MERGE(t1) */ t1.key FROM
97+ | (SELECT key FROM t1 WHERE key > 10 ORDER BY key DESC LIMIT 10) t1
98+ |JOIN
99+ | (SELECT key FROM t2 WHERE key > 50 ORDER BY key DESC LIMIT 100) t2
100+ |ON t1.key = t2.key
101+ |ORDER BY t1.key
102+ """ .stripMargin
103+
104+ val queryAsc = query + " ASC"
105+ checkSorts(queryAsc, 2 , 3 )
106+
107+ // Top level sort should only be eliminated if it's order is descending with SMJ.
108+ val queryDesc = query + " DESC"
109+ checkSorts(queryDesc, 3 , 3 )
111110 }
112111 }
113112
0 commit comments