Search in sources :

Example 1 with TextDBException

use of edu.uci.ics.textdb.api.exception.TextDBException 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(jsonNode, resultJsonNode);
        return jsonNode;
    } catch (IOException e) {
        throw new TextDBException(e);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with TextDBException

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

the class ScanBasedSourceOperator method close.

@Override
public void close() throws TextDBException {
    if (!isOpen) {
        return;
    }
    try {
        dataReader.close();
        isOpen = false;
    } catch (Exception e) {
        throw new DataFlowException(e.getMessage(), e);
    }
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Example 3 with TextDBException

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

the class ExcelSink method open.

@Override
public void open() throws TextDBException {
    if (cursor != CLOSED) {
        return;
    }
    inputOperator.open();
    inputSchema = inputOperator.getOutputSchema();
    outputSchema = new Schema(inputSchema.getAttributes().stream().filter(attr -> !attr.getAttributeName().equalsIgnoreCase(SchemaConstants._ID)).filter(attr -> !attr.getAttributeName().equalsIgnoreCase(SchemaConstants.PAYLOAD)).filter(attr -> !attr.getAttributeType().equals(AttributeType.LIST)).toArray(Attribute[]::new));
    wb = new XSSFWorkbook();
    DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
    fileName = df.format(new Date()) + ".xlsx";
    try {
        if (Files.notExists(Paths.get(excelIndexDirectory))) {
            Files.createDirectories(Paths.get(excelIndexDirectory));
        }
        fileOut = new FileOutputStream(Paths.get(excelIndexDirectory, fileName).toString());
    } catch (IOException e) {
        throw new DataFlowException(e);
    }
    sheet = wb.createSheet("new sheet");
    Row row = sheet.createRow(0);
    List<String> attributeNames = outputSchema.getAttributeNames();
    for (int i = 0; i < attributeNames.size(); i++) {
        String attributeName = attributeNames.get(i);
        row.createCell(i).setCellValue(attributeName);
    }
    cursor = OPENED;
}
Also used : SchemaConstants(edu.uci.ics.textdb.api.constants.SchemaConstants) DoubleField(edu.uci.ics.textdb.api.field.DoubleField) DateField(edu.uci.ics.textdb.api.field.DateField) Date(java.util.Date) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) AttributeType(edu.uci.ics.textdb.api.schema.AttributeType) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) IntegerField(edu.uci.ics.textdb.api.field.IntegerField) ISink(edu.uci.ics.textdb.api.dataflow.ISink) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) Cell(org.apache.poi.ss.usermodel.Cell) DateFormat(java.text.DateFormat) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) IOperator(edu.uci.ics.textdb.api.dataflow.IOperator) Sheet(org.apache.poi.ss.usermodel.Sheet) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Utils(edu.uci.ics.textdb.api.utils.Utils) Schema(edu.uci.ics.textdb.api.schema.Schema) List(java.util.List) Workbook(org.apache.poi.ss.usermodel.Workbook) Paths(java.nio.file.Paths) IField(edu.uci.ics.textdb.api.field.IField) Row(org.apache.poi.ss.usermodel.Row) Schema(edu.uci.ics.textdb.api.schema.Schema) IOException(java.io.IOException) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Row(org.apache.poi.ss.usermodel.Row) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with TextDBException

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

the class FuzzyTokenMatcher method processOneInputTuple.

@Override
public Tuple processOneInputTuple(Tuple inputTuple) throws TextDBException {
    ListField<Span> payloadField = inputTuple.getField(SchemaConstants.PAYLOAD);
    List<Span> payload = payloadField.getValue();
    List<Span> relevantSpans = filterRelevantSpans(payload);
    List<Span> matchResults = new ArrayList<>();
    /*
         * The source operator returns spans even for those fields which did not
         * satisfy the threshold criterion. So if two attributes A,B have 10 and
         * 5 matching tokens, and we set threshold to 10, the number of spans
         * returned is 15. So we need to filter those 5 spans for attribute B.
         */
    for (String attributeName : this.predicate.getAttributeNames()) {
        AttributeType attributeType = this.inputSchema.getAttribute(attributeName).getAttributeType();
        // types other than TEXT and STRING: throw Exception for now
        if (attributeType != AttributeType.TEXT && attributeType != AttributeType.STRING) {
            throw new DataFlowException("FuzzyTokenMatcher: Fields other than TEXT or STRING are not supported");
        }
        List<Span> fieldSpans = relevantSpans.stream().filter(span -> span.getAttributeName().equals(attributeName)).filter(span -> predicate.getQueryTokens().contains(span.getKey())).collect(Collectors.toList());
        if (fieldSpans.size() >= predicate.getThreshold()) {
            matchResults.addAll(fieldSpans);
        }
    }
    if (matchResults.isEmpty()) {
        return null;
    }
    ListField<Span> spanListField = inputTuple.getField(predicate.getSpanListName());
    List<Span> spanList = spanListField.getValue();
    spanList.addAll(matchResults);
    return inputTuple;
}
Also used : SchemaConstants(edu.uci.ics.textdb.api.constants.SchemaConstants) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Iterator(java.util.Iterator) ErrorMessages(edu.uci.ics.textdb.api.constants.ErrorMessages) AbstractSingleInputOperator(edu.uci.ics.textdb.exp.common.AbstractSingleInputOperator) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Utils(edu.uci.ics.textdb.api.utils.Utils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AttributeType(edu.uci.ics.textdb.api.schema.AttributeType) Schema(edu.uci.ics.textdb.api.schema.Schema) List(java.util.List) ListField(edu.uci.ics.textdb.api.field.ListField) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) Span(edu.uci.ics.textdb.api.span.Span) DataflowUtils(edu.uci.ics.textdb.exp.utils.DataflowUtils) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) AttributeType(edu.uci.ics.textdb.api.schema.AttributeType) ArrayList(java.util.ArrayList) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Span(edu.uci.ics.textdb.api.span.Span)

Example 5 with TextDBException

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

the class Join method close.

@Override
public void close() throws TextDBException {
    if (cursor == CLOSED) {
        return;
    }
    try {
        innerOperator.close();
        outerOperator.close();
    } catch (Exception e) {
        throw new DataFlowException(e.getMessage(), e);
    }
    // Set the inner tuple list back to null on close.
    innerTupleList = null;
    innerTupleListCursor = 0;
    cursor = CLOSED;
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException)

Aggregations

TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)15 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)9 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)8 IOException (java.io.IOException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 TextdbWebException (edu.uci.ics.textdb.web.TextdbWebException)4 QueryPlanBean (edu.uci.ics.textdb.web.response.planstore.QueryPlanBean)4 StorageException (edu.uci.ics.textdb.api.exception.StorageException)3 Attribute (edu.uci.ics.textdb.api.schema.Attribute)3 Schema (edu.uci.ics.textdb.api.schema.Schema)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SchemaConstants (edu.uci.ics.textdb.api.constants.SchemaConstants)2 IField (edu.uci.ics.textdb.api.field.IField)2 AttributeType (edu.uci.ics.textdb.api.schema.AttributeType)2 Utils (edu.uci.ics.textdb.api.utils.Utils)2 AbstractSingleInputOperator (edu.uci.ics.textdb.exp.common.AbstractSingleInputOperator)2 TextdbWebResponse (edu.uci.ics.textdb.web.response.TextdbWebResponse)2 Collectors (java.util.stream.Collectors)2