CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 06:51:19 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=a7bc4b2f692b4f950464bcd929f7eeefbc986eefe862d1ca20a0a8aa1c76aaf8a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22vWQNmWlo7KPhUFyxJfMIWfGxzNmRWx-o%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cc6da2fbf73e92-BLR
BDOT LR4 - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sevsu.spark
- import java.nio.file.Paths
- import org.apache.spark.{SparkConf, SparkContext}
- import org.apache.spark.rdd.RDD
- object Application {
- private val conf: SparkConf = new SparkConf()
- .setMaster("local[*]")
- .setAppName("spark_example")
- .set("spark.ui.showConsoleProgress", "false")
- private val sc: SparkContext = getSparkContext(conf)
- private val resourcesRoot: String = this.getClass.getResource("/").toString
- private val personPath: String = resourcesRoot + "person.csv"
- private val apartmentPath: String = resourcesRoot + "apartment.csv"
- case class Person(id: Int, name: String)
- case class Apartment(id_apartment: Int, id_human: Int, num_rooms: Int, address: String)
- def main(args: Array[String]): Unit = {
- val rawPersonRdd: RDD[String] = sc.textFile(personPath)
- val rawApartmentRdd: RDD[String] = sc.textFile(apartmentPath)
- val persons = rawPersonRdd.map(strPerson => {
- strPerson.split(",").map(_.trim) match {
- case Array(id, name) => Person(id.toInt, name)
- }
- })
- val apartments = rawApartmentRdd.map(strPerson => {
- strPerson.split(",").map(_.trim) match {
- case Array(id_apartment, id_human, num_rooms, address) => Apartment(id_apartment.toInt, id_human.toInt, num_rooms.toInt, address)
- }
- })
- // ====== Task 1 ======
- val personCounter: RDD[(Int, Int)] = apartments.map(item => (item.id_human, 1))
- val numPersonApartments = personCounter.reduceByKey((a, b) => a + b)
- val numApartmentsPerson = numPersonApartments.map(_.swap).groupByKey().sortByKey()
- println(numApartmentsPerson.collect().mkString("\n"))
- // ====== Task 2 ======
- val personPairRDD = persons.map(item => (item.id, item.name))
- val joined = personPairRDD join numPersonApartments
- val numPersonNameApartments = joined.map(item => item._2)
- println(numPersonNameApartments.collect().mkString("\n"))
- // ====== Task 3 ======
- val personApartmentsAddress = apartments
- .filter(_.num_rooms > 2)
- .map(item =>
- (item.id_human, item.address)
- )
- val personNameAddressWithId = personApartmentsAddress join personPairRDD
- val personNameAddress = personNameAddressWithId.map(item => item._2)
- println(personNameAddress.collect().mkString("\n"))
- sc.stop()
- }
- private def getSparkContext(conf: SparkConf): SparkContext = {
- if (System.getProperty("os.name").toLowerCase.contains("windows")) {
- System.setProperty(
- "hadoop.home.dir",
- Paths.get(this.getClass.getResource("/winutils/hadoop-2.7.1/").toURI).toString
- )
- }
- new SparkContext(conf)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐⭐⭐Exploit 500$ in 15 Minutes⭐⭐
Java | 11 sec ago | 0.10 KB
-
⭐⭐⭐ G2A Payment Exploit ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 16 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 26 sec ago | 0.24 KB
-
⭐ ✅ Free Products Method ✅ ✅ NEVER SEEN BEFOR...
JavaScript | 36 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ M
JavaScript | 43 sec ago | 0.24 KB
-
⭐ G2A Bug ⭐ (Get more on BTC swaps) ✅ NEVER S...
JavaScript | 45 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ H
JavaScript | 54 sec ago | 0.24 KB
-
⭐✅ Jack's Profit Method ✅ NEVER SEEN BEF...
JavaScript | 54 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand