@Override public Response run(JerseyResourceDelegateContext context) { JerseyResourceDelegateContextKey<MasterContext> masterContextKey = JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class); MasterContext masterContext = context.get(masterContextKey); Collection<FunctionDesc> functionDescriptors = masterContext.getCatalog().getFunctions(); if (functionDescriptors.size() > 0) { List<FunctionSignature> functionSignature = new ArrayList<FunctionSignature>(functionDescriptors.size()); for (FunctionDesc functionDesc : functionDescriptors) { functionSignature.add(functionDesc.getSignature()); } return Response.ok(functionSignature).build(); } else { return Response.status(Status.NOT_FOUND).build(); } } }
@Override public Response run(JerseyResourceDelegateContext context) { JerseyResourceDelegateContextKey<MasterContext> masterContextKey = JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class); MasterContext masterContext = context.get(masterContextKey); Collection<FunctionDesc> functionDescriptors = masterContext.getCatalog().getFunctions(); if (functionDescriptors.size() > 0) { List<FunctionSignature> functionSignature = new ArrayList<>(functionDescriptors.size()); for (FunctionDesc functionDesc : functionDescriptors) { functionSignature.add(functionDesc.getSignature()); } return Response.ok(functionSignature).build(); } else { return Response.status(Status.NOT_FOUND).build(); } } }
@Override public FunctionListResponse getFunctionList(RpcController controller, SessionedStringProto request) throws ServiceException { try { context.getSessionManager().touch(request.getSessionId().getId()); String functionName = request.getValue(); Collection<FunctionDesc> functions = catalog.getFunctions(); List<CatalogProtos.FunctionDescProto> functionProtos = new ArrayList<>(); for (FunctionDesc eachFunction: functions) { if (functionName == null || functionName.isEmpty()) { functionProtos.add(eachFunction.getProto()); } else { if(functionName.equals(eachFunction.getFunctionName())) { functionProtos.add(eachFunction.getProto()); } } } return FunctionListResponse.newBuilder() .setState(OK) .addAllFunction(functionProtos) .build(); } catch (Throwable t) { printStackTraceIfError(LOG, t); return FunctionListResponse.newBuilder(). setState(returnError(t)) .build(); } }
@Override public FunctionListResponse getFunctionList(RpcController controller, SessionedStringProto request) throws ServiceException { try { context.getSessionManager().touch(request.getSessionId().getId()); String functionName = request.getValue(); Collection<FunctionDesc> functions = catalog.getFunctions(); List<CatalogProtos.FunctionDescProto> functionProtos = new ArrayList<CatalogProtos.FunctionDescProto>(); for (FunctionDesc eachFunction: functions) { if (functionName == null || functionName.isEmpty()) { functionProtos.add(eachFunction.getProto()); } else { if(functionName.equals(eachFunction.getFunctionName())) { functionProtos.add(eachFunction.getProto()); } } } return FunctionListResponse.newBuilder() .setState(OK) .addAllFunction(functionProtos) .build(); } catch (Throwable t) { printStackTraceIfError(LOG, t); return FunctionListResponse.newBuilder(). setState(returnError(t)) .build(); } }
@Test public final void testGetFunctions() throws IOException, TajoException { Collection<FunctionDesc> catalogFunctions = cluster.getMaster().getCatalog().getFunctions(); String functionName = "sum"; int numFunctions = 0; for(FunctionDesc eachFunction: catalogFunctions) { if(functionName.equals(eachFunction.getFunctionName())) { numFunctions++; } } List<CatalogProtos.FunctionDescProto> functions = client.getFunctions(functionName); assertEquals(numFunctions, functions.size()); functions = client.getFunctions("notmatched"); assertEquals(0, functions.size()); functions = client.getFunctions(null); assertEquals(catalogFunctions.size(), functions.size()); }