Pradeep Ramachandra
02/22/2023, 5:51 PMpublic class JoinJob {
// create environments of both APIs
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(new Configuration());
env.setParallelism(4);
env.setRuntimeMode(RuntimeExecutionMode.STREAMING);
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
tableEnv.createTemporaryView("user",TargetDataReader.convertSourceToTable(FILE_PATH_USER, env, tableEnv));
tableEnv.createTemporaryView("account",AccountReader.convertSourceToTable(FILE_PATH_ACCOUNT, env, tableEnv));
Table resultTable = tableEnv
.sqlQuery("select u.id, u.name, u.email, "
+ a.account_name as account_name, a.type as account_type"
+ from user u left join account a on u.id = a.user_id");
DataStream<Row> resultStream = tableEnv.toDataStream(resultTable);
resultStream.print();
env.execute("Executing flink test job");
}
- - code to read account information from CSV (also there is a similar class to read user information) - -
public class AccountReader {
public static Table convertSourceToTable(String path, StreamExecutionEnvironment env,
StreamTableEnvironment tableEnv) {
FileSource<String> accountSrc = FileSource.forRecordStreamFormat(
new TextLineInputFormat("UTF-8"),
new Path(path))
//monitors folder to read new files. Every second it checks if folder has more files to read
.monitorContinuously(Duration.ofSeconds(1))
.setSplitAssigner(FileSource.DEFAULT_SPLIT_ASSIGNER)
//This is to decide if we need to tell flink to split file and read in chunks. archived files are not splittable.
.setFileEnumerator((Provider) () -> new NonSplittingRecursiveEnumerator())
.build();
DataStream< Account2> accountStream = env.fromSource(accountSrc,
WatermarkStrategy.forMonotonousTimestamps(),
"Account as source")
.flatMap(new FlatMapFunction<String, Account2>() {
@Override
public void flatMap(String value, Collector<Account2> out) throws Exception {
String[] splittedString = value.split(",");
Account2 account = new Account2();
account.setType(Integer.parseInt(splittedString[0]));
account.setName(splittedString[1]);
account.setUserId(splittedString[2]);
out.collect(account);
}
});
return tableEnv.fromDataStream(accountStream).as("type", "account_name");
}
}
- - error - -
Exception in thread "main" org.apache.flink.table.api.TableException: Table sink '*anonymous_datastream_sink$4*' doesn't support consuming update and delete changes which is produced by node Join(joinType=[LeftOuterJoin], where=[(id = user_id)], select=[id, name, email], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
at org.apache.flink.table.planner.plan.optimize.program.FlinkChangelogModeInferenceProgram$SatisfyModifyKindSetTraitVisitor.createNewNode(FlinkChangelogModeInferenceProgram.scala:406)Martijn Visser
02/22/2023, 5:59 PMPradeep Ramachandra
02/22/2023, 6:01 PMMartijn Visser
02/22/2023, 6:02 PMMartijn Visser
02/22/2023, 6:03 PMPradeep Ramachandra
02/22/2023, 6:24 PMMartijn Visser
02/22/2023, 9:01 PMJames Watkins
06/07/2023, 10:40 PMJames Watkins
06/08/2023, 9:28 AM