RDD创建的两种方式

There are two ways to create RDDs: parallelizing an existing collection in your driver program, or referencing a dataset in an external storage system, such as a shared filesystem, HDFS, HBase, or any data source offering a Hadoop InputFormat.

第一种创建方式:并行化的方式
val data = Array(1, 2, 3, 4, 5)
val distData = sc.parallelize(data)

分为几个RDD和系统的核数是有关的核数越多效率越好。

Once created, the distributed dataset (distData) can beoperated on in parallel. For example, we might call distData.reduce((a, b) => a + b)to add up the elements of the array. We describe operations on distributed datasets later on.One important parameter for parallel collections is the number of partitions to cut the dataset into. Spark willrun one task for each partition of the cluster. Typically you want 2-4 partitions for each CPU in your cluster. Normally,Spark tries to set the number of partitions automatically based on your cluster. However, you can also set it manually by passing it as a second parameter to parallelize (e.g. sc.parallelize(data, 10)).Note: some places in the code use the term slices (a synonym for partitions) to maintain backward compatibility.

第二种创建方式:通过读取外部文件的方式(External Datasets)
scala> val distFile = sc.textFile("data.txt")
distFile: org.apache.spark.rdd.RDD[String] = data.txt MapPartitionsRDD[10] 

Spark can create distributed datasets from any storage source supported by Hadoop, including yourlocal file system, HDFS, Cassandra, HBase, Amazon S3, etc. Spark supports text files, SequenceFiles, and any other Hadoop InputFormat.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值