Search in sources :

Example 31 with TexeraException

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

the class TwitterFeedOperator method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    try {
        twitterConnector.getClient().connect();
        cursor = OPENED;
    } catch (Exception e) {
        throw new DataflowException(e.getMessage(), e);
    }
}
Also used : DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) IOException(java.io.IOException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 32 with TexeraException

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

the class TwitterUtils method getPlaceLocation.

/**
 * To track tweets inside a geoBox defined by a List</Location>.
 * The string defines the coordinates in the order of "latitude_SW, longitude_SW, latitude_NE, longitude_NE".
 *
 * @param inputLocation
 * @return
 * @throws TexeraException
 */
public static List<Location> getPlaceLocation(String inputLocation) throws TexeraException {
    List<Location> locationList = new ArrayList<>();
    if (inputLocation == null || inputLocation.isEmpty()) {
        return locationList;
    }
    List<String> boudingCoordinate = Arrays.asList(inputLocation.trim().split(","));
    if (boudingCoordinate.size() != 4 || boudingCoordinate.stream().anyMatch(s -> s.trim().isEmpty())) {
        throw new DataflowException("Please provide valid location coordinates");
    }
    List<Double> boundingBox = new ArrayList<>();
    boudingCoordinate.stream().forEach(s -> boundingBox.add(Double.parseDouble(s.trim())));
    locationList.add(new Location(new Coordinate(boundingBox.get(1), boundingBox.get(0)), new Coordinate(boundingBox.get(3), boundingBox.get(2))));
    return locationList;
}
Also used : Arrays(java.util.Arrays) Coordinate(com.twitter.hbc.core.endpoint.Location.Coordinate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) IOException(java.io.IOException) Location(com.twitter.hbc.core.endpoint.Location) ArrayList(java.util.ArrayList) List(java.util.List) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode) Attribute(edu.uci.ics.texera.api.schema.Attribute) Coordinate(com.twitter.hbc.core.endpoint.Location.Coordinate) ArrayList(java.util.ArrayList) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) Location(com.twitter.hbc.core.endpoint.Location)

Example 33 with TexeraException

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

the class WordCloudSink method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    if (inputOperator == null) {
        throw new TexeraException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
    }
    inputOperator.open();
    this.addPayload = !inputOperator.getOutputSchema().containsAttribute(SchemaConstants.PAYLOAD);
    Schema schema = inputOperator.getOutputSchema();
    Attribute textColumn = schema.getAttribute(predicate.getAttribute());
    AttributeType nameColumnType = textColumn.getType();
    if (!nameColumnType.equals(AttributeType.TEXT)) {
        throw new DataflowException("Type of name column should be text.");
    }
    outputSchema = new Schema.Builder().add(new Attribute("word", AttributeType.STRING), new Attribute("count", AttributeType.INTEGER)).build();
    cursor = OPENED;
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) 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 34 with TexeraException

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

the class FileSourceOperator method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    cursor = OPENED;
    try {
        List<String> columnNames = null;
        if (predicate.getFileFormat() != null && predicate.getFileFormat() == FileSourcePredicate.FileFormat.CSV_WITH_HEADER) {
            Optional<String> header = Files.lines(pathList.get(0)).findFirst();
            if (header.isPresent()) {
                columnNames = Arrays.stream(header.get().split(predicate.getColumnDelimiter())).collect(Collectors.toList());
            }
        }
        if (predicate.getColumnDelimiter() != null) {
            Optional<String> firstLine = Files.lines(pathList.get(0)).findFirst();
            if (firstLine.isPresent()) {
                columnNames = IntStream.range(0, firstLine.get().split(predicate.getColumnDelimiter()).length).map(i -> i + 1).mapToObj(i -> "c" + i).collect(Collectors.toList());
            }
        }
        if (columnNames == null) {
            columnNames = Collections.singletonList("c1");
        }
        List<Attribute> attributes = columnNames.stream().map(name -> new Attribute(name, AttributeType.TEXT)).collect(Collectors.toList());
        this.outputSchema = new Schema.Builder().add(SchemaConstants._ID_ATTRIBUTE).add(attributes).build();
    } catch (IOException e) {
        throw new DataflowException(e);
    }
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) Verify(com.google.common.base.Verify) Files(java.nio.file.Files) Tuple(edu.uci.ics.texera.api.tuple.Tuple) QueryContext(edu.uci.ics.texera.dataflow.plangen.QueryContext) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) FileManager(edu.uci.ics.texera.dataflow.resource.file.FileManager) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SchemaConstants(edu.uci.ics.texera.api.constants.SchemaConstants) IField(edu.uci.ics.texera.api.field.IField) TextField(edu.uci.ics.texera.api.field.TextField) Paths(java.nio.file.Paths) ErrorMessages(edu.uci.ics.texera.api.constants.ErrorMessages) ISourceOperator(edu.uci.ics.texera.api.dataflow.ISourceOperator) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) Attribute(edu.uci.ics.texera.api.schema.Attribute) IDField(edu.uci.ics.texera.api.field.IDField) Path(java.nio.file.Path) Attribute(edu.uci.ics.texera.api.schema.Attribute) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) IOException(java.io.IOException)

Example 35 with TexeraException

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

the class JSONSink method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    inputOperator.open();
    inputSchema = inputOperator.getOutputSchema();
    outputSchema = new Schema(inputSchema.getAttributes().stream().filter(attr -> !attr.getName().equalsIgnoreCase(SchemaConstants._ID)).filter(attr -> !attr.getName().equalsIgnoreCase(SchemaConstants.PAYLOAD)).toArray(Attribute[]::new));
    DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
    fileName = df.format(new Date()) + ".json";
    mapper = new ObjectMapper();
    File file = new File(jsonIndexDirectory.resolve(fileName).toString());
    try {
        if (Files.notExists(jsonIndexDirectory)) {
            Files.createDirectories(jsonIndexDirectory);
        }
        // creates json generator factory for writing to file
        jsonGenerator = mapper.getFactory().createGenerator(file, JsonEncoding.UTF8);
        jsonGenerator.writeStartArray();
    } catch (IOException e) {
        throw new DataflowException(e);
    }
    cursor = OPENED;
}
Also used : ListField(edu.uci.ics.texera.api.field.ListField) Date(java.util.Date) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) SimpleDateFormat(java.text.SimpleDateFormat) Span(edu.uci.ics.texera.api.span.Span) ArrayList(java.util.ArrayList) SchemaConstants(edu.uci.ics.texera.api.constants.SchemaConstants) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) IField(edu.uci.ics.texera.api.field.IField) JsonEncoding(com.fasterxml.jackson.core.JsonEncoding) ISink(edu.uci.ics.texera.api.dataflow.ISink) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) Schema(edu.uci.ics.texera.api.schema.Schema) Attribute(edu.uci.ics.texera.api.schema.Attribute) Path(java.nio.file.Path) DateFormat(java.text.DateFormat) IntegerField(edu.uci.ics.texera.api.field.IntegerField) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) File(java.io.File) DoubleField(edu.uci.ics.texera.api.field.DoubleField) DateField(edu.uci.ics.texera.api.field.DateField) List(java.util.List) Utils(edu.uci.ics.texera.api.utils.Utils) ErrorMessages(edu.uci.ics.texera.api.constants.ErrorMessages) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) 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