use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class PlanStoreResource method addQueryPlan.
@POST
public GenericWebResponse addQueryPlan(String queryPlanBeanJson) {
try {
QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
// Adding the query plan to the PlanStore
planStore.addPlan(queryPlanBean.getName(), queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
} catch (TexeraException e) {
throw new TexeraWebException(e.getMessage());
} catch (IOException e) {
throw new TexeraWebException(e.getMessage());
}
return new GenericWebResponse(0, "Success");
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class UserDFOperator method computeNextMatchingTuple.
/**
* Input Buffer layout:
* ----------------------------------------
* | | | |
* | Texera PID | Input Tag | JSON string |
* | | | |
* ----------------------------------------
* Output Buffer layout:
* -----------------------------------------
* | | | |
* | Python PID | Output Tag | JSON string |
* | | | |
* -----------------------------------------
*
* There are tags which are put into the buffer between Process PID and main content.
* Input tag (Put by Texera):
* TAG_NULL= "": input NULL. All input lines have been exhausted.
* TAG_LEN = length of text
* Output tag (Put by Python script):
* TAG_NULL= "": result NULL
* TAG_WAIT= Character.unsigned: need to wait for next
* TAG_LEN = length of text
*
* 1. Whenever computeNextMatchingTuple is called, the UDF operator first puts one of the tags (Null/Length of text) into the buffer
* 2. After that the actual input tuple to the UDF operator (if one exists) is input into the buffer.
* 3. Python script is signalled and UDF operator begins to poll on 'getPythonResult' flag.
* 4. The python process processes the tuple and puts its output into the output buffer. It then signals Texera.
* 5. After being signalled, Texera fetches the contents of output buffer and checks its tag.
* a. If the Tag is TAG_WAIT, it means that the python process needs more tuples to complete its job. Therefore, UDF operator
* fetches next tuple and puts it in the input buffer and notifies Python process again.
* b. If the Tag is TAG_NULL, it means that the Python process has output nothing. This happens typically when the Python process
* has gone through all the tuples and is fed TAG_NULL by Texera.
* Upon receiving TAG_NULL, Texera destroys Python process and returns NULL to the output operator.
* c. If the Tag is a length, then buffer is read till Unsigned Character is found. This read portion forms the output tuple.
*/
@Override
protected Tuple computeNextMatchingTuple() throws TexeraException {
try {
Tuple inputTuple = inputOperator.getNextTuple();
// write attribute content to input mmap buffer
if (inputTuple == null) {
putTagIntoInputBuffer(predicate.TAG_NULL);
} else {
String inputTupleText = new ObjectMapper().writeValueAsString(inputTuple);
putTagIntoInputBuffer(String.valueOf((new ObjectMapper().writeValueAsString(inputTuple)).length()));
putJsonIntoInputBuffer(inputTupleText);
}
notifyPython(pythonPID.trim());
for (; ; ) {
Thread.sleep(200);
if (getPythonResult) {
getPythonResult = false;
break;
}
}
// Output from buffer
String strLenTag = getTagFromOutputBuffer();
if (strLenTag == predicate.TAG_WAIT) {
this.getNextTuple();
}
if (strLenTag == predicate.TAG_NULL) {
processPython.destroy();
return null;
}
String outputTupleJsonStr = getJsonFromOutputBuffer();
outputTuple = new ObjectMapper().readValue(outputTupleJsonStr.trim(), Tuple.class);
outputSchema = outputTuple.getSchema();
} catch (Exception e) {
throw new TexeraException("MMap Operation Failed!");
}
return outputTuple;
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class TestUtils method testJsonSerialization.
public static JsonNode testJsonSerialization(Object object, boolean printResults) {
try {
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(object);
Object resultObject = objectMapper.readValue(json, object.getClass());
String resultJson = objectMapper.writeValueAsString(resultObject);
JsonNode jsonNode = objectMapper.readValue(json, JsonNode.class);
JsonNode resultJsonNode = objectMapper.readValue(resultJson, JsonNode.class);
if (printResults) {
System.out.println(resultJson);
}
Assert.assertEquals(object, resultObject);
Assert.assertEquals(jsonNode, resultJsonNode);
return jsonNode;
} catch (IOException e) {
throw new TexeraException(e);
}
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class PlanStoreTest method assertPlanEquivalence.
/**
* This function checks whether the two given logical plan JSON strings are equivalent
* @param plan1 - The first Logical Plan JSON
* @param plan2 - The second Logical Plan JSON
*/
public static void assertPlanEquivalence(String plan1, String plan2) {
Assert.assertNotNull(plan1);
Assert.assertNotNull(plan2);
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode1 = objectMapper.readValue(plan1, JsonNode.class);
JsonNode jsonNode2 = objectMapper.readValue(plan2, JsonNode.class);
Assert.assertEquals(jsonNode1, jsonNode2);
} catch (IOException e) {
throw new TexeraException(e);
}
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class ScanBasedSourceOperator method open.
@Override
public void open() throws TexeraException {
if (isOpen) {
return;
}
try {
dataReader.open();
isOpen = true;
} catch (Exception e) {
throw new DataflowException(e.getMessage(), e);
}
}
Aggregations