Example #1
0
 private FunctionDescProto findFunctionStrictType(
     FunctionDescProto target, boolean strictTypeCheck) {
   return findFunction(
       target.getSignature().getName(),
       target.getSignature().getType(),
       target.getSignature().getParameterTypesList(),
       strictTypeCheck);
 }
Example #2
0
      @Override
      public int compare(FunctionDescProto o1, FunctionDescProto o2) {
        List<DataType> types1 = o1.getSignature().getParameterTypesList();
        List<DataType> types2 = o2.getSignature().getParameterTypesList();

        int minLen = Math.min(types1.size(), types2.size());

        for (int i = 0; i < minLen; i++) {
          int cmpVal = types1.get(i).getType().getNumber() - types2.get(i).getType().getNumber();

          if (cmpVal != 0) {
            return cmpVal;
          }
        }

        return types1.size() - types2.size();
      }
Example #3
0
    private FunctionDescProto findFunction(
        String signature,
        FunctionType type,
        List<TajoDataTypes.DataType> params,
        boolean strictTypeCheck) {
      List<FunctionDescProto> candidates = Lists.newArrayList();

      if (functions.containsKey(signature)) {
        if (strictTypeCheck) {
          for (FunctionDescProto func : functions.get(signature)) {
            if (func.getSignature().getType() == type
                && func.getSignature().getParameterTypesList().equals(params)) {
              candidates.add(func);
            }
          }
        } else {
          for (FunctionDescProto func : functions.get(signature)) {
            if (func.getSignature().getParameterTypesList() != null
                && CatalogUtil.isMatchedFunction(
                    func.getSignature().getParameterTypesList(), params)) {
              candidates.add(func);
            }
          }
        }
      }

      // if there are more than one function candidates, we choose the nearest matched function.
      if (candidates.size() > 0) {
        return findNearestMatchedFunction(candidates);
      } else {
        return null;
      }
    }
Example #4
0
    @Override
    public ReturnState createFunction(RpcController controller, FunctionDescProto funcDesc) {

      try {
        FunctionSignature signature = FunctionSignature.create(funcDesc);

        if (functions.containsKey(funcDesc.getSignature())) {
          FunctionDescProto found = findFunctionStrictType(funcDesc, true);
          if (found != null) {
            return errDuplicateFunction(signature.toString());
          }
        }

        TUtil.putToNestedList(functions, funcDesc.getSignature().getName(), funcDesc);

        return OK;

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      }
    }
Example #5
0
    private FunctionDescProto findFunction(String signature, List<TajoDataTypes.DataType> params) {
      List<FunctionDescProto> candidates = Lists.newArrayList();

      if (functions.containsKey(signature)) {
        for (FunctionDescProto func : functions.get(signature)) {
          if (func.getSignature().getParameterTypesList() != null
              && func.getSignature().getParameterTypesList().equals(params)) {
            candidates.add(func);
          }
        }
      }

      /*
       *
       * FALL BACK to look for nearest match
       * WORKING BUT BAD WAY TO IMPLEMENT.I WOULD RATHER implement compareTo in FunctionDesc to keep them
       * in sorted order of param types LIKE INT1 SHOULD BE BEFORE INT2 should be before INT3 so on.
       * Due to possibility of multiple parameters and types the permutation and combinations are endless
       * to implement compareTo so decided to take the shortcut.
       *
       * */
      if (functions.containsKey(signature)) {
        for (FunctionDescProto func : functions.get(signature)) {
          if (func.getSignature().getParameterTypesList() != null
              && CatalogUtil.isMatchedFunction(
                  func.getSignature().getParameterTypesList(), params)) {
            candidates.add(func);
          }
        }

        // if there are more than one function candidates, we choose the nearest matched function.
        if (candidates.size() > 0) {
          return findNearestMatchedFunction(candidates);
        } else {
          return null;
        }
      }

      return null;
    }
Example #6
0
 public static FunctionSignature create(FunctionDescProto proto) {
   return new FunctionSignature(
       proto.getSignature().getName(),
       proto.getSignature().getType(),
       proto.getSignature().getParameterTypesList());
 }