You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vo...@apache.org on 2021/02/24 18:35:44 UTC
[drill] branch master updated: DRILL-7867: Allow using required
arguments for functions with nullable parameters
This is an automated email from the ASF dual-hosted git repository.
volodymyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
The following commit(s) were added to refs/heads/master by this push:
new 4e3cc06 DRILL-7867: Allow using required arguments for functions with nullable parameters
4e3cc06 is described below
commit 4e3cc06557283904092e6f9b82443a9091da794d
Author: Volodymyr Vysotskyi <vv...@gmail.com>
AuthorDate: Sun Feb 21 14:48:44 2021 +0200
DRILL-7867: Allow using required arguments for functions with nullable parameters
---
.../drill/exec/expr/fn/impl/StringFunctions.java | 43 +---------------------
.../apache/drill/exec/resolver/TypeCastRules.java | 10 +++--
2 files changed, 8 insertions(+), 45 deletions(-)
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
index 7b2aaba..22edb47 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
@@ -37,6 +37,7 @@ import org.apache.drill.exec.expr.holders.NullableVarCharHolder;
import org.apache.drill.exec.expr.holders.VarBinaryHolder;
import org.apache.drill.exec.expr.holders.VarCharHolder;
import org.apache.drill.exec.physical.impl.project.OutputSizeEstimateConstants;
+import org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter;
import javax.inject.Inject;
import java.nio.charset.Charset;
@@ -1360,46 +1361,6 @@ public class StringFunctions{
@FunctionTemplate(name = "split", scope = FunctionScope.SIMPLE,
outputWidthCalculatorType = OutputWidthCalculatorType.CUSTOM_FIXED_WIDTH_DEFAULT)
- public static class Split implements DrillSimpleFunc {
- @Param VarCharHolder in;
- @Param VarCharHolder delimiter;
-
- @Workspace com.google.common.base.Splitter splitter;
- @Inject DrillBuf buffer;
-
- @Output org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter writer;
-
- @Override
- public void setup() {
- int len = delimiter.end - delimiter.start;
- if (len != 1) {
- throw new IllegalArgumentException("Only single character delimiters are supported for split()");
- }
- char splitChar = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.
- toStringFromUTF8(delimiter.start, delimiter.end, delimiter.buffer).charAt(0);
- splitter = com.google.common.base.Splitter.on(splitChar);
- }
-
- @Override
- public void eval() {
- String inputString =
- org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(in.start, in.end, in.buffer);
- // Convert the iterable to an array as Janino will not handle generics.
- Object[] tokens = com.google.common.collect.Iterables.toArray(splitter.split(inputString), String.class);
- org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter list = writer.rootAsList();
- list.startList();
- for (Object token : tokens) {
- final byte[] strBytes = ((String) token).getBytes(com.google.common.base.Charsets.UTF_8);
- buffer = buffer.reallocIfNeeded(strBytes.length);
- buffer.setBytes(0, strBytes);
- list.varChar().writeVarChar(0, strBytes.length, buffer);
- }
- list.endList();
- }
- }
-
- @FunctionTemplate(name = "split", scope = FunctionScope.SIMPLE,
- outputWidthCalculatorType = OutputWidthCalculatorType.CUSTOM_FIXED_WIDTH_DEFAULT)
public static class SplitNullableInput implements DrillSimpleFunc {
@Param NullableVarCharHolder in;
@Param VarCharHolder delimiter;
@@ -1407,7 +1368,7 @@ public class StringFunctions{
@Workspace com.google.common.base.Splitter splitter;
@Inject DrillBuf buffer;
- @Output org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter writer;
+ @Output ComplexWriter writer;
@Override
public void setup() {
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
index 9baf6c5..b617572 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
@@ -683,14 +683,16 @@ public class TypeCastRules {
rules.put(MinorType.DICT, Sets.newHashSet(MinorType.DICT));
}
- public static boolean isCastableWithNullHandling(MajorType from, MajorType to, NullHandling nullHandling) {
- if ((from.getMode() == DataMode.REPEATED || to.getMode() == DataMode.REPEATED) && from.getMode() != to.getMode()) {
+ public static boolean isCastableWithNullHandling(MajorType argumentType, MajorType paramType, NullHandling nullHandling) {
+ if ((argumentType.getMode() == DataMode.REPEATED || paramType.getMode() == DataMode.REPEATED) && argumentType.getMode() != paramType.getMode()) {
return false;
}
- if (nullHandling == NullHandling.INTERNAL && from.getMode() != to.getMode()) {
+ // allow using functions with nullable parameters for required arguments only for the case of data mode mismatch
+ if (nullHandling == NullHandling.INTERNAL && argumentType.getMode() != paramType.getMode()
+ && (paramType.getMode() != DataMode.OPTIONAL || argumentType.getMode() != DataMode.REQUIRED)) {
return false;
}
- return isCastable(from.getMinorType(), to.getMinorType());
+ return isCastable(argumentType.getMinorType(), paramType.getMinorType());
}
public static boolean isCastable(MinorType from, MinorType to) {