Rename ReaderUtils to ResultUtils and make some minor adjustments.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_result_distribution@1158 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
index 3a43461..ae70eb6 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
@@ -146,7 +146,8 @@
public enum DisplayFormat {
TEXT,
- HTML
+ HTML,
+ JSON
}
public static Pair<Query, Integer> reWriteQuery(List<FunctionDecl> declaredFunctions,
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
index 06defbd..9915f7c 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
@@ -18,9 +18,7 @@
import edu.uci.ics.asterix.aql.parser.AQLParser;
import edu.uci.ics.asterix.aql.parser.ParseException;
import edu.uci.ics.asterix.aql.translator.AqlTranslator;
-import edu.uci.ics.asterix.aql.translator.QueryResult;
import edu.uci.ics.asterix.metadata.MetadataManager;
-import edu.uci.ics.asterix.result.ResultReader;
import edu.uci.ics.hyracks.api.client.HyracksConnection;
import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
@@ -339,10 +337,9 @@
isSet(printOptimizedLogicalPlanParam), false, true, isSet(printJob));
MetadataManager.INSTANCE.init();
AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, out, sessionConfig, DisplayFormat.HTML);
- List<QueryResult> executionResults = null;
double duration = 0;
long startTime = System.currentTimeMillis();
- executionResults = aqlTranslator.compileAndExecute(hcc, false);
+ aqlTranslator.compileAndExecute(hcc, false);
long endTime = System.currentTimeMillis();
duration = (endTime - startTime) / 1000.00;
out.println("<PRE>Duration of all jobs: " + duration + "</PRE>");
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
index e1950f9..9416b0a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
@@ -26,7 +26,7 @@
import org.json.JSONArray;
import org.json.JSONObject;
-import edu.uci.ics.asterix.result.ReaderUtils;
+import edu.uci.ics.asterix.result.ResultUtils;
import edu.uci.ics.asterix.result.ResultReader;
import edu.uci.ics.asterix.runtime.formats.FormatUtils;
import edu.uci.ics.hyracks.api.client.HyracksConnection;
@@ -71,7 +71,7 @@
JSONObject jsonResponse = new JSONObject();
JSONArray results = new JSONArray();
while (resultReader.read(buffer) > 0) {
- results.put(ReaderUtils.getJSONFromBuffer(buffer, resultReader.getFrameTupleAccessor(),
+ results.put(ResultUtils.getJSONFromBuffer(buffer, resultReader.getFrameTupleAccessor(),
resultReader.getRecordDescriptor()));
}
jsonResponse.put("results", results);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
index 5781be2..e97275b 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
@@ -85,7 +85,7 @@
import edu.uci.ics.asterix.om.types.ATypeTag;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.types.TypeSignature;
-import edu.uci.ics.asterix.result.ReaderUtils;
+import edu.uci.ics.asterix.result.ResultUtils;
import edu.uci.ics.asterix.result.ResultReader;
import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionIDFactory;
@@ -298,7 +298,7 @@
buffer.clear();
JSONArray results = new JSONArray();
while (resultReader.read(buffer) > 0) {
- results.put(ReaderUtils.getJSONFromBuffer(buffer, resultReader.getFrameTupleAccessor(),
+ results.put(ResultUtils.getJSONFromBuffer(buffer, resultReader.getFrameTupleAccessor(),
resultReader.getRecordDescriptor()));
}
response.put("results", results);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ReaderUtils.java b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
similarity index 79%
rename from asterix-app/src/main/java/edu/uci/ics/asterix/result/ReaderUtils.java
rename to asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
index ccedc98..adb8573 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ReaderUtils.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
@@ -17,9 +17,9 @@
import java.io.DataInputStream;
import java.nio.ByteBuffer;
+import org.json.JSONArray;
import org.json.JSONException;
-
-import twitter4j.internal.org.json.JSONArray;
+import org.json.JSONObject;
import edu.uci.ics.asterix.om.base.IAObject;
import edu.uci.ics.hyracks.api.dataflow.value.RecordDescriptor;
@@ -27,7 +27,7 @@
import edu.uci.ics.hyracks.dataflow.common.comm.io.FrameTupleAccessor;
import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
-public class ReaderUtils {
+public class ResultUtils {
public static JSONArray getJSONFromBuffer(ByteBuffer buffer, FrameTupleAccessor fta,
RecordDescriptor recordDescriptor) throws HyracksDataException {
JSONArray resultRecords = new JSONArray();
@@ -52,4 +52,17 @@
}
return resultRecords;
}
+
+ public static JSONObject getErrorResponse(int errorCode, String errorMessage) {
+ JSONObject errorResp = new JSONObject();
+ JSONArray errorArray = new JSONArray();
+ errorArray.put(errorCode);
+ errorArray.put(errorMessage);
+ try {
+ errorResp.put("error-code", errorArray);
+ } catch (JSONException e) {
+ // TODO(madhusudancs): Figure out what to do when JSONException occurs while building the results.
+ }
+ return errorResp;
+ }
}