Search in sources :

Example 1 with DateTimeField

use of edu.uci.ics.texera.api.field.DateTimeField in project textdb by TextDB.

the class TwitterConverter method generateFieldsFromJson.

private List<IField> generateFieldsFromJson(String rawJsonData) {
    try {
        JsonNode tweet = new ObjectMapper().readTree(rawJsonData);
        String text = tweet.get("text").asText();
        Long id = tweet.get("id").asLong();
        String tweetLink = "https://twitter.com/statuses/" + id;
        JsonNode userNode = tweet.get("user");
        String userScreenName = userNode.get("screen_name").asText();
        String userLink = "https://twitter.com/" + userScreenName;
        String userName = userNode.get("name").asText();
        String userDescription = userNode.get("description").asText();
        Integer userFollowersCount = userNode.get("followers_count").asInt();
        Integer userFriendsCount = userNode.get("friends_count").asInt();
        JsonNode geoTagNode = tweet.get("geo_tag");
        String state = geoTagNode.get("stateName").asText();
        String county = geoTagNode.get("countyName").asText();
        String city = geoTagNode.get("cityName").asText();
        String createAt = tweet.get("create_at").asText();
        ZonedDateTime zonedCreateAt = ZonedDateTime.parse(createAt, DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
        return Arrays.asList(new StringField(id.toString()), new TextField(text), new StringField(tweetLink), new StringField(userLink), new TextField(userScreenName), new TextField(userName), new TextField(userDescription), new IntegerField(userFollowersCount), new IntegerField(userFriendsCount), new TextField(state), new TextField(county), new TextField(city), new DateTimeField(zonedCreateAt.toLocalDateTime()));
    } catch (Exception e) {
        return Arrays.asList();
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerField(edu.uci.ics.texera.api.field.IntegerField) DateTimeField(edu.uci.ics.texera.api.field.DateTimeField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 2 with DateTimeField

use of edu.uci.ics.texera.api.field.DateTimeField in project textdb by TextDB.

the class TestConstantsRegexSplit method constructSamplePeopleTuples.

public static List<Tuple> constructSamplePeopleTuples() {
    IField[] fields1 = { new StringField("bruce"), new StringField("john Lee"), new IntegerField(46), new DoubleField(5.50), new DateTimeField(LocalDateTime.parse("1970-01-01T11:11:11")), new TextField("banana") };
    IField[] fields2 = { new StringField("tom hanks"), new StringField("cruise"), new IntegerField(45), new DoubleField(5.95), new DateTimeField(LocalDateTime.parse("1980-01-02T13:14:15")), new TextField("mississippi") };
    Tuple tuple1 = new Tuple(SCHEMA_PEOPLE, fields1);
    Tuple tuple2 = new Tuple(SCHEMA_PEOPLE, fields2);
    return Arrays.asList(tuple1, tuple2);
}
Also used : StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) IntegerField(edu.uci.ics.texera.api.field.IntegerField) DateTimeField(edu.uci.ics.texera.api.field.DateTimeField) IField(edu.uci.ics.texera.api.field.IField) DoubleField(edu.uci.ics.texera.api.field.DoubleField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 3 with DateTimeField

use of edu.uci.ics.texera.api.field.DateTimeField in project textdb by TextDB.

the class TwitterJsonConverter method generateFieldsFromJson.

/**
 * Generates Fields from the raw JSON tweet.
 * Returns Optional.Empty() if something goes wrong while parsing this tweet.
 */
private Optional<List<IField>> generateFieldsFromJson(String rawJsonData) {
    try {
        // read the JSON string into a JSON object
        JsonNode tweet = new ObjectMapper().readTree(rawJsonData);
        // extract fields from the JSON object
        String text = tweet.get("text").asText();
        Long id = tweet.get("id").asLong();
        String tweetLink = "https://twitter.com/statuses/" + id;
        JsonNode userNode = tweet.get("user");
        String userScreenName = userNode.get("screen_name").asText();
        String userLink = "https://twitter.com/" + userScreenName;
        String userName = userNode.get("name").asText();
        String userDescription = userNode.get("description").asText();
        Integer userFollowersCount = userNode.get("followers_count").asInt();
        Integer userFriendsCount = userNode.get("friends_count").asInt();
        JsonNode geoTagNode = tweet.get("geo_tag");
        String state = geoTagNode.get("stateName").asText();
        String county = geoTagNode.get("countyName").asText();
        String city = geoTagNode.get("cityName").asText();
        String createAt = tweet.get("create_at").asText();
        ZonedDateTime zonedCreateAt = ZonedDateTime.parse(createAt, DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
        String isRetweet = tweet.get("is_retweet").asText();
        return Optional.of(Arrays.asList(new StringField(id.toString()), new TextField(text), new StringField(tweetLink), new StringField(userLink), new TextField(userScreenName), new TextField(userName), new TextField(userDescription), new IntegerField(userFollowersCount), new IntegerField(userFriendsCount), new TextField(state), new TextField(county), new TextField(city), new DateTimeField(zonedCreateAt.toLocalDateTime()), new StringField(isRetweet)));
    } catch (Exception e) {
        return Optional.empty();
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StringField(edu.uci.ics.texera.api.field.StringField) TextField(edu.uci.ics.texera.api.field.TextField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntegerField(edu.uci.ics.texera.api.field.IntegerField) DateTimeField(edu.uci.ics.texera.api.field.DateTimeField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Aggregations

DateTimeField (edu.uci.ics.texera.api.field.DateTimeField)3 IntegerField (edu.uci.ics.texera.api.field.IntegerField)3 StringField (edu.uci.ics.texera.api.field.StringField)3 TextField (edu.uci.ics.texera.api.field.TextField)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)2 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)2 ZonedDateTime (java.time.ZonedDateTime)2 DoubleField (edu.uci.ics.texera.api.field.DoubleField)1 IField (edu.uci.ics.texera.api.field.IField)1 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1