flink入门

package com.gr.dologic
import java.util

import org.apache.flink.api.java.aggregation.Aggregations
import org.apache.flink.api.scala._
object flink1 {
  def main(args: Array[String]): Unit = {

    val env = ExecutionEnvironment.getExecutionEnvironment
    val list = new util.ArrayList[Int]();
    list.add(1);
    list.add(2);
    list.add(3);
    val stream = env.fromElements(1,2,3,4,3,4,3,3,5).map(arr=>{
      arr
    }).filter(_>=2).map{x=>(x,1)}.groupBy(0).aggregate(Aggregations.SUM,1)//.sum(1)
    stream.print
    // env.execute()
    /*Exception in thread "main" java.lang.RuntimeException: No new data sinks have been defined since the last execution.
    The last execution refers to the latest call to 'execute()', 'count()', 'collect()', or 'print()'.
    参照此文,原因是print()方法自动会调用execute()方法,造成错误,所以注释掉env.execute()即可*/

  }
}

//https://ci.apache.org/projects/flink/flink-docs-release-1.2/dev/table_api.html

/*  pom.xml



    4.0.0

    com.gr
    flink_demo
    1.0-SNAPSHOT


    
        org.apache.flink
        flink-scala_2.11
        1.6.0
    
    
        org.apache.flink
        flink-streaming-scala_2.11
        1.6.0
    
    
        org.apache.flink
        flink-clients_2.11
        1.6.0
    

*/

 

你可能感兴趣的:(flink入门)