diff options
author | dbarclay <dbarclay@maprtech.com> | 2015-02-17 13:50:16 -0800 |
---|---|---|
committer | Parth Chandra <pchandra@maprtech.com> | 2015-02-23 11:51:33 -0800 |
commit | 5efc7e686d04ebff7c651270961ec7f5ca09c93d (patch) | |
tree | b676a069c6b9dac80f995a3a605bf0255032a20b /exec/java-exec/src/main/java | |
parent | 3c85bd8aa412f0a4d361a9a7b3136a03b15c9f37 (diff) |
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.
Diffstat (limited to 'exec/java-exec/src/main/java')
22 files changed, 182 insertions, 905 deletions
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java index 1ed3cb349..926e703c5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java @@ -53,6 +53,7 @@ public class PrintingResultsListener implements UserResultsListener { @Override public void submissionFailed(RpcException ex) { exception = ex; + System.out.println("Exception (no rows returned): " + ex ); latch.countDown(); } @@ -87,7 +88,7 @@ public class PrintingResultsListener implements UserResultsListener { if (isLastChunk) { allocator.close(); latch.countDown(); - System.out.println("Total rows returned : " + count.get()); + System.out.println("Total rows returned: " + count.get()); } } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java index e1ad85492..3565bf470 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java @@ -203,7 +203,7 @@ public class ExpressionTreeMaterializer { List<LogicalExpression> args = Lists.newArrayList(); for (int i = 0; i < call.args.size(); ++i) { LogicalExpression newExpr = call.args.get(i).accept(this, registry); - assert newExpr != null : String.format("Materialization of %s return a null expression.", call.args.get(i)); + assert newExpr != null : String.format("Materialization of %s returned a null expression.", call.args.get(i)); args.add(newExpr); } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java index 1f732a398..15c7e196d 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/annotations/FunctionTemplate.java @@ -28,15 +28,27 @@ import java.lang.annotation.Target; public @interface FunctionTemplate { /** - * Use this annotation if there is only one name for function - * Note: If you use this annotation don't use {@link #names()} + * Name of function (when only one.) + * Use this annotation element if there is only one name for the function. + * Note: If you use this annotation don't use {@link #names()}. + * <p> + * TODO: Refer to wherever list of possible or at least known names is, + * to resolve the current issue of spaces vs. underlines in names (e.g., we + * have both "less_than" and "less than". + * </p> * @return */ String name() default ""; /** - * Use this annotation if there are multiple names for function - * Note: If you use this annotation don't use {@link #name()} + * Names of function (when multiple). + * Use this annotation element if there are multiple names for the function. + * Note: If you use this annotation don't use {@link #name()}. + * <p> + * TODO: Refer to wherever list of possible or at least known names is, + * to resolve the current issue of spaces vs. underlines in names (e.g., we + * have both "less_than" and "less than". + * </p> * @return */ String[] names() default {}; @@ -49,10 +61,21 @@ public @interface FunctionTemplate { FunctionCostCategory costCategory() default FunctionCostCategory.SIMPLE; public static enum NullHandling { - INTERNAL, NULL_IF_NULL; + /** + * Method handles nulls. + */ + INTERNAL, + + /** + * Null output if any null input: + * Indicates that a method's associated logical operation returns NULL if + * either input is NULL, and therefore that the method must not be called + * with null inputs. (The calling framework must handle NULLs.) + */ + NULL_IF_NULL; } - public static enum FunctionScope{ + public static enum FunctionScope { SIMPLE, POINT_AGGREGATE, DECIMAL_AGGREGATE, diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java index d007d7c54..19cd1d851 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionGenerationHelper.java @@ -29,28 +29,58 @@ import org.apache.drill.common.types.TypeProtos.MinorType; import org.apache.drill.common.types.Types; import org.apache.drill.exec.expr.ClassGenerator.HoldingContainer; import org.apache.drill.exec.expr.HoldingContainerExpression; +import org.eigenbase.rel.RelFieldCollation.NullDirection; public class FunctionGenerationHelper { - public static final String COMPARE_TO = "compare_to"; + public static final String COMPARE_TO_NULLS_HIGH = "compare_to_nulls_high"; + public static final String COMPARE_TO_NULLS_LOW = "compare_to_nulls_low"; /** - * Given materialized arguments find the "compare_to" FunctionHolderExpression - * @param left - * @param right - * @param registry - * @return FunctionHolderExpression containing the function implementation + * Finds ordering comparator ("compare_to...") FunctionHolderExpression with + * a specified ordering for NULL (and considering NULLS <i>equal</i>). + * @param null_high whether NULL should compare as the lowest value (if + * {@code false}) or the highest value (if {@code true}) + * @param left ... + * @param right ... + * @param registry ... + * @return + * FunctionHolderExpression containing the found function implementation */ - public static FunctionHolderExpression getComparator(HoldingContainer left, - HoldingContainer right, - FunctionImplementationRegistry registry) { - if (! isComparableType(left.getMajorType()) || ! isComparableType(right.getMajorType()) ){ - throw new UnsupportedOperationException(formatCanNotCompareMsg(left.getMajorType(), right.getMajorType())); + public static FunctionHolderExpression getOrderingComparator( + boolean null_high, + HoldingContainer left, + HoldingContainer right, + FunctionImplementationRegistry registry) { + final String comparator_name = + null_high ? COMPARE_TO_NULLS_HIGH : COMPARE_TO_NULLS_LOW; + + if ( ! isComparableType(left.getMajorType() ) + || ! isComparableType(right.getMajorType() ) ) { + throw new UnsupportedOperationException( + formatCanNotCompareMsg(left.getMajorType(), right.getMajorType())); } + return getFunctionExpression(comparator_name, Types.required(MinorType.INT), + registry, left, right); + } - return getFunctionExpression(COMPARE_TO, Types.required(MinorType.INT), registry, left, right); + /** + * Finds ordering comparator ("compare_to...") FunctionHolderExpression with + * a "NULL high" ordering (and considering NULLS <i>equal</i>). + * @param left ... + * @param right ... + * @param registry ... + * @return FunctionHolderExpression containing the function implementation + * @see #getComparator + */ + public static FunctionHolderExpression getOrderingComparatorNullsHigh( + HoldingContainer left, + HoldingContainer right, + FunctionImplementationRegistry registry) { + return getOrderingComparator(true, left, right, registry); } - public static FunctionHolderExpression getFunctionExpression(String name, MajorType returnType, FunctionImplementationRegistry registry, HoldingContainer... args) { + public static FunctionHolderExpression getFunctionExpression( + String name, MajorType returnType, FunctionImplementationRegistry registry, HoldingContainer... args) { List<MajorType> argTypes = new ArrayList<MajorType>(args.length); List<LogicalExpression> argExpressions = new ArrayList<LogicalExpression>(args.length); for(HoldingContainer c : args) { @@ -69,10 +99,10 @@ public class FunctionGenerationHelper { sb.append("( "); for(int i =0; i < args.length; i++) { MajorType mt = args[i].getMajorType(); - appendType(mt, sb); if (i != 0) { sb.append(", "); } + appendType(mt, sb); } sb.append(" ) returns "); appendType(returnType, sb); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java index 25dcbbcbe..55e4121d3 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionImplementationRegistry.java @@ -99,11 +99,15 @@ public class FunctionImplementationRegistry { return functionResolver.getBestMatch(drillFuncRegistry.getMethods(functionReplacement(functionCall)), functionCall); } - // Check if this Function Replacement is Needed; if yes, return a new name. otherwise, return the original name + // Check if this Function Replacement is needed; if yes, return a new name. otherwise, return the original name private String functionReplacement(FunctionCall functionCall) { String funcName = functionCall.getName(); - if(optionManager != null && optionManager.getOption(ExecConstants.CAST_TO_NULLABLE_NUMERIC).bool_val && CastFunctions.isReplacementNeeded(functionCall.args.get(0).getMajorType().getMinorType(), funcName)) { - org.apache.drill.common.types.TypeProtos.DataMode dataMode = functionCall.args.get(0).getMajorType().getMode(); + if (optionManager != null + && optionManager.getOption(ExecConstants.CAST_TO_NULLABLE_NUMERIC).bool_val + && CastFunctions.isReplacementNeeded(functionCall.args.get(0).getMajorType().getMinorType(), + funcName)) { + org.apache.drill.common.types.TypeProtos.DataMode dataMode = + functionCall.args.get(0).getMajorType().getMode(); funcName = CastFunctions.getReplacingCastFunction(funcName, dataMode); } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java index 3fe489fd9..ae428726a 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/BitFunctions.java @@ -27,9 +27,17 @@ import org.apache.drill.exec.expr.holders.BitHolder; import org.apache.drill.exec.expr.holders.IntHolder; import org.apache.drill.exec.record.RecordBatch; +/** + * Function templates for Bit/BOOLEAN functions other than comparison + * functions. (Bit/BOOLEAN comparison functions are generated in + * ComparisonFunctions.java template.) + * + */ public class BitFunctions { - @FunctionTemplate(names = {"booleanOr", "or", "||"}, scope = FunctionScope.SC_BOOLEAN_OPERATOR, nulls = NullHandling.NULL_IF_NULL) + @FunctionTemplate(names = {"booleanOr", "or", "||"}, + scope = FunctionScope.SC_BOOLEAN_OPERATOR, + nulls = NullHandling.NULL_IF_NULL) public static class BitOr implements DrillSimpleFunc { @Param BitHolder left; @@ -43,7 +51,9 @@ public class BitFunctions { } } - @FunctionTemplate(names = {"booleanAnd", "and", "&&"}, scope = FunctionScope.SC_BOOLEAN_OPERATOR, nulls = NullHandling.NULL_IF_NULL) + @FunctionTemplate(names = {"booleanAnd", "and", "&&"}, + scope = FunctionScope.SC_BOOLEAN_OPERATOR, + nulls = NullHandling.NULL_IF_NULL) public static class BitAnd implements DrillSimpleFunc { @Param BitHolder left; @@ -58,7 +68,9 @@ public class BitFunctions { } - @FunctionTemplate(names = {"xor", "^"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + @FunctionTemplate(names = {"xor", "^"}, + scope = FunctionScope.SIMPLE, + nulls = NullHandling.NULL_IF_NULL) public static class IntXor implements DrillSimpleFunc { @Param IntHolder left; @@ -72,32 +84,4 @@ public class BitFunctions { } } - @FunctionTemplate(names = {"equal","==","="}, scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) - public static class EqualsBitBit implements DrillSimpleFunc { - - @Param BitHolder left; - @Param BitHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - out.value = left.value == right.value ? 1 : 0; - - } - } - - @FunctionTemplate(name = "compare_to", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) - public static class CompareBitBit implements DrillSimpleFunc { - - @Param BitHolder left; - @Param BitHolder right; - @Output IntHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - out.value = left.value < right.value ? -1 : ((left.value == right.value)? 0 : 1); - } - } } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java deleted file mode 100644 index bf42ce6c0..000000000 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctions.java +++ /dev/null @@ -1,572 +0,0 @@ -/** - * 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.exec.expr.fn.impl; - - -public class ComparisonFunctions { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MathFunctions.class); - -// private ComparisonFunctions() {} -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class IntEqual implements DrillSimpleFunc { -// -// @Param IntHolder left; -// @Param IntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value == right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class BigIntEqual implements DrillSimpleFunc { -// -// @Param BigIntHolder left; -// @Param BigIntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value == right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float4Equal implements DrillSimpleFunc { -// -// @Param Float4Holder left; -// @Param Float4Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value == right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float8Equal implements DrillSimpleFunc { -// -// @Param Float8Holder left; -// @Param Float8Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value == right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class IntNotEqual implements DrillSimpleFunc { -// -// @Param IntHolder left; -// @Param IntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value != right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class BigIntNotEqual implements DrillSimpleFunc { -// -// @Param BigIntHolder left; -// @Param BigIntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value != right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float4NotEqual implements DrillSimpleFunc { -// -// @Param Float4Holder left; -// @Param Float4Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value != right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "not equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float8NotEqual implements DrillSimpleFunc { -// -// @Param Float8Holder left; -// @Param Float8Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value != right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class IntGreaterThan implements DrillSimpleFunc { -// -// @Param IntHolder left; -// @Param IntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value > right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class BigIntGreaterThan implements DrillSimpleFunc { -// -// @Param BigIntHolder left; -// @Param BigIntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value > right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float4GreaterThan implements DrillSimpleFunc { -// -// @Param Float4Holder left; -// @Param Float4Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value > right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float8GreaterThan implements DrillSimpleFunc { -// -// @Param Float8Holder left; -// @Param Float8Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value > right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class IntGreaterThanEqual implements DrillSimpleFunc { -// -// @Param IntHolder left; -// @Param IntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value >= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class BigIntGreaterThanEqual implements DrillSimpleFunc { -// -// @Param BigIntHolder left; -// @Param BigIntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value >= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float4GreaterThanEqual implements DrillSimpleFunc { -// -// @Param Float4Holder left; -// @Param Float4Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value >= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float8GreaterThanEqual implements DrillSimpleFunc { -// -// @Param Float8Holder left; -// @Param Float8Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value >= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class IntLessThan implements DrillSimpleFunc { -// -// @Param IntHolder left; -// @Param IntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value < right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class BigIntLessThan implements DrillSimpleFunc { -// -// @Param BigIntHolder left; -// @Param BigIntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value < right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float4LessThan implements DrillSimpleFunc { -// -// @Param Float4Holder left; -// @Param Float4Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value < right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float8LessThan implements DrillSimpleFunc { -// -// @Param Float8Holder left; -// @Param Float8Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value < right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class IntLessThanEqual implements DrillSimpleFunc { -// -// @Param IntHolder left; -// @Param IntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value <= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class BigIntLessThanEqual implements DrillSimpleFunc { -// -// @Param BigIntHolder left; -// @Param BigIntHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value <= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float4LessThanEqual implements DrillSimpleFunc { -// -// @Param Float4Holder left; -// @Param Float4Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value <= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class Float8LessThanEqual implements DrillSimpleFunc { -// -// @Param Float8Holder left; -// @Param Float8Holder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = (left.value <= right.value) ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryEqual implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarBinaryHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == 0 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarCharEqual implements DrillSimpleFunc { -// -// @Param VarCharHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == 0 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "equal", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryCharEqual implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == 0 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryGTE implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarBinaryHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) > -1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarCharGTE implements DrillSimpleFunc { -// -// @Param VarCharHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) > -1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryCharGTE implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) > -1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryGT implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarBinaryHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == 1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarCharGT implements DrillSimpleFunc { -// -// @Param VarCharHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == 1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "greater than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryCharGT implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == 1? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryLTE implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarBinaryHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) < 1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarCharLTE implements DrillSimpleFunc { -// -// @Param VarCharHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) < 1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than or equal to", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryCharLTE implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) < 1? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryLT implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarBinaryHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == -1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarCharLT implements DrillSimpleFunc { -// -// @Param VarCharHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == -1 ? 1 : 0; -// } -// } -// -// @FunctionTemplate(name = "less than", scope = FunctionTemplate.FunctionScope.SIMPLE) -// public static class VarBinaryCharLT implements DrillSimpleFunc { -// -// @Param VarBinaryHolder left; -// @Param VarCharHolder right; -// @Output BitHolder out; -// -// public void setup(RecordBatch b) {} -// -// public void eval() { -// out.value = org.apache.drill.exec.expr.fn.impl.VarHelpers.compare(left, right) == -1 ? 1 : 0; -// } -// } - -} diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java deleted file mode 100644 index 570aaeb05..000000000 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ComparisonFunctionsNullable.java +++ /dev/null @@ -1,250 +0,0 @@ -/** - * 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.exec.expr.fn.impl; - -import org.apache.drill.exec.expr.DrillSimpleFunc; -import org.apache.drill.exec.expr.annotations.FunctionTemplate; -import org.apache.drill.exec.expr.annotations.Output; -import org.apache.drill.exec.expr.annotations.Param; -import org.apache.drill.exec.expr.holders.BitHolder; -import org.apache.drill.exec.expr.holders.NullableBigIntHolder; -import org.apache.drill.exec.expr.holders.NullableIntHolder; -import org.apache.drill.exec.record.RecordBatch; - -public class ComparisonFunctionsNullable { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ComparisonFunctionsNullable.class); - - private ComparisonFunctionsNullable() {} - - @FunctionTemplate(names = {"equal", "=", "=="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableIntEqual implements DrillSimpleFunc { - - @Param NullableIntHolder left; - @Param NullableIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value == right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"equal", "=", "=="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableBigIntEqual implements DrillSimpleFunc { - - @Param NullableBigIntHolder left; - @Param NullableBigIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value == right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"not equal", "<>", "!="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableIntNotEqual implements DrillSimpleFunc { - - @Param NullableIntHolder left; - @Param NullableIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value != right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"not equal", "<>", "!="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableBigIntNotEqual implements DrillSimpleFunc { - - @Param NullableBigIntHolder left; - @Param NullableBigIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value != right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"less than","<"}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableIntLessThan implements DrillSimpleFunc { - - @Param NullableIntHolder left; - @Param NullableIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value < right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"less than","<"}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableBigIntLessThan implements DrillSimpleFunc { - - @Param NullableBigIntHolder left; - @Param NullableBigIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value < right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"less than or equal to","<="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableIntLessThanEqual implements DrillSimpleFunc { - - @Param NullableIntHolder left; - @Param NullableIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value <= right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"less than or equal to","<="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableBigIntLessThanEqual implements DrillSimpleFunc { - - @Param NullableBigIntHolder left; - @Param NullableBigIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value <= right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"greater than",">"}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableIntGreaterThan implements DrillSimpleFunc { - - @Param NullableIntHolder left; - @Param NullableIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value > right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"greater than",">"}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableBigIntGreaterThan implements DrillSimpleFunc { - - @Param NullableBigIntHolder left; - @Param NullableBigIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value > right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"greater than or equal to",">="}, scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableIntGreaterThanEqual implements DrillSimpleFunc { - - @Param NullableIntHolder left; - @Param NullableIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value >= right.value) ? 1 : 0; - } - } - } - - @FunctionTemplate(names = {"greater than or equal to",">="}, - scope = FunctionTemplate.FunctionScope.SIMPLE) - public static class NullableBigIntGreaterThanEqual implements DrillSimpleFunc { - - @Param NullableBigIntHolder left; - @Param NullableBigIntHolder right; - @Output BitHolder out; - - public void setup(RecordBatch b) {} - - public void eval() { - if (left.isSet == 0 || right.isSet == 0) { - out.value = 0; - } else { - out.value = (left.value >= right.value) ? 1 : 0; - } - } - } -} diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/TopNBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/TopNBatch.java index 9829fc616..a73bdad9f 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/TopNBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/TopNBatch.java @@ -61,6 +61,7 @@ import org.apache.drill.exec.record.selection.SelectionVector4; import org.apache.drill.exec.vector.ValueVector; import org.apache.drill.exec.vector.complex.AbstractContainerVector; import org.eigenbase.rel.RelFieldCollation.Direction; +import org.eigenbase.rel.RelFieldCollation.NullDirection; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; @@ -324,7 +325,9 @@ public class TopNBatch extends AbstractRecordBatch<TopN> { g.setMappingSet(mainMapping); // next we wrap the two comparison sides and add the expression block for the comparison. - LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, + context.getFunctionRegistry()); HoldingContainer out = g.addExpr(fh, false); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java index 860627d9c..4acf3d6de 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java @@ -248,7 +248,9 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> { cg.setMappingSet(IS_SAME_I2); HoldingContainer second = cg.addExpr(expr, false); - LogicalExpression fh = FunctionGenerationHelper.getComparator(first, second, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper + .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry()); HoldingContainer out = cg.addExpr(fh, false); cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE); } @@ -269,7 +271,9 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> { cg.setMappingSet(ISA_B2); HoldingContainer second = cg.addExpr(expr, false); - LogicalExpression fh = FunctionGenerationHelper.getComparator(first, second, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper + .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry()); HoldingContainer out = cg.addExpr(fh, false); cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE); } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/ChainedHashTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/ChainedHashTable.java index ea196457f..8f921f7f8 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/ChainedHashTable.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/common/ChainedHashTable.java @@ -250,8 +250,10 @@ public class ChainedHashTable { jc._then()._return(JExpr.FALSE); } - // next we wrap the two comparison sides and add the expression block for the comparison. - LogicalExpression f = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + final LogicalExpression f = + FunctionGenerationHelper + .getOrderingComparatorNullsHigh(left, right, context.getFunctionRegistry()); + HoldingContainer out = cg.addExpr(f, false); // check if two values are not equal (comparator result != 0) diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java index a7fa5aac8..8dfc8f1ab 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinStatus.java @@ -72,6 +72,29 @@ public final class JoinStatus { this.joinType = output.getJoinType(); } + @Override + public String toString() { + return + super.toString() + + "[" + + "leftPosition = " + leftPosition + + ", rightPosition = " + rightPosition + + ", svRightPosition = " + svRightPosition + + ", outputPosition = " + outputPosition + + ", lastLeft = " + lastLeft + + ", lastRight = " + lastRight + + ", rightSourceMode = " + rightSourceMode + + ", sv4 = " + sv4 + + ", joinType = " + joinType + + ", ok = " + ok + + ", initialSet = " + initialSet + + ", leftRepeating = " + leftRepeating + + ", left = " + left + + ", right = " + right + + ", outputBatch = " + outputBatch + + "]"; + } + private final IterOutcome nextLeft() { return outputBatch.next(LEFT_INPUT, left); } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java index 48a0996c5..4124e6db5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinTemplate.java @@ -155,7 +155,9 @@ public abstract class JoinTemplate implements JoinWorker { } status.advanceRight(); - } while ((!status.isLeftRepeating() || status.isRightPositionInCurrentBatch()) && status.isRightPositionAllowed() && doCompare(status.getLeftPosition(), status.getRightPosition()) == 0); + } while ((!status.isLeftRepeating() || status.isRightPositionInCurrentBatch()) + && status.isRightPositionAllowed() + && doCompare(status.getLeftPosition(), status.getRightPosition()) == 0); if (status.getRightPosition() > initialRightPosition && (status.isLeftRepeating() || ! status.isNextLeftPositionInCurrentBatch())) { @@ -204,8 +206,8 @@ public abstract class JoinTemplate implements JoinWorker { /** * Copy the data to the new record batch (if it fits). * - * @param leftIndex position of batch (lower 16 bits) and record (upper 16 bits) in left SV4 - * @param outIndex position of the output record batch + * @param leftIndex position of batch (lower 16 bits) and record (upper 16 bits) in left SV4 + * @param outIndex position of the output record batch * @return Whether or not the data was copied. */ public abstract void doCopyLeft(@Named("leftIndex") int leftIndex, @Named("outIndex") int outIndex); @@ -228,8 +230,8 @@ public abstract class JoinTemplate implements JoinWorker { /** * Compare the current left key to the next left key, if it's within the batch. - * @return 0 if both keys are equal - * 1 if the keys are not equal + * @return 0 if both keys are equal, + * 1 if the keys are not equal, and * -1 if there are no more keys in this batch */ protected abstract int doCompareNextLeftKey(@Named("leftIndex") int leftIndex); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/MergeJoinBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/MergeJoinBatch.java index 257b93e9e..8fce52ec7 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/MergeJoinBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/MergeJoinBatch.java @@ -313,12 +313,13 @@ public class MergeJoinBatch extends AbstractRecordBatch<MergeJoinPOP> { // check value equality - LogicalExpression gh = FunctionGenerationHelper.getComparator(compareThisLeftExprHolder, - compareNextLeftExprHolder, - context.getFunctionRegistry()); + LogicalExpression gh = + FunctionGenerationHelper.getOrderingComparatorNullsHigh(compareThisLeftExprHolder, + compareNextLeftExprHolder, + context.getFunctionRegistry()); HoldingContainer out = cg.addExpr(gh, false); - //If not 0, it means not equal. We return this out value. + // If not 0, it means not equal. We return this out value. JConditional jc = cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); jc._then()._return(out.getValue()); } @@ -523,12 +524,13 @@ public class MergeJoinBatch extends AbstractRecordBatch<MergeJoinPOP> { cg.getSetupBlock().assign(JExpr._this().ref(incomingRecordBatch), JExpr._this().ref(incomingRightRecordBatch)); ClassGenerator.HoldingContainer compareRightExprHolder = cg.addExpr(materializedRightExpr, false); - LogicalExpression fh = FunctionGenerationHelper.getComparator(compareLeftExprHolder, - compareRightExprHolder, - context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparatorNullsHigh(compareLeftExprHolder, + compareRightExprHolder, + context.getFunctionRegistry()); HoldingContainer out = cg.addExpr(fh, false); - // If not 0, it means not equal. We return this out value. + // If not 0, it means not equal. // Null compares to Null should returns null (unknown). In such case, we return 1 to indicate they are not equal. if (compareLeftExprHolder.isOptional() && compareRightExprHolder.isOptional() && ! areNullsEqual) { diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/mergereceiver/MergingRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/mergereceiver/MergingRecordBatch.java index d78ba8ed4..804671e56 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/mergereceiver/MergingRecordBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/mergereceiver/MergingRecordBatch.java @@ -76,6 +76,7 @@ import org.apache.drill.exec.vector.CopyUtil; import org.apache.drill.exec.vector.FixedWidthVector; import org.apache.drill.exec.vector.ValueVector; import org.eigenbase.rel.RelFieldCollation.Direction; +import org.eigenbase.rel.RelFieldCollation.NullDirection; import parquet.Preconditions; @@ -636,7 +637,9 @@ public class MergingRecordBatch extends AbstractRecordBatch<MergingReceiverPOP> g.setMappingSet(MAIN_MAPPING); // next we wrap the two comparison sides and add the expression block for the comparison. - LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, + context.getFunctionRegistry()); HoldingContainer out = g.addExpr(fh, false); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/orderedpartitioner/OrderedPartitionRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/orderedpartitioner/OrderedPartitionRecordBatch.java index a06207405..352e7aedf 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/orderedpartitioner/OrderedPartitionRecordBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/orderedpartitioner/OrderedPartitionRecordBatch.java @@ -70,6 +70,7 @@ import org.apache.drill.exec.vector.AllocationHelper; import org.apache.drill.exec.vector.IntVector; import org.apache.drill.exec.vector.ValueVector; import org.eigenbase.rel.RelFieldCollation.Direction; +import org.eigenbase.rel.RelFieldCollation.NullDirection; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; @@ -574,7 +575,10 @@ public class OrderedPartitionRecordBatch extends AbstractRecordBatch<OrderedPart new ValueVectorReadExpression(new TypedFieldId(expr.getMajorType(), count++)), false); cg.setMappingSet(mainMapping); - LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + // next we wrap the two comparison sides and add the expression block for the comparison. + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, + context.getFunctionRegistry()); ClassGenerator.HoldingContainer out = cg.addExpr(fh, false); JConditional jc = cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/sort/SortBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/sort/SortBatch.java index 19f542302..6f19e91d5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/sort/SortBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/sort/SortBatch.java @@ -43,6 +43,7 @@ import org.apache.drill.exec.record.WritableBatch; import org.apache.drill.exec.record.selection.SelectionVector2; import org.apache.drill.exec.record.selection.SelectionVector4; import org.eigenbase.rel.RelFieldCollation.Direction; +import org.eigenbase.rel.RelFieldCollation.NullDirection; import com.sun.codemodel.JConditional; import com.sun.codemodel.JExpr; @@ -180,7 +181,9 @@ public class SortBatch extends AbstractRecordBatch<Sort> { g.setMappingSet(mainMapping); // next we wrap the two comparison sides and add the expression block for the comparison. - LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, + context.getFunctionRegistry()); HoldingContainer out = g.addExpr(fh, false); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/window/StreamingWindowFrameRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/window/StreamingWindowFrameRecordBatch.java index 26d23f231..87209ebf0 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/window/StreamingWindowFrameRecordBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/window/StreamingWindowFrameRecordBatch.java @@ -185,7 +185,9 @@ public class StreamingWindowFrameRecordBatch extends AbstractSingleRecordBatch<W cg.setMappingSet(ISA_B2); ClassGenerator.HoldingContainer second = cg.addExpr(expr, false); - LogicalExpression fh = FunctionGenerationHelper.getComparator(first, second, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper + .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry()); ClassGenerator.HoldingContainer out = cg.addExpr(fh, false); cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE); } @@ -205,7 +207,9 @@ public class StreamingWindowFrameRecordBatch extends AbstractSingleRecordBatch<W cg.setMappingSet(IS_SAME_I2); ClassGenerator.HoldingContainer second = cg.addExpr(expr, false); - LogicalExpression fh = FunctionGenerationHelper.getComparator(first, second, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper + .getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry()); ClassGenerator.HoldingContainer out = cg.addExpr(fh, false); cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE); } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java index 902666141..f320bbbba 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/ExternalSortBatch.java @@ -65,6 +65,7 @@ import org.apache.drill.exec.vector.complex.AbstractContainerVector; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.eigenbase.rel.RelFieldCollation.Direction; +import org.eigenbase.rel.RelFieldCollation.NullDirection; import com.google.common.base.Stopwatch; import com.google.common.collect.Iterators; @@ -565,7 +566,9 @@ public class ExternalSortBatch extends AbstractRecordBatch<ExternalSort> { g.setMappingSet(mainMapping); // next we wrap the two comparison sides and add the expression block for the comparison. - LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, + context.getFunctionRegistry()); HoldingContainer out = g.addExpr(fh, false); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); @@ -612,7 +615,9 @@ public class ExternalSortBatch extends AbstractRecordBatch<ExternalSort> { g.setMappingSet(MAIN_MAPPING); // next we wrap the two comparison sides and add the expression block for the comparison. - LogicalExpression fh = FunctionGenerationHelper.getComparator(left, right, context.getFunctionRegistry()); + LogicalExpression fh = + FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, + context.getFunctionRegistry()); HoldingContainer out = g.addExpr(fh, false); JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0))); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/MSorter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/MSorter.java index e80d30903..d97ffc06e 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/MSorter.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/MSorter.java @@ -24,6 +24,8 @@ import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.record.VectorContainer; import org.apache.drill.exec.record.selection.SelectionVector4; +// TODO: Doc.: What's an MSorter? A sorter for merge join? something else? +// (What's the "M" part? Actually, rename interface to clearer. public interface MSorter { public void setup(FragmentContext context, BufferAllocator allocator, SelectionVector4 vector4, VectorContainer hyperBatch) throws SchemaChangeException; public void sort(VectorContainer container); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrule.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrule.java index 732a34520..72034ed85 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrule.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ProjectPrule.java @@ -115,7 +115,7 @@ public class ProjectPrule extends Prule { for ( RelFieldCollation field : src.getFieldCollations()) { if (inToOut.containsKey(field.getFieldIndex())) { - newFields.add(new RelFieldCollation(inToOut.get(field.getFieldIndex()), field.getDirection())); + newFields.add(new RelFieldCollation(inToOut.get(field.getFieldIndex()), field.getDirection(), field.nullDirection)); } } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/QueryResultHandler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/QueryResultHandler.java index 9015a162c..b07942873 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/QueryResultHandler.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/QueryResultHandler.java @@ -65,7 +65,7 @@ public class QueryResultHandler { if (l == null) { BufferingListener bl = new BufferingListener(); l = resultsListener.putIfAbsent(result.getQueryId(), bl); - // if we had a succesful insert, use that reference. Otherwise, just throw away the new bufering listener. + // if we had a successful insert, use that reference. Otherwise, just throw away the new bufering listener. if (l == null) { l = bl; } |