zoukankan      html  css  js  c++  java
  • Flink开发环境搭建(maven)

    1、下载scala sdk

    http://www.scala-lang.org/download/ 直接到这里下载sdk,(https://downloads.lightbend.com/scala/2.12.8/scala-2.12.8.msi)

    2、下载scala for intellij idea的插件

    File->setting->plugins里搜索Scala,然后安装即可

    3、https://maven.apache.org/download.cgi

    http://mirrors.shu.edu.cn/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.zip

    4、生成工程

    mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-scala

    或者

    mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeCatalog=https://repository.apache.org/content/repositories/snapshots/ -DarchetypeVersion=1.7-SNAPSHOT

    5、scala统计词频示例

    package com.test.s
    
    import org.apache.flink.api.scala._
    
    object WordCount {
    
      def main(args: Array[String]) {
    
        val env = ExecutionEnvironment.getExecutionEnvironment
    
        // get input data
        val text = env.readTextFile("D:\git\test\pom.xml")
    
        val counts = text.flatMap { _.toLowerCase.split("\W+") filter { _.nonEmpty } }
          .map { (_, 1) }
          .groupBy(0)
          .sum(1)
    
        // counts.writeAsCsv("D:\git\test\output.txt", "
    ", " ")
        counts.print()
        env.execute("Socket Window WordCount")
    
      }
    }
    • 直接按照样例执行,可能出现以下错误:
    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()即可
  • 相关阅读:
    [TJOI2013]循环格
    [CQOI2017]小Q的表格
    【51nod 1514】 美妙的序列
    【bzoj3456】 城市规划
    [SHOI2010]最小生成树
    CF438E The Child and Binary Tree
    bzoj 4712: 洪水
    POJ-3069 Saruman's Army---区间选点
    POJ-3617 Best Cow Line---字符串贪心
    HDU-1850 Being a Good Boy in Spring Festival---尼姆博奕的运用
  • 原文地址:https://www.cnblogs.com/linn/p/10454921.html
Copyright © 2011-2022 走看看