Skip to content

Commit 8b9d00b

Browse files
Scala spark
1 parent 39b46cd commit 8b9d00b

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

hadoop/edw/cloudera/spark/spark_demo_scala.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ dataRDD.map(x => (x.split(",")(0), x.split(",")(1))).saveAsSequenceFile("/user/c
5858
import org.apache.hadoop.mapreduce.lib.output._
5959

6060
val path="/user/cloudera/scalaspark/departmentsSeq"
61-
dataRDD.map(x => (new Text(x.split(",")(0)), new Text(x.split(",")(1)))).saveAsNewAPIHadoopFile(path, classOf(Text), classOf(Text), classOf(SequenceFileOutputFormat(Text, Text)))
61+
dataRDD.map(x => (new Text(x.split(",")(0)), new Text(x.split(",")(1)))).saveAsNewAPIHadoopFile(path, classOf[Text], classOf[Text], classOf[SequenceFileOutputFormat[Text, Text]])
6262

6363
#reading sequence file
64-
sc.sequenceFile("/user/cloudera/spark/departmentsSeq", classOf(IntWritable), classOf(Text)).map(rec => rec.toString()).collect().foreach(println)
64+
sc.sequenceFile("/user/cloudera/spark/departmentsSeq", classOf[IntWritable], classOf[Text]).map(rec => rec.toString()).collect().foreach(println)
6565

6666
import org.apache.spark.sql.hive.HiveContext
6767
val sqlContext = new HiveContext(sc)
@@ -526,12 +526,6 @@ def getTopDenseN(rec: (String, Iterable[String]), topN: Int): Iterable[String] =
526526

527527
productsMap.groupByKey().flatMap(x => getTopDenseN(x, 2)).collect().foreach(println)
528528

529-
530-
productsFlatMap = products.flatMap(lambda rec: (rec.split(",")[1], float(rec.split(",")[4])))
531-
for i in productsMap.groupByKey().flatMap(lambda x: getFirstTwo(x)).collect(): print(i)
532-
for i in productsMap.groupByKey().flatMap(lambda x: getAllSortByPrice(x, True)).collect(): print(i)
533-
for i in productsMap.groupByKey().flatMap(getTop).collect(): print(i)
534-
535529
#Sorting using queries
536530
#Global sorting and ranking
537531
select * from products order by product_price desc;

0 commit comments

Comments
 (0)