Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-1062: Implemented null ordering (NULLS FIRST/NULLS LAST).
Primary: - Split "compare_to" function templates (for sorting) into "compare_to_nulls_high" and "compare_to_nulls_low" versions. - Added tests to verify ORDER BY ordering. - Added tests to verify merge join order correctness. - Implemented java.sql.DatabaseMetaData.nullsAreSortedHigh(), etc. Secondary: - Eliminated DateInterfaceFunctions.java template (merged into other). - Renamed comparison-related template data objects and file names. - Eliminated unused template macros, function template classes. - Overhauled Order.Ordering; added unit test. - Regularized some generated-class names. Miscellaneous: - Added toString() to ExpressionPosition, Order.Ordering, JoinStatus. - Fixed some typos. - Fixed some comment syntax.
- Loading branch information
1 parent
3c85bd8
commit 5efc7e6
Showing
50 changed files
with
3,101 additions
and
1,836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
common/src/test/java/org/apache/drill/common/logical/data/OrderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,93 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.apache.drill.common.logical.data; | |||
|
|||
import static org.junit.Assert.*; | |||
|
|||
import java.sql.SQLException; | |||
|
|||
import org.apache.drill.common.exceptions.DrillRuntimeException; | |||
import org.apache.drill.common.expression.LogicalExpression; | |||
import org.apache.drill.common.logical.data.Order.Ordering; | |||
import org.eigenbase.rel.RelFieldCollation; | |||
import org.eigenbase.rel.RelFieldCollation.Direction; | |||
import org.eigenbase.rel.RelFieldCollation.NullDirection; | |||
import org.junit.Test; | |||
|
|||
import static org.hamcrest.CoreMatchers.*; | |||
|
|||
public class OrderTest { | |||
|
|||
////////// | |||
// Order.Ordering tests: | |||
|
|||
// "Round trip" tests that strings from output work as input: | |||
|
|||
@Test | |||
public void test_Ordering_roundTripAscAndNullsFirst() { | |||
Ordering src = new Ordering( Direction.ASCENDING, null, NullDirection.FIRST); | |||
Ordering reconstituted = | |||
new Ordering( (LogicalExpression) null, src.getOrder(), src.getNullDirection().toString() ); | |||
assertThat( reconstituted.getDirection(), equalTo( RelFieldCollation.Direction.ASCENDING ) ); | |||
assertThat( reconstituted.getNullDirection(), equalTo( NullDirection.FIRST ) ); | |||
} | |||
|
|||
@Test | |||
public void test_Ordering_roundTripDescAndNullsLast() { | |||
Ordering src = new Ordering( Direction.DESCENDING, null, NullDirection.LAST); | |||
Ordering reconstituted = | |||
new Ordering( (LogicalExpression) null, src.getOrder(), src.getNullDirection().toString() ); | |||
assertThat( reconstituted.getDirection(), equalTo( RelFieldCollation.Direction.DESCENDING ) ); | |||
assertThat( reconstituted.getNullDirection(), equalTo( NullDirection.LAST ) ); | |||
} | |||
|
|||
@Test | |||
public void test_Ordering_roundTripDescAndNullsUnspecified() { | |||
Ordering src = new Ordering( Direction.DESCENDING, null, NullDirection.UNSPECIFIED); | |||
Ordering reconstituted = | |||
new Ordering( (LogicalExpression) null, src.getOrder(), src.getNullDirection().toString() ); | |||
assertThat( reconstituted.getDirection(), equalTo( RelFieldCollation.Direction.DESCENDING ) ); | |||
assertThat( reconstituted.getNullDirection(), equalTo( NullDirection.UNSPECIFIED ) ); | |||
} | |||
|
|||
|
|||
// Basic input validation: | |||
|
|||
@Test( expected = DrillRuntimeException.class ) // (Currently.) | |||
public void test_Ordering_garbageOrderRejected() { | |||
new Ordering( (LogicalExpression) null, "AS CE ND IN G", (String) null ); | |||
} | |||
|
|||
@Test( expected = DrillRuntimeException.class ) // (Currently.) | |||
public void test_Ordering_garbageNullOrderingRejected() { | |||
new Ordering( (LogicalExpression) null, (String) null, "HIGH" ); | |||
} | |||
|
|||
|
|||
// Defaults-value/null-strings test: | |||
|
|||
@Test | |||
public void testOrdering_nullStrings() { | |||
Ordering ordering = new Ordering( (LogicalExpression) null, null, null ); | |||
assertThat( ordering.getDirection(), equalTo( RelFieldCollation.Direction.ASCENDING ) ); | |||
assertThat( ordering.getNullDirection(), equalTo( RelFieldCollation.NullDirection.UNSPECIFIED ) ); | |||
assertThat( ordering.getOrder(), equalTo( "ASC" ) ); | |||
} | |||
|
|||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.