我第一次使用flink(1.6,1.7),并使用来自https://www.gharchive.org/的github档案中的数据,但将这些数据用作流数据源。
我的简单示例仅计算每个用户每天的所有事件,而我尝试复制相同的示例,但改用TableEnvironment和SQL支持。
但是,我遇到以下错误:
org.apache.flink.streaming.api.functions.source.TimestampedFileInputSplit类不包含用于字段ModifyTime的设置器,如下所示:
8-12-04 14:17:02:115 INFO main exploration.StreamingTableApp:32 - Starting Streaming Table Flink App Example...
18-12-04 14:17:02:174 INFO main typeutils.TypeExtractor:1818 - class org.apache.flink.streaming.api.functions.source.TimestampedFileInputSplit does not contain a setter for field modificationTime
18-12-04 14:17:02:176 INFO main typeutils.TypeExtractor:1857 - Class class org.apache.flink.streaming.api.functions.source.TimestampedFileInputSplit cannot be used as a POJO type because not all fields are valid POJO fields, and must be processed as GenericType. Please read the Flink documentation on "Data Types & Serialization" for details of the effect on performance.
18-12-04 14:17:02:937 INFO main exploration.StreamingTableApp:74 - Finished...
我正在读取CSV源作为数据流,并使用Gson解析出json行的位并将这些属性映射到元组。
有人对此有任何想法/经验吗?
主要方法:
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
// Mapped in docker compose file too.
DataStreamSource<String> input = env.readTextFile("/some/path/github/");
// Setup the stream
DataStream<Tuple4<String, Integer, String, Long>> stream = input.map(new GithubTupleConverter())
.assignTimestampsAndWatermarks(new TupleTimestampExtractor());
StreamTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env);
Table tableFromStream = tEnv.fromDataStream(stream, "user_id, kount, basic_date,event_date");
TupleTimestampExtractor
public class TupleTimestampExtractor
extends BoundedOutOfOrdernessTimestampExtractor<Tuple4<String, Integer, String, Long>> {
private static final long serialVersionUID = 3737675541965835242L;
public TupleTimestampExtractor() {
super(Time.seconds(30L));
}
@Override
public long extractTimestamp(Tuple4<String, Integer, String, Long> element) {
return element.getField(3);
}
}
GithubTupleConverter.java
public class GithubTupleConverter implements MapFunction<String, Tuple4<String, Integer, String, Long>> {
private static final Gson g = new Gson();
@Override
public Tuple4<String, Integer, String, Long> map(String value) throws Exception {
// Take each line as Json.
JsonObject o = g.fromJson(value, JsonObject.class);
// Extract the user id
String userId = o.get("actor").getAsJsonObject().get("login").getAsString();
// Extract the event type (commit, pull request, fork event)
String type = o.get("type").getAsString();
// Get the event date time
String dateTime = o.get("created_at").getAsString();
// Parse date string to Typed type.
LocalDateTime eventTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ISO_DATE_TIME);
// Format the date so it can be used in the output.
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;
return Tuple4.of(userId, 1, formatter.format(eventTime), eventTime.toInstant(ZoneOffset.UTC).toEpochMilli());
}
}
答案 0 :(得分:0)
您共享的日志不会显示错误。日志处于INFO
级别,不会引发异常(至少不在提供的日志中)。
日志条目仅表明类TimestampedFileInputSplit
不能被视为POJO。通常,此消息表明性能不是最佳的,但是在这种特定情况下,这不是问题。
您还收到其他任何错误消息吗?