Github user amansinha100 commented on a diff in the pull request: https://github.com/apache/drill/pull/1117#discussion_r167441417 --- Diff: exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoinAdvanced.java --- @@ -197,4 +198,24 @@ public void emptyPartTest() throws Exception { BaseTestQuery.resetSessionOption(ExecConstants.SLICE_TARGET); } } + + @Test // DRILL-6089 + public void testJoinOrdering() throws Exception { + final String query = "select * from dfs.`sample-data/nation.parquet` nation left outer join " + + "(select * from dfs.`sample-data/region.parquet`) " + + "as region on region.r_regionkey = nation.n_nationkey order by region.r_name desc"; + final String plan = getPlanInString("EXPLAIN PLAN for " + QueryTestUtil.normalizeQuery(query), OPTIQ_FORMAT); + lastSortAfterJoin(plan); --- End diff -- Most plan tests that we have use one of the utility methods in PlanTestBase (from which JoinTestBase is derived) which uses Java's regex Pattern and Matcher classes. In your query, is it necessary to check the index of the Sort vs the HashJoin ? Since there is expected to be only 1 Sort (corresponding to the final ORDER BY), as long as there is a regex pattern that matches `'*Sort*HashJoin',` I think that would be sufficient. You might want to see the callers of [1] if it satisfies your requirement. [1] https://github.com/apache/drill/blob/master/exec/java-exec/src/test/java/org/apache/drill/PlanTestBase.java#L82
---