import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import java.util.Arrays;
import java.util.List;
/**
* take(n)
* 将RDD中的前多少数据返回过来,返回结果为数据形式
*
*/
public class TakeOperator {
public static void main(String[] args){
SparkConf conf = new SparkConf().setMaster("local").setAppName("take");
JavaSparkContext sc = new JavaSparkContext(conf);
List<String> list = Arrays.asList("w1","w2","w3","w4","w5","w6");
JavaRDD<String> listRdd = sc.parallelize(list);
List<String> result = listRdd.take(3);
System.err.println(result.toString());
}
}
微信扫描下图二维码加入博主知识星球,获取更多大数据、人工智能、算法等免费学习资料哦!