Windows下IntelliJ IDEA中運行Spark Standalone

來源:互聯網
上載者:User

標籤:

 ZHUAN 

http://www.cnblogs.com/one--way/archive/2016/08/29/5818989.html

http://www.cnblogs.com/one--way/p/5814148.html

前提條件:

1、Spark Standalone 叢集部署完成

2、Intellij Idea 能夠運行 Spark local 模式的程式。 

 

源碼:

 1 import org.apache.spark.{SparkContext, SparkConf} 2 import scala.math._ 3  4 /** 5   * Created by Edward on 2016/8/27. 6   */ 7 object WordCount { 8   def main(args: Array[String]) { 9 10     val sparkConf = new SparkConf().setAppName("WordCount")11       .setMaster("spark://node1:7077").setJars(List("D:\\documents\\Spark\\MyDemo\\Test\\out\\artifacts\\spark_sample_jar\\Test.jar"))12     //val sc = new SparkContext(sparkConf)13     val spark = new SparkContext(sparkConf)14     val slices = if (args.length > 0) args(0).toInt else 215     val n = math.min(100000L * slices, Int.MaxValue).toInt // avoid overflow16     val count = spark.parallelize(1 until n, slices).map { i =>17         val x = random * 2 - 118         val y = random * 2 - 119         if (x*x + y*y < 1) 1 else 020       }.reduce(_ + _)21     println("Pi is roughly " + 4.0 * count / n)22     spark.stop()23   }24 }

這裡主要的思想還是將打包的jar提交到叢集。

使用.setJars方法

 

Windows下IntelliJ IDEA中運行Spark Standalone

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.