Example #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;
      }
    }
Example #2
0
    @Override
    public GetTablespaceListResponse getAllTablespaces(RpcController controller, NullProto request)
        throws ServiceException {
      rlock.lock();
      try {

        // retrieves tablespaces from catalog store
        final List<TablespaceProto> tableSpaces = Lists.newArrayList(store.getTablespaces());

        // retrieves tablespaces from linked meta data
        tableSpaces.addAll(
            Collections2.transform(
                linkedMetadataManager.getTablespaces(),
                new Function<Pair<String, URI>, TablespaceProto>() {
                  @Override
                  public TablespaceProto apply(Pair<String, URI> input) {
                    return TablespaceProto.newBuilder()
                        .setSpaceName(input.getFirst())
                        .setUri(input.getSecond().toString())
                        .build();
                  }
                }));

        return GetTablespaceListResponse.newBuilder()
            .setState(OK)
            .addAllTablespace(tableSpaces)
            .build();

      } catch (Throwable t) {
        printStackTraceIfError(LOG, t);
        throw new ServiceException(t);
      } finally {
        rlock.unlock();
      }
    }
Example #3
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();
      }
    }
Example #4
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();
      }
    }
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
      @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 #7
0
 public FunctionSignature(String signature, FunctionType type, List<DataType> arguments) {
   this.signature = signature;
   this.type = type;
   this.arguments = arguments.toArray(new DataType[arguments.size()]);
 }
Example #8
0
 /**
  * Find the nearest matched function
  *
  * @param candidates Candidate Functions
  * @return
  */
 private FunctionDescProto findNearestMatchedFunction(List<FunctionDescProto> candidates) {
   Collections.sort(candidates, new NearestParamsComparator());
   return candidates.get(0);
 }
Example #9
0
 private boolean containFunction(String signature) {
   List<FunctionDescProto> found = findFunction(signature);
   return found != null && found.size() > 0;
 }