Github user jacques-n commented on a diff in the pull request:

    https://github.com/apache/drill/pull/257#discussion_r44882947
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/UnionFunctions.java
 ---
    @@ -32,16 +33,72 @@
     import org.apache.drill.exec.expr.holders.UnionHolder;
     import org.apache.drill.exec.expr.holders.IntHolder;
     import org.apache.drill.exec.expr.holders.VarCharHolder;
    +import org.apache.drill.exec.resolver.TypeCastRules;
     import org.apache.drill.exec.vector.complex.impl.UnionReader;
     import org.apache.drill.exec.vector.complex.reader.FieldReader;
     
     import javax.inject.Inject;
    +import java.util.Set;
     
     /**
      * The class contains additional functions for union types in addition to 
those in GUnionFunctions
      */
     public class UnionFunctions {
     
    +  /**
    +   * Returns zero if the inputs have equivalent types. Two numeric types 
are considered equivalent, as are a combination
    +   * of date/timestamp. If not equivalent, returns a value determined by 
the numeric value of the MinorType enum
    +   */
    +  @FunctionTemplate(names = {"compareType"},
    +          scope = FunctionTemplate.FunctionScope.SIMPLE,
    +          nulls = NullHandling.INTERNAL)
    +  public static class CompareType implements DrillSimpleFunc {
    +
    +    @Param
    +    FieldReader input1;
    +    @Param
    +    FieldReader input2;
    +    @Output
    +    IntHolder out;
    +
    +    public void setup() {}
    +
    +    public void eval() {
    +      org.apache.drill.common.types.TypeProtos.MinorType type1;
    +      if (input1.isSet()) {
    +        type1 = input1.getType().getMinorType();
    +      } else {
    +        type1 = org.apache.drill.common.types.TypeProtos.MinorType.NULL;
    +      }
    +      org.apache.drill.common.types.TypeProtos.MinorType type2;
    +      if (input2.isSet()) {
    +        type2 = input2.getType().getMinorType();
    +      } else {
    +        type2 = org.apache.drill.common.types.TypeProtos.MinorType.NULL;
    +      }
    +
    +      out.value = 
org.apache.drill.exec.expr.fn.impl.UnionFunctions.compareTypes(type1, type2);
    +    }
    +  }
    +
    +  public static int compareTypes(MinorType type1, MinorType type2) {
    +    int typeValue1 = getTypeValue(type1);
    +    int typeValue2 = getTypeValue(type2);
    +    return typeValue1 - typeValue2;
    +  }
    +
    +  private static int getTypeValue(MinorType type) {
    +    if (TypeCastRules.isNumericType(type)) {
    --- End diff --
    
    would be good to add comments here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to