예제 #1
0
  public static FunctionDecl getFunctionDecl(Function function) throws AsterixException {
    String functionBody = function.getFunctionBody();
    List<String> params = function.getParams();
    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("(");
    for (String param : params) {
      VarIdentifier varId = new VarIdentifier(param);
      varIdentifiers.add(varId);
      builder.append(param);
      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("}");

    AQLParser parser = new AQLParser(new StringReader(new String(builder)));

    List<Statement> statements = parser.parse();
    FunctionDecl decl = (FunctionDecl) statements.get(1);
    return decl;
  }
예제 #2
0
 public static void executeAQL(String aql) throws Exception {
   AQLParser parser = new AQLParser(new StringReader(aql));
   List<Statement> statements;
   statements = parser.Statement();
   SessionConfig pc = new SessionConfig(out, OutputFormat.ADM);
   AqlTranslator translator = new AqlTranslator(statements, pc);
   translator.compileAndExecute(
       AsterixAppContextInfo.getInstance().getHcc(), null, AqlTranslator.ResultDelivery.SYNC);
 }