vdiravka commented on a change in pull request #1494: DRILL-6768: Improve 
to_date, to_time and to_timestamp and correspondi…
URL: https://github.com/apache/drill/pull/1494#discussion_r226455956
 
 

 ##########
 File path: 
exec/java-exec/src/main/codegen/templates/DateIntervalFunctionTemplates/EmptyStringToDateTypeFunctions.java
 ##########
 @@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+import org.apache.drill.exec.expr.annotations.Workspace;
+
+<@pp.dropOutputFile />
+
+<#list dateIntervalFunc.emptyStringToDateConversion as conversion>
+
+<@pp.changeOutputFile 
name="/org/apache/drill/exec/expr/fn/impl/G${conversion.from}To${conversion.to}.java"
 />
+
+<#include "/@includes/license.ftl" />
+
+    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.FunctionTemplate.NullHandling;
+    import org.apache.drill.exec.expr.annotations.Output;
+    import org.apache.drill.exec.expr.annotations.Workspace;
+    import org.apache.drill.exec.expr.annotations.Param;
+    import org.apache.drill.exec.expr.holders.*;
+    import org.apache.drill.exec.record.RecordBatch;
+
+/*
+ * This class is generated using freemarker and the ${.template_name} template.
+ */
+@FunctionTemplate(name = "convert${conversion.from}To${conversion.to}", scope 
= FunctionTemplate.FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
 
 Review comment:
   I think `NULL_IF_NULL` mode fits better these functions (allows to skip 
functions `eval` blocks in case of null inputs), but I found that it doesn't 
work for your case with empty input VarChar `""`. Not sure that it is expected.
   If `NULL_IF_NULL` means null output value if and only if null input, then 
everything is ok, but it should be described better only.
   But looks like null outputs for non null inputs could be allowed in [some 
cases](https://github.com/apache/drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java#L143).
 I will describe it in more detail.
   
   I have tried to use `NULL_IF_NULL` mode for your function 
`castEmptyStringNullableVarCharToNULLABLEDATE` for 3 input VarChar values:
   1.  "1997-12-10"
   2. null
   3. ""
   
   1 and 2 cases for work as intended. But for 3 case the logic for proper 
output from the function is performed as intended:
   ```
   if (in.isSet == 0 || in.end == in.start) {
           out.isSet = 0;
           break CastNullableVarCharNullableVarCharToNullableDate_eval;
       }
   ```
   and then additional logic is added right after the previous one:
   ```
   CastNullableVarCharNullableVarCharToNullableDate_eval: {
       if (in.isSet == 0 || in.end == in.start) {
           out.isSet = 0;
           break CastNullableVarCharNullableVarCharToNullableDate_eval;
       }
       out.isSet = 1;
       out.value = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getDate(in.buffer, 
in.start, in.end);
   }
    
                       out.isSet = 1;
                       out4 = out;
                       out.isSet = 1;
   ```
   [This 
code](https://github.com/apache/drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java#L143)
 is [duplicated 
here](https://github.com/apache/drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/DrillSimpleFuncHolder.java#L147).
 Looks like second statement is redundant and first one along with a comment is 
questionable.
   It sets the output to 1, so it means non-nullable output in any case and 
consequently `1970-01-01` output date for "" input VarChar.
   
   Or am I missed something here? 
   
   We can consider 3 ways here:
   to update javadoc to reflect this: 
   > NULL output if and only if NULL input
   
   or to ask community, or to open the Jira ticket.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to