flink 多表join的例子
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,今天写了一个稍微复杂的例子, 实现了类似mysql group_concat 功能,记录一下MapToString 参考bug 那篇博客public static void main(String[]
千家信息网最后更新 2026年11月03日flink 多表join的例子
今天写了一个稍微复杂的例子, 实现了类似mysql group_concat 功能,记录一下
MapToString 参考bug 那篇博客
public static void main(String[] arg) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tableEnv = new BatchTableEnvironment(env, TableConfig.DEFAULT()); tableEnv.registerFunction("mapToString", new MapToString()); getProjectInfo(env,tableEnv); getProject(env,tableEnv); joinTableProjectWithInfo(tableEnv); Table query = tableEnv.sqlQuery("select id, name, type from result_agg"); DataSet ds= tableEnv.toDataSet(query, Row.class); ds.print(); ds.writeAsText("/home/test", WriteMode.OVERWRITE); env.execute("multiple-table"); } public static void getProjectInfo(ExecutionEnvironment env,BatchTableEnvironment tableEnv) { TypeInformation[] fieldTypes = new TypeInformation[] { BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO }; String[] fieldNames = new String[] { "id", "type" }; RowTypeInfo rowTypeInfo = new RowTypeInfo(fieldTypes, fieldNames); JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat().setDrivername("com.mysql.jdbc.Driver") .setDBUrl("jdbc:mysql://ip:3306/space?characterEncoding=utf8") .setUsername("user").setPassword("pwd") .setQuery("select project_fid, cast(project_info_type as CHAR) as type from project").setRowTypeInfo(rowTypeInfo).finish(); DataSource s = env.createInput(jdbcInputFormat); tableEnv.registerDataSet("project_info", s); aggProjectInfo(tableEnv,"project_info"); } public static void aggProjectInfo(BatchTableEnvironment tableEnv, String tableName) { Table tapiResult = tableEnv.scan(tableName); tapiResult.printSchema(); Table query = tableEnv.sqlQuery("select id, mapToString(collect(type)) as type from project_info group by id"); tableEnv.registerTable(tableName+"_agg", query); tapiResult = tableEnv.scan(tableName+"_agg"); tapiResult.printSchema(); } public static void getProject(ExecutionEnvironment env,BatchTableEnvironment tableEnv) { TypeInformation[] fieldTypes = new TypeInformation[] { BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO }; String[] fieldNames = new String[] { "pid", "name" }; RowTypeInfo rowTypeInfo = new RowTypeInfo(fieldTypes, fieldNames); JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat().setDrivername("com.mysql.jdbc.Driver") .setDBUrl("jdbc:mysql://ip:3306/space?characterEncoding=utf8") .setUsername("user").setPassword("pwd") .setQuery("select fid, project_name from t_project").setRowTypeInfo(rowTypeInfo).finish(); DataSource s = env.createInput(jdbcInputFormat); tableEnv.registerDataSet("project", s); } public static void joinTableProjectWithInfo(BatchTableEnvironment tableEnv) { Table result =tableEnv.sqlQuery("select a.pid as id , a.name , b.type from project a inner join project_info_agg b on a.pid=b.id"); tableEnv.registerTable("result_agg", result); result.printSchema(); }
例子
复杂
功能
博客
参考
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
圆梦互联网科技
互联网为科技
狮子座互联网科技
紫鲸互联网科技
唐信互联网科技
广州互联网络科技有限公司
互联网金融和金融科技
互联网科技生活的内容
互联网科技公司的市场部门
新华互联网科技2019
欧洲十大科技互联网公司
互联网校园科技培训
国大互联网教育科技有限公司工作
银行科技岗属于互联网吗
从那以后互联网科技有限公司
国产互联网科技公司
互联网科技企业商标注意事项
西安左小互联网科技有限公司
恒生互联网科技趋势
互联网 科技节活动 微视频大赛
江苏根荣互联网科技
互联网科技与金融科技
高科技与互联网
互联网科技小贷
广州善班互联网科技
互联网 新科技
居家互联网科技有限公司
深圳市优智互联网科技有限公司
东莞新华互联网科技学校
西安小鹰速贷互联网科技有限公司