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