亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

flink 多表join的例子

發布時間:2020-07-09 15:10:54 來源:網絡 閱讀:1197 作者:大海之中 欄目:大數據

今天寫了一個稍微復雜的例子, 實現了類似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<Row> 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<Row> 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<Row> 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();
    }
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

焦作市| 临汾市| 阿合奇县| 台江县| 共和县| 弋阳县| 铅山县| 西和县| 黄石市| 贵南县| 公主岭市| 昂仁县| 龙泉市| 酒泉市| 七台河市| 陇西县| 历史| 平潭县| 昌邑市| 桓台县| 浦北县| 西峡县| 炎陵县| 博爱县| 聊城市| 昌乐县| 宜丰县| 松江区| 滦平县| 旬邑县| 景德镇市| 和龙市| 都江堰市| 凤冈县| 建平县| 吴忠市| 株洲市| 莎车县| 吉安县| 安龙县| 沙田区|