fewer copies
Change-Id: Ia409bf61140816c8246ab79c11732654613b20bf
Reviewed-on: https://asterix-gerrit.ics.uci.edu/823
Reviewed-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java
index 96086a1..1f58d08 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java
@@ -19,7 +19,6 @@
package org.apache.asterix.lang.aql.parser;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +29,7 @@
import org.apache.asterix.lang.common.statement.FunctionDecl;
import org.apache.asterix.lang.common.struct.VarIdentifier;
import org.apache.asterix.metadata.entities.Function;
+import org.apache.commons.io.input.CharSequenceReader;
public class FunctionParser {
@@ -48,23 +48,20 @@
builder.append(" use dataverse " + function.getDataverseName() + ";");
builder.append(" declare function " + function.getName().split("@")[0]);
builder.append("(");
+ boolean first = true;
for (String param : params) {
VarIdentifier varId = new VarIdentifier(param);
varIdentifiers.add(varId);
+ if (first) {
+ first = false;
+ } else {
+ builder.append(",");
+ }
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("}");
+ builder.append("){\n").append(functionBody).append("\n}");
- IParser parser = parserFactory.createParser(new StringReader(new String(builder)));
+ IParser parser = parserFactory.createParser(new CharSequenceReader(builder));
List<Statement> statements = parser.parse();
FunctionDecl decl = (FunctionDecl) statements.get(1);
return decl;