7.spring篇-@Aspect切面

Can‘t find mysqld.sock: Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.s

  返回  

Spark之takeOrdered,取前几个数据

2021/8/20 18:22:33 浏览:

takeOrdered 案例

package com.sgg.sparkCore

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

object SparkTrans012_takeOrdered {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("s")
    val sc = new SparkContext(conf)
    sc.setLogLevel("WARN")

    //TODO 算子  -- takeOrdered
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))

    // Int 类型的RDD
    val ints: Array[Int] = rdd.takeOrdered(3)(ord = Ordering[Int])

    println(ints.mkString(","))

    // String 类型的RDD
    val rdd1: RDD[String] = sc.makeRDD(List("hello", "world", "spark", "scala", "netty", "by"))

    val strings: Array[String] = rdd1.takeOrdered(3)(ord = Ordering[String].reverse)

    println(strings.mkString(","))

    sc.stop()
  }
}

打印结果:

1,2,3
world,spark,scala

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号