Search in sources :

Example 26 with TexeraException

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");
}
Also used : IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) GenericWebResponse(edu.uci.ics.texera.web.response.GenericWebResponse) QueryPlanBean(edu.uci.ics.texera.web.response.planstore.QueryPlanBean) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 27 with TexeraException

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;
}
Also used : TexeraException(edu.uci.ics.texera.api.exception.TexeraException) Tuple(edu.uci.ics.texera.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 28 with TexeraException

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);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with TexeraException

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);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 30 with TexeraException

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);
    }
}
Also used : DataflowException(edu.uci.ics.texera.api.exception.DataflowException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) StorageException(edu.uci.ics.texera.api.exception.StorageException)

Aggregations

TexeraException (edu.uci.ics.texera.api.exception.TexeraException)46 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)27 Schema (edu.uci.ics.texera.api.schema.Schema)20 IOException (java.io.IOException)20 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)17 Tuple (edu.uci.ics.texera.api.tuple.Tuple)17 Attribute (edu.uci.ics.texera.api.schema.Attribute)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ErrorMessages (edu.uci.ics.texera.api.constants.ErrorMessages)9 IField (edu.uci.ics.texera.api.field.IField)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)7 Collectors (java.util.stream.Collectors)7 SchemaConstants (edu.uci.ics.texera.api.constants.SchemaConstants)6 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)6 ISink (edu.uci.ics.texera.api.dataflow.ISink)5 IntegerField (edu.uci.ics.texera.api.field.IntegerField)4 LogicalPlan (edu.uci.ics.texera.dataflow.plangen.LogicalPlan)4