Flink 1.11 table案例

1,先来的简单点的,折腾了半天 昨天是maven下载不了flink-clients.jar ,下载之后手动导入,然后最简单的代码都运行不了

今天没办法,还是报错,缺包(org.apache.flink.optimizer.costs.CostEstimator),没法子,缺的包就是flink-clients.jar里面的,

再次尝试加入依赖,今天是成功了,代码就执行成功了。

官网中文文档地址:https://ci.apache.org/projects/flink/flink-docs-release-1.11/zh/dev/table/common.html#%E9%80%9A%E8%BF%87-dataset-%E6%88%96-datastream-%E5%88%9B%E5%BB%BA%E8%A7%86%E5%9B%BE

 


    org.apache.flink
    flink-table-api-java-bridge_${scala.binary.version}
    ${flink.version}


    org.apache.flink
    flink-table-api-scala-bridge_${scala.binary.version}
    ${flink.version}


    org.apache.flink
    flink-table-planner_${scala.binary.version}
    ${flink.version}


    org.apache.flink
    flink-table-planner-blink_${scala.binary.version}
    ${flink.version}



    org.apache.flink
    flink-streaming-scala_${scala.binary.version}
    ${flink.version}



    org.apache.flink
    flink-clients_${scala.binary.version}
    ${flink.version}
public class SqlTest03 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        EnvironmentSettings bsSettings = EnvironmentSettings.newInstance().useBlinkPlanner().inStreamingMode().build();
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env,bsSettings);

// ingest a DataStream from an external source
        DataStream> ds = env.addSource(new SourceFunction>() {
            @Override
            public void run(SourceContext> out) throws Exception {
                while (true){
                    out.collect(new Tuple3<>(1L,"a",11));
                    Thread.sleep(1000L);
                }
            }
            @Override
            public void cancel() {

            }
        });
        Table table = tableEnv.fromDataStream(ds, $("user"), $("product"), $("amount"));
        DataStream> dsRow = tableEnv.toRetractStream(table, Row.class);
        dsRow.print();
        env.execute();

    }
}

 顺便提一句关于 最后面的执行:

Flink 1.11 table案例_第1张图片

你可能感兴趣的:(Flink)