@Override public Void visit(CreateFunctionStatement cfs, Integer step) throws CompilationException { out.print(skip(step) + CREATE + " function "); out.print(generateIfNotExists(cfs.getIfNotExists())); out.print( this.generateFullName(cfs.getFunctionSignature().getNamespace(), cfs.getFunctionSignature().getName())); out.print("("); printDelimitedStrings(cfs.getParamList(), COMMA); out.println(") {"); out.println(cfs.getFunctionBody()); out.println("}" + SEMICOLON); out.println(); return null; }
protected void handleCreateFunctionStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception { CreateFunctionStatement cfs = (CreateFunctionStatement) stmt; SourceLocation sourceLoc = cfs.getSourceLocation(); FunctionSignature signature = cfs.getFunctionSignature(); String dataverse = getActiveDataverseName(signature.getNamespace()); signature.setNamespace(dataverse); Query wrappedQuery = new Query(false); wrappedQuery.setSourceLocation(sourceLoc); wrappedQuery.setBody(cfs.getFunctionBodyExpression()); wrappedQuery.setTopLevel(false); List<VarIdentifier> paramVars = new ArrayList<>(); for (String v : cfs.getParamList()) { paramVars.add(new VarIdentifier(v)); rewriterFactory.createQueryRewriter(), cfs.getFunctionBodyExpression(), metadataProvider); Function function = new Function(signature, cfs.getParamList(), Function.RETURNTYPE_VOID, cfs.getFunctionBody(), getFunctionLanguage(), FunctionKind.SCALAR.toString(), dependencies); MetadataManager.INSTANCE.addFunction(mdTxnCtx, function);
final public CreateFunctionStatement FunctionSpecification() throws ParseException, ParseException { FunctionSignature signature; boolean ifNotExists = false; List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); String functionBody; VarIdentifier var = null; Expression functionBodyExpr; Token beginPos; Token endPos; FunctionName fctName = null; createNewScope(); jj_consume_token(FUNCTION); fctName = FunctionName(); ifNotExists = IfNotExists(); paramList = ParameterList(); jj_consume_token(LEFTBRACE); beginPos = token; functionBodyExpr = Expression(); jj_consume_token(RIGHTBRACE); endPos = token; functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); // TODO use fctName.library signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size()); getCurrentScope().addFunctionDescriptor(signature, false); removeCurrentScope(); {if (true) return new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);} throw new Error("Missing return statement in function"); }
final public CreateFunctionStatement FunctionSpecification() throws ParseException, ParseException { FunctionSignature signature; boolean ifNotExists = false; List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); String functionBody; VarIdentifier var = null; Expression functionBodyExpr; Token beginPos; Token endPos; FunctionName fctName = null; createNewScope(); jj_consume_token(FUNCTION); fctName = FunctionName(); ifNotExists = IfNotExists(); paramList = ParameterList(); jj_consume_token(LEFTBRACE); beginPos = token; functionBodyExpr = Expression(); jj_consume_token(RIGHTBRACE); endPos = token; functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); // TODO use fctName.library signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size()); getCurrentScope().addFunctionDescriptor(signature, false); removeCurrentScope(); {if (true) return new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);} throw new Error("Missing return statement in function"); }
removeCurrentScope(); defaultDataverse = currentDataverse; CreateFunctionStatement stmt = new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists); {if (true) return addSourceLocation(stmt, startStmtToken);} throw new Error("Missing return statement in function");