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()); } } } }
public FunctionDecl getFunctionDecl(Function function) throws CompilationException { if (!function.getLanguage().equals(Function.LANGUAGE_SQLPP)) { throw new CompilationException(ErrorCode.COMPILATION_INCOMPATIBLE_FUNCTION_LANGUAGE, Function.LANGUAGE_SQLPP, function.getLanguage()); } String functionBody = function.getFunctionBody(); List<String> params = function.getArguments(); StringBuilder builder = new StringBuilder(); builder.append(" use " + function.getDataverseName() + ";"); builder.append(" declare function " + function.getName().split("@")[0]); builder.append("("); for (String param : params) { VarIdentifier varId = SqlppVariableUtil.toUserDefinedVariableName(param); builder.append(varId); builder.append(","); } if (params.size() > 0) { builder.delete(builder.length() - 1, builder.length()); } builder.append(")"); builder.append("{"); builder.append("\n"); builder.append(functionBody); builder.append("\n"); builder.append("};"); IParser parser = parserFactory.createParser(new StringReader(new String(builder))); List<Statement> statements = parser.parse(); FunctionDecl decl = (FunctionDecl) statements.get(1); return decl; }
public FunctionDecl getFunctionDecl(Function function) throws CompilationException { if (!function.getLanguage().equals(Function.LANGUAGE_AQL)) { throw new CompilationException(ErrorCode.COMPILATION_INCOMPATIBLE_FUNCTION_LANGUAGE, Function.LANGUAGE_AQL, function.getLanguage()); } String functionBody = function.getFunctionBody(); List<String> arguments = function.getArguments(); List<VarIdentifier> varIdentifiers = new ArrayList<VarIdentifier>(); StringBuilder builder = new StringBuilder(); builder.append(" use dataverse " + function.getDataverseName() + ";"); builder.append(" declare function " + function.getName().split("@")[0]); builder.append("("); boolean first = true; for (String argument : arguments) { VarIdentifier varId = new VarIdentifier(argument); varIdentifiers.add(varId); if (first) { first = false; } else { builder.append(","); } builder.append(argument); } builder.append("){\n").append(functionBody).append("\n}"); IParser parser = parserFactory.createParser(new CharSequenceReader(builder)); List<Statement> statements = parser.parse(); FunctionDecl decl = (FunctionDecl) statements.get(1); return decl; }
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)); if (functionDependency.get(0).equals(dataverseName)) { 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);
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.getName()); stringSerde.serialize(aString, tupleBuilder.getDataOutput()); tupleBuilder.addFieldEndOffset(); aString.setValue(function.getName()); stringSerde.serialize(aString, fieldValue.getDataOutput()); recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTIONNAME_FIELD_INDEX, fieldValue);