use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class EmojiSentimentOperator 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 input schema is present
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 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 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 PlanStore method addPlan.
/**
* Adds a Logical Plan JSON to the plan store.
*
* @param planName, the name of the plan.
* @param description, the description of the plan.
* @param logicalPlanJson, the logical plan JSON string
* @Return IDField, the id field of the plan stored.
* @throws TexeraException, when there are null fields or the given name is invalid or there is an existing plan with same name.
*/
public IDField addPlan(String planName, String description, String logicalPlanJson) throws TexeraException {
if (planName == null || description == null || logicalPlanJson == null) {
throw new TexeraException("Arguments cannot be null when adding a plan");
}
if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
throw new TexeraException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
}
if (getPlan(planName) != null) {
throw new TexeraException("A plan with the same name already exists");
}
try {
// Converting the JSON String to a JSON Node to minimize space usage and to check validity of JSON string
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
} catch (IOException e) {
throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
}
Tuple tuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), new StringField(description), new StringField(logicalPlanJson));
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
IDField id = dataWriter.insertTuple(tuple);
dataWriter.close();
return id;
}
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 AbstractSingleInputOperator method open.
@Override
public void open() throws TexeraException {
if (cursor != CLOSED) {
return;
}
try {
if (this.inputOperator == null) {
throw new DataflowException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
}
inputOperator.open();
setUp();
} catch (Exception e) {
throw new DataflowException(e.getMessage(), e);
}
cursor = OPENED;
}
Aggregations