[ 
https://issues.apache.org/jira/browse/DRILL-6810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16660504#comment-16660504
 ] 

ASF GitHub Bot commented on DRILL-6810:
---------------------------------------

arina-ielchiieva commented on a change in pull request #1509: DRILL-6810: 
Disable NULL_IF_NULL NullHandling for functions with Comp…
URL: https://github.com/apache/drill/pull/1509#discussion_r227352819
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/ParseUrlFunction.java
 ##########
 @@ -22,134 +22,238 @@
 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.NullableVarCharHolder;
 import org.apache.drill.exec.expr.holders.VarCharHolder;
 import org.apache.drill.exec.vector.complex.writer.BaseWriter;
 
 import javax.inject.Inject;
 
-@FunctionTemplate(
-        name="parse_url",
-        scope= FunctionTemplate.FunctionScope.SIMPLE,
-        nulls = FunctionTemplate.NullHandling.NULL_IF_NULL
-)
+public class ParseUrlFunction {
 
-public class ParseUrlFunction implements DrillSimpleFunc {
+  @FunctionTemplate(name = "parse_url", scope = 
FunctionTemplate.FunctionScope.SIMPLE)
+  public static class ParseUrl implements DrillSimpleFunc {
 
-    @Param VarCharHolder input;
+    @Param
+    VarCharHolder in;
+    @Output
+    BaseWriter.ComplexWriter outWriter;
+    @Inject
+    DrillBuf outBuffer;
 
-    @Output BaseWriter.ComplexWriter outWriter;
-
-    @Inject DrillBuf outBuffer;
-
-    public void setup() {}
+    @Override
+    public void setup() {
+    }
 
+    @Override
     public void eval() {
+      org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter 
urlMapWriter = outWriter.rootAsMap();
+
+      String urlString =
+          
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(in.start,
 in.end, in.buffer);
+      try {
+        java.net.URL aURL = new java.net.URL(urlString);
+
+        String protocol = aURL.getProtocol();
+        String authority = aURL.getAuthority();
+        String host = aURL.getHost();
+        java.lang.Integer port = aURL.getPort();
+        String path = aURL.getPath();
+        String query = aURL.getQuery();
+        String filename = aURL.getFile();
+        String ref = aURL.getRef();
+
+        org.apache.drill.exec.expr.holders.VarCharHolder rowHolder =
+            new org.apache.drill.exec.expr.holders.VarCharHolder();
+
+        urlMapWriter.start();
+
+        byte[] protocolBytes = protocol.getBytes();
+        outBuffer.reallocIfNeeded(protocolBytes.length);
+        outBuffer.setBytes(0, protocolBytes);
+        rowHolder.start = 0;
+        rowHolder.end = protocolBytes.length;
+        rowHolder.buffer = outBuffer;
+        urlMapWriter.varChar("protocol").write(rowHolder);
+
+        byte[] authorityBytes = authority.getBytes();
+        outBuffer.reallocIfNeeded(authorityBytes.length);
+        outBuffer.setBytes(0, authorityBytes);
+        rowHolder.start = 0;
+        rowHolder.end = authorityBytes.length;
+        rowHolder.buffer = outBuffer;
+        urlMapWriter.varChar("authority").write(rowHolder);
+
+        byte[] hostBytes = host.getBytes();
+        outBuffer.reallocIfNeeded(hostBytes.length);
+        outBuffer.setBytes(0, hostBytes);
+        rowHolder.start = 0;
+        rowHolder.end = hostBytes.length;
+        rowHolder.buffer = outBuffer;
+        urlMapWriter.varChar("host").write(rowHolder);
+
+        byte[] pathBytes = path.getBytes();
+        outBuffer.reallocIfNeeded(pathBytes.length);
+        outBuffer.setBytes(0, pathBytes);
+        rowHolder.start = 0;
+        rowHolder.end = pathBytes.length;
+        rowHolder.buffer = outBuffer;
+        urlMapWriter.varChar("path").write(rowHolder);
+
+        if (query != null) {
+          byte[] queryBytes = query.getBytes();
+          outBuffer.reallocIfNeeded(queryBytes.length);
+          outBuffer.setBytes(0, queryBytes);
+          rowHolder.start = 0;
+          rowHolder.end = queryBytes.length;
+          rowHolder.buffer = outBuffer;
+          urlMapWriter.varChar("query").write(rowHolder);
+        }
 
-        org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter 
urlMapWriter = outWriter.rootAsMap();
-
-        String urlString = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start,
 input.end, input.buffer);
-
-        try {
-            java.net.URL aURL = new java.net.URL(urlString);
-
-            String protocol = aURL.getProtocol();
-            String authority = aURL.getAuthority();
-            String host = aURL.getHost();
-            java.lang.Integer port = aURL.getPort();
-            String path = aURL.getPath();
-            String query = aURL.getQuery();
-            String filename = aURL.getFile();
-            String ref = aURL.getRef();
-
-            org.apache.drill.exec.expr.holders.VarCharHolder rowHolder = new 
org.apache.drill.exec.expr.holders.VarCharHolder();
-
-            byte[] rowStringBytes = protocol.getBytes();
-
-            outBuffer.reallocIfNeeded(rowStringBytes.length);
-            outBuffer.setBytes(0, rowStringBytes);
-
-            rowHolder.start = 0;
-            rowHolder.end = rowStringBytes.length;
-            rowHolder.buffer = outBuffer;
-
-            urlMapWriter.varChar("protocol").write(rowHolder);
-
-
-            byte[] authRowStringBytes = authority.getBytes();
-
-            outBuffer.reallocIfNeeded(authRowStringBytes.length);
-            outBuffer.setBytes(0, authRowStringBytes);
-
-            rowHolder.start = 0;
-            rowHolder.end = authRowStringBytes.length;
-            rowHolder.buffer = outBuffer;
-
-            urlMapWriter.varChar("authority").write(rowHolder);
-
-
-            byte[] hostRowStringBytes = host.getBytes();
-
-            outBuffer.reallocIfNeeded(hostRowStringBytes.length);
-            outBuffer.setBytes(0, hostRowStringBytes);
-
-            rowHolder.start = 0;
-            rowHolder.end = hostRowStringBytes.length;
-            rowHolder.buffer = outBuffer;
-
-            urlMapWriter.varChar("host").write(rowHolder);
-
-
-            byte[] pathRowStringBytes = path.getBytes();
-
-            outBuffer.reallocIfNeeded(pathRowStringBytes.length);
-            outBuffer.setBytes(0, pathRowStringBytes);
-
-            rowHolder.start = 0;
-            rowHolder.end = pathRowStringBytes.length;
-            rowHolder.buffer = outBuffer;
-
-            urlMapWriter.varChar("path").write(rowHolder);
-
-
-            byte[] queryRowStringBytes = query.getBytes();
-
-            outBuffer.reallocIfNeeded(queryRowStringBytes.length);
-            outBuffer.setBytes(0, queryRowStringBytes);
-
-            rowHolder.start = 0;
-            rowHolder.end = queryRowStringBytes.length;
-            rowHolder.buffer = outBuffer;
-
-            urlMapWriter.varChar("query").write(rowHolder);
-
-
-            byte[] filenameRowStringBytes = filename.getBytes();
-
-            outBuffer.reallocIfNeeded(filenameRowStringBytes.length);
-            outBuffer.setBytes(0, filenameRowStringBytes);
+        byte[] filenameBytes = filename.getBytes();
+        outBuffer.reallocIfNeeded(filenameBytes.length);
+        outBuffer.setBytes(0, filenameBytes);
+        rowHolder.start = 0;
+        rowHolder.end = filenameBytes.length;
+        rowHolder.buffer = outBuffer;
+        urlMapWriter.varChar("filename").write(rowHolder);
+
+        if (ref != null) {
+          byte[] refBytes = ref.getBytes();
+          outBuffer.reallocIfNeeded(refBytes.length);
+          outBuffer.setBytes(0, refBytes);
+          rowHolder.start = 0;
+          rowHolder.end = refBytes.length;
+          rowHolder.buffer = outBuffer;
+          urlMapWriter.varChar("ref").write(rowHolder);
+        }
 
-            rowHolder.start = 0;
-            rowHolder.end = filenameRowStringBytes.length;
-            rowHolder.buffer = outBuffer;
+        if (port != -1) {
 
 Review comment:
   Please add comment.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Disable NULL_IF_NULL NullHandling for functions with ComplexWriter
> ------------------------------------------------------------------
>
>                 Key: DRILL-6810
>                 URL: https://issues.apache.org/jira/browse/DRILL-6810
>             Project: Apache Drill
>          Issue Type: Bug
>    Affects Versions: 1.14.0
>            Reporter: Bohdan Kazydub
>            Assignee: Bohdan Kazydub
>            Priority: Major
>             Fix For: 1.15.0
>
>
> Currently NullHandling.NULL_IF_NULL is allowed for UDFs with @Output of type 
> org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter but no 
> null handling is performed for the kind of functions which leads to 
> confusion. The problem is ComplexWriter holds list/map values and Drill does 
> not yet support NULL values for the types (there is an issue to allow null 
> maps/lists in [DRILL-4824|https://issues.apache.org/jira/browse/DRILL-4824]).
> For such functions support for NULL_IF_NULL will be disabled, as it is done 
> for aggregate functions, and NullHandling.INTERNAL should be used instead.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to