Search in sources :

Example 1 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class TwitterConverter method getNextTuple.

@Override
public Tuple getNextTuple() throws TexeraException {
    if (cursor == CLOSED) {
        throw new DataflowException(ErrorMessages.OPERATOR_NOT_OPENED);
    }
    Tuple tuple;
    while ((tuple = inputOperator.getNextTuple()) != null) {
        List<IField> tweetFields = generateFieldsFromJson(tuple.getField(rawDataAttribute).getValue().toString());
        if (!tweetFields.isEmpty()) {
            cursor++;
            List<IField> tupleFields = new ArrayList<>();
            final Tuple finalTuple = tuple;
            tupleFields.addAll(tuple.getSchema().getAttributeNames().stream().filter(attrName -> !attrName.equalsIgnoreCase(rawDataAttribute)).map(attrName -> finalTuple.getField(attrName, IField.class)).collect(Collectors.toList()));
            tupleFields.addAll(tweetFields);
            return new Tuple(outputSchema, tupleFields);
        }
    }
    return null;
}
Also used : DateTimeField(edu.uci.ics.texera.api.field.DateTimeField) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) Tuple(edu.uci.ics.texera.api.tuple.Tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ArrayList(java.util.ArrayList) List(java.util.List) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) IField(edu.uci.ics.texera.api.field.IField) TextField(edu.uci.ics.texera.api.field.TextField) StringField(edu.uci.ics.texera.api.field.StringField) DateTimeFormatter(java.time.format.DateTimeFormatter) ErrorMessages(edu.uci.ics.texera.api.constants.ErrorMessages) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) Schema(edu.uci.ics.texera.api.schema.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode) Attribute(edu.uci.ics.texera.api.schema.Attribute) IntegerField(edu.uci.ics.texera.api.field.IntegerField) AsterixSource(edu.uci.ics.texera.dataflow.source.asterix.AsterixSource) ArrayList(java.util.ArrayList) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 2 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class NltkSentimentOperator method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    if (inputOperator == null) {
        throw new DataflowException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
    }
    inputOperator.open();
    Schema inputSchema = inputOperator.getOutputSchema();
    // check if the input schema is presented
    if (!inputSchema.containsAttribute(predicate.getInputAttributeName())) {
        throw new TexeraException(String.format("input attribute %s is not in the input schema %s", predicate.getInputAttributeName(), inputSchema.getAttributeNames()));
    }
    // check if the attribute type is valid
    AttributeType inputAttributeType = inputSchema.getAttribute(predicate.getInputAttributeName()).getType();
    boolean isValidType = inputAttributeType.equals(AttributeType.STRING) || inputAttributeType.equals(AttributeType.TEXT);
    if (!isValidType) {
        throw new TexeraException(String.format("input attribute %s must have type String or Text, its actual type is %s", predicate.getInputAttributeName(), inputAttributeType));
    }
    // generate output schema by transforming the input schema
    outputSchema = transformSchema(inputOperator.getOutputSchema());
    cursor = OPENED;
}
Also used : AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Example 3 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class ProjectionOperator method setUp.

@Override
protected void setUp() throws TexeraException {
    inputSchema = inputOperator.getOutputSchema();
    List<Attribute> outputAttributes = inputSchema.getAttributes().stream().filter(attr -> predicate.getProjectionFields().contains(attr.getName().toLowerCase())).collect(Collectors.toList());
    if (outputAttributes.size() != predicate.getProjectionFields().size()) {
        throw new DataflowException("input schema doesn't contain one of the attributes to be projected");
    }
    outputSchema = new Schema(outputAttributes.stream().toArray(Attribute[]::new));
}
Also used : List(java.util.List) IField(edu.uci.ics.texera.api.field.IField) AbstractSingleInputOperator(edu.uci.ics.texera.dataflow.common.AbstractSingleInputOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) Schema(edu.uci.ics.texera.api.schema.Schema) Attribute(edu.uci.ics.texera.api.schema.Attribute) Collectors(java.util.stream.Collectors) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 4 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class JsonSchemaHelper method generateJsonSchema.

public static void generateJsonSchema(Class<? extends PredicateBase> predicateClass) throws Exception {
    if (!operatorTypeMap.containsKey(predicateClass)) {
        throw new TexeraException("predicate class " + predicateClass.toString() + " is not registerd in PredicateBase class");
    }
    // find the operatorType of the predicate class
    String operatorType = operatorTypeMap.get(predicateClass);
    // find the operator json schema path by its predicate class
    Path operatorSchemaPath = getJsonSchemaPath(predicateClass);
    // create the json schema file of the operator
    Files.deleteIfExists(operatorSchemaPath);
    Files.createFile(operatorSchemaPath);
    // generate the json schema
    JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(DataConstants.defaultObjectMapper);
    JsonSchema schema = jsonSchemaGenerator.generateSchema(predicateClass);
    ObjectNode schemaNode = objectMapper.readValue(objectMapper.writeValueAsBytes(schema), ObjectNode.class);
    LinkedHashSet<JsonNode> propertiesNodes = new LinkedHashSet<>();
    searchForEntity(schemaNode, "properties", propertiesNodes);
    for (JsonNode propertiesJsonNode : propertiesNodes) {
        ObjectNode propertiesNode = (ObjectNode) propertiesJsonNode;
        // remove the operatorID from the json schema
        propertiesNode.remove("operatorID");
        // process each property due to frontend form generator requirements
        propertiesNode.fields().forEachRemaining(e -> {
            String propertyName = e.getKey();
            ObjectNode propertyNode = (ObjectNode) e.getValue();
            // add a "title" field to each property
            propertyNode.put("title", propertyName);
            // if property is an enum, set unique items to true
            if (propertiesNode.has("enum")) {
                propertyNode.put("uniqueItems", true);
            }
        });
    }
    // add required/optional properties to the schema
    List<String> requiredProperties = getRequiredProperties(predicateClass);
    // because draft v4 doesn't allow it
    if (!requiredProperties.isEmpty()) {
        schemaNode.set("required", objectMapper.valueToTree(requiredProperties));
    }
    // add property default values to the schema
    Map<String, Object> defaultValues = getPropertyDefaultValues(predicateClass);
    for (String property : defaultValues.keySet()) {
        ObjectNode propertyNode = (ObjectNode) schemaNode.get("properties").get(property);
        propertyNode.set("default", objectMapper.convertValue(defaultValues.get(property), JsonNode.class));
    }
    // add the additionalMetadataNode
    ObjectNode additionalMetadataNode = objectMapper.createObjectNode();
    // add additional operator metadata to the additionalMetadataNode
    Map<String, Object> operatorMetadata = (Map<String, Object>) predicateClass.getMethod("getOperatorMetadata").invoke(null);
    for (String key : operatorMetadata.keySet()) {
        additionalMetadataNode.set(key, objectMapper.valueToTree(operatorMetadata.get(key)));
    }
    // add input and output arity to the schema
    additionalMetadataNode.put("numInputPorts", OperatorArityConstants.getFixedInputArity(predicateClass));
    additionalMetadataNode.put("numOutputPorts", OperatorArityConstants.getFixedOutputArity(predicateClass));
    // add advancedOption properties to the schema
    List<String> advancedOptionProperties = getAdvancedOptionProperties(predicateClass);
    additionalMetadataNode.set("advancedOptions", objectMapper.valueToTree(advancedOptionProperties));
    // setup the full metadata node, which contains the schema and additional metadata
    ObjectNode fullMetadataNode = objectMapper.createObjectNode();
    // add the operator type to the full node
    fullMetadataNode.put("operatorType", operatorType);
    fullMetadataNode.set("jsonSchema", schemaNode);
    fullMetadataNode.set("additionalMetadata", additionalMetadataNode);
    Files.write(operatorSchemaPath, objectMapper.writeValueAsBytes(fullMetadataNode));
    System.out.println("generating schema of " + operatorType + " completed");
    System.out.println(fullMetadataNode);
}
Also used : Path(java.nio.file.Path) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) JsonNode(com.fasterxml.jackson.databind.JsonNode) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) JsonSchemaGenerator(com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator)

Example 5 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class PlanStoreResource method updateQueryPlan.

@PUT
@Path("/{plan_name}")
public GenericWebResponse updateQueryPlan(@PathParam("plan_name") String planName, String queryPlanBeanJson) {
    try {
        QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
        // Updating the plan in the plan store
        planStore.updatePlan(planName, queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
    } catch (IOException | TexeraException 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)

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