Esempio n. 1
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;
      }
    }
Esempio n. 2
0
    @Override
    public IndexResponse getIndexByColumnNames(
        RpcController controller, GetIndexByColumnNamesRequest request) throws ServiceException {

      TableIdentifierProto identifier = request.getTableIdentifier();
      String databaseName = identifier.getDatabaseName();
      String tableName = identifier.getTableName();
      List<String> columnNamesList = request.getColumnNamesList();
      String[] columnNames = new String[columnNamesList.size()];
      columnNames = columnNamesList.toArray(columnNames);

      rlock.lock();
      try {

        if (!store.existIndexByColumns(databaseName, tableName, columnNames)) {
          return IndexResponse.newBuilder()
              .setState(errUndefinedIndex(tableName, columnNamesList))
              .build();
        }
        return IndexResponse.newBuilder()
            .setState(OK)
            .setIndexDesc(store.getIndexByColumns(databaseName, tableName, columnNames))
            .build();
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);

        return IndexResponse.newBuilder().setState(returnError(t)).build();
      } finally {
        rlock.unlock();
      }
    }
Esempio n. 3
0
    @Override
    public ReturnState existIndexByColumnNames(
        RpcController controller, GetIndexByColumnNamesRequest request) throws ServiceException {

      TableIdentifierProto identifier = request.getTableIdentifier();
      String databaseName = identifier.getDatabaseName();
      String tableName = identifier.getTableName();
      List<String> columnNames = request.getColumnNamesList();

      try {
        // linked meta data do not support index. The request will be failed.
        if (linkedMetadataManager.existsDatabase(databaseName)) {
          return errUndefinedIndex(tableName);
        }
      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      }

      rlock.lock();
      try {
        return store.existIndexByColumns(
                databaseName, tableName, columnNames.toArray(new String[columnNames.size()]))
            ? OK
            : errUndefinedIndex(tableName, columnNames);

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        return returnError(t);
      } finally {
        rlock.unlock();
      }
    }
Esempio n. 4
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();
      }
Esempio n. 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;
    }
Esempio n. 6
0
 public FunctionSignature(String signature, FunctionType type, List<DataType> arguments) {
   this.signature = signature;
   this.type = type;
   this.arguments = arguments.toArray(new DataType[arguments.size()]);
 }
Esempio n. 7
0
 private boolean containFunction(String signature) {
   List<FunctionDescProto> found = findFunction(signature);
   return found != null && found.size() > 0;
 }