public Function addFunctionIfNotExists(Function function) { synchronized (functions) { FunctionSignature signature = new FunctionSignature(function.getDataverseName(), function.getName(), function.getArity()); Function fun = functions.get(signature); if (fun == null) { return functions.put(signature, function); } return null; } }
public Function dropFunction(Function function) { synchronized (functions) { FunctionSignature signature = new FunctionSignature(function.getDataverseName(), function.getName(), function.getArity()); Function fun = functions.get(signature); if (fun == null) { return null; } return functions.remove(signature); } }
private void confirmDatasetCanBeDeleted(TxnId txnId, String dataverseName, String datasetName) throws AlgebricksException, RemoteException { // If any function uses this type, throw an error List<Function> functions = getAllFunctions(txnId); for (Function function : functions) { for (List<String> datasetDependency : function.getDependencies().get(0)) { if (datasetDependency.get(0).equals(dataverseName) && datasetDependency.get(1).equals(datasetName)) { throw new AlgebricksException("Cannot drop dataset " + dataverseName + "." + datasetName + " being used by function " + function.getDataverseName() + "." + function.getName() + "@" + function.getArity()); } } } }
private void confirmFunctionCanBeDeleted(TxnId txnId, FunctionSignature signature) throws AlgebricksException, RemoteException { // If any other function uses this function, throw an error List<Function> functions = getAllFunctions(txnId); for (Function function : functions) { for (List<String> functionalDependency : function.getDependencies().get(1)) { if (functionalDependency.get(0).equals(signature.getNamespace()) && functionalDependency.get(1).equals(signature.getName()) && functionalDependency.get(2).equals(Integer.toString(signature.getArity()))) { throw new AlgebricksException("Cannot drop function " + signature + " being used by function " + function.getDataverseName() + "." + function.getName() + "@" + function.getArity()); } } } }
if (datasetDependency.get(0).equals(dataverseName)) { throw new AlgebricksException("Cannot drop dataverse. Function " + function.getDataverseName() + "." + function.getName() + "@" + function.getArity() + " depends on dataset " + datasetDependency.get(0) + "." + datasetDependency.get(1)); throw new AlgebricksException( "Cannot drop dataverse. Function " + function.getDataverseName() + "." + function.getName() + "@" + function.getArity() + " depends on function " + functionDependency.get(0) + "." + functionDependency.get(1) + "@" + functionDependency.get(2));
@Override public void addFunction(TxnId txnId, Function function) throws AlgebricksException, RemoteException { try { // Insert into the 'function' dataset. FunctionTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getFunctionTupleTranslator(true); ITupleReference functionTuple = tupleReaderWriter.getTupleFromMetadataEntity(function); insertTupleIntoIndex(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple); } catch (HyracksDataException e) { if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.DUPLICATE_KEY) { throw new AlgebricksException("A function with this name " + function.getName() + " and arity " + function.getArity() + " already exists in dataverse '" + function.getDataverseName() + "'.", e); } else { throw new AlgebricksException(e); } } }
private static IFunctionInfo getScalarFunctionInfo(MetadataTransactionContext txnCtx, Function function) throws AlgebricksException { FunctionIdentifier fid = new FunctionIdentifier(function.getDataverseName(), function.getName(), function.getArity()); IResultTypeComputer typeComputer = getResultTypeComputer(txnCtx, function); List<IAType> arguments = new ArrayList<>(); IAType returnType; List<String> argumentTypes = function.getArguments(); for (String argumentType : argumentTypes) { arguments.add(getTypeInfo(argumentType, txnCtx, function)); } returnType = getTypeInfo(function.getReturnType(), txnCtx, function); return new ExternalScalarFunctionInfo(fid.getNamespace(), fid.getName(), fid.getArity(), returnType, function.getFunctionBody(), function.getLanguage(), arguments, typeComputer); }
dropFunction(txnId, new FunctionSignature(dataverseName, function.getName(), function.getArity()), true);
new FunctionSignature(dataverse, function.getName(), function.getArity()));
if (isFunctionUsed(mdTxnCtx, function.getSignature(), dataverseName)) { throw new MetadataException(ErrorCode.METADATA_DROP_FUCTION_IN_USE, sourceLoc, function.getDataverseName() + "." + function.getName() + "@" + function.getArity());
stringSerde.serialize(aString, tupleBuilder.getDataOutput()); tupleBuilder.addFieldEndOffset(); aString.setValue(function.getArity() + ""); stringSerde.serialize(aString, tupleBuilder.getDataOutput()); tupleBuilder.addFieldEndOffset(); aString.setValue(function.getArity() + ""); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_ARITY_FIELD_INDEX, fieldValue);