Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fields to the TwitterStatus object #54

Open
Cam-Cam opened this issue May 25, 2018 · 1 comment
Open

Add fields to the TwitterStatus object #54

Cam-Cam opened this issue May 25, 2018 · 1 comment

Comments

@Cam-Cam
Copy link

Cam-Cam commented May 25, 2018

Hello,
Thank you for this code, I successfully connected to twitter and received Avro format messages.
I am trying to add to the TweeterStatus information about the original tweet so I added these bold lines to the object TwitterStatus.

`Object TwitterStatus {
def asIso8601String(d:Date) = {
val tz = TimeZone.getTimeZone("UTC")
val df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
df.setTimeZone(tz)
df.format(if (d == null) { new Date() } else { d })
}

def struct(s: twitter4j.Status) =
new Struct(schema)
.put("id", s.getId)
.put("created_at", asIso8601String(s.getCreatedAt))
.put("user", TwitterUser.struct(s.getUser))
.put("text", s.getText)
.put("lang", s.getLang)
.put("is_retweet", s.isRetweet)
.put("retweeted_status", new Struct(schema)
.put("original_tweet_id", s.getRetweetedStatus.getId)
.put("original_user_id", s.getRetweetedStatus.getUser.getId))

.put("entities", Entities.struct(s))

val schema = SchemaBuilder.struct().name("com.eneco.trading.kafka.connect.twitter.Tweet")
.field("id", Schema.INT64_SCHEMA)
.field("created_at", Schema.OPTIONAL_STRING_SCHEMA)
.field("user", TwitterUser.schema)
.field("text", Schema.OPTIONAL_STRING_SCHEMA)
.field("lang", Schema.OPTIONAL_STRING_SCHEMA)
.field("is_retweet", Schema.BOOLEAN_SCHEMA)
.field("retweeted_status",
SchemaBuilder.struct.name("retweeted_status")
.field("original_tweet_id", Schema.OPTIONAL_INT64_SCHEMA).optional()
.field("original_user_id", Schema.OPTIONAL_INT64_SCHEMA).optional().build())

.field("entities", Entities.schema)
.build()
}`

Unfortunately, after various tries I still get an error of NullPointerException.

Would you have any tips about adding information to your schema?

Thanks a lot.

@Cam-Cam
Copy link
Author

Cam-Cam commented May 29, 2018

Never mind, my bad, I forgot to test that "is_retweet" was true.
It works well now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant