drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacques-n <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-3232: Handle promoting writers and vecto...
Date Fri, 30 Oct 2015 04:55:28 GMT
Github user jacques-n commented on a diff in the pull request:

    https://github.com/apache/drill/pull/207#discussion_r43471797
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
---
    @@ -308,10 +334,115 @@ public LogicalExpression visitFunctionCall(FunctionCall call, FunctionLookupCont
             return matchedNonDrillFuncHolder.getExpr(call.getName(), extArgsWithCast, call.getPosition());
           }
     
    +      if (hasUnionInput(call)) {
    +        return rewriteUnionFunction(call, functionLookupContext);
    +      }
    +
           logFunctionResolutionError(errorCollector, call);
           return NullExpression.INSTANCE;
         }
     
    +    private static final Set<String> UNION_FUNCTIONS;
    +
    +    static {
    +      UNION_FUNCTIONS = new HashSet<>();
    +      for (MinorType t : MinorType.values()) {
    +        UNION_FUNCTIONS.add("assert_" + t.name().toLowerCase());
    +        UNION_FUNCTIONS.add("is_" + t.name().toLowerCase());
    +      }
    +      UNION_FUNCTIONS.add("typeof");
    +    }
    +
    +    private boolean hasUnionInput(FunctionCall call) {
    +      for (LogicalExpression arg : call.args) {
    +        if (arg.getMajorType().getMinorType() == MinorType.UNION) {
    +          return true;
    +        }
    +      }
    +      return false;
    +    }
    +
    +    private LogicalExpression rewriteUnionFunction(FunctionCall call, FunctionLookupContext
functionLookupContext) {
    +      LogicalExpression[] args = new LogicalExpression[call.args.size()];
    +      call.args.toArray(args);
    +
    +      for (int i = 0; i < args.length; i++) {
    +        LogicalExpression arg = call.args.get(i);
    +        MajorType majorType = arg.getMajorType();
    +
    +        if (majorType.getMinorType() != MinorType.UNION) {
    +          continue;
    +        }
    +
    +        List<MinorType> subTypes = majorType.getSubTypeList();
    +        Preconditions.checkState(subTypes.size() > 0, "Union type has no subtypes");
    +
    +        Queue<IfCondition> ifConditions = Lists.newLinkedList();
    +
    +        for (MinorType minorType : subTypes) {
    +          LogicalExpression ifCondition = getIsTypeExpressionForType(minorType, arg.accept(new
CloneVisitor(), null));
    +          args[i] = getUnionCastExpressionForType(minorType, arg.accept(new CloneVisitor(),
null));
    +
    +          List<LogicalExpression> newArgs = Lists.newArrayList();
    +          for (LogicalExpression e : args) {
    +            newArgs.add(e.accept(new CloneVisitor(), null));
    +          }
    +
    +          errorCollectors.push(errorCollector);
    +          errorCollector = new ErrorCollectorImpl();
    +
    +          LogicalExpression thenExpression = new FunctionCall(call.getName(), newArgs,
call.getPosition()).accept(this, functionLookupContext);
    +
    +          if (errorCollector.hasErrors()) {
    --- End diff --
    
    Let's add comment here about what we're doing re: exceptions.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message