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;
}
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;
}
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));
}
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);
}
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");
}
Aggregations