• spark学习三


    今天完成了实验二的最后两个实验,由于对Scala语言并不了解,不知道如何进行文件读取,后来通过上网查询,找到了相关代码,

    spark中partition的概念
    partition是RDD的最小单元,是盛放文件的盒子,一个文件可能需要多个partition,但是一个partition只能
    存放一个文件中的内容,partition是spark计算中,生成的数据在计算空间内最小单元。

    用于根据文件类型的输入源常见RDD的方法叫textFile()方法。
     
    textFile().cache()中cache()是用于将一个RDD进行缓存,在之后的使用过程中就不需要重新计算,可以大大节省程序运行时间。
    persist()也是用于将RDD进行缓存,它还可以根据情况设置缓存级别。

    2.模拟图形绘制

    case class Point(var x:Double,var y:Double)extends Drawable

      {

          def shift(deltaX:Double,deltaY:Double)

          {

             x+=deltaX;

              y+=deltaY

          }

      }

      trait Drawable

     {

         def draw(){println(this.toString)}

     }

     abstract class Shape(var location:Point)//location是Shape的一个可变字段

     {

         def moveTo(newLocation:Point)     {

             location=newLocation

         }

         def zoom(scale:Double)

     }

     class Line(beginPoint:Point,var endPoint:Point)extends Shape(beginPoint)with Drawable

     {

         override def draw()

         {

             println(s"Line:(${location.x},${location.y})--(${endPoint.x},${endPoint.y})")     }

        

         override def moveTo(newLocation:Point)

         {

             endPoint.shift(newLocation.x-location.x,newLocation.y-location.y)         location=newLocation

         }

        

         override def zoom(scale:Double)

         {

             val midPoint=Point((endPoint.x+location.x)/2,(endPoint.y+location.y)/2)         location.x=midPoint.x+scale*(location.x-midPoint.x)

             location.y=midPoint.y+scale*(location.y-midPoint.y)

             endPoint.x=midPoint.x+scale*(endPoint.x-midPoint.x)

             endPoint.y=midPoint.y+scale*(endPoint.y-midPoint.y)

         }

     }

     class Circle(center:Point,var radius:Double)extends Shape(center)with Drawable

     {

         override def draw()

         {

             println(s"Circle center:(${location.x},${location.y}),R=$radius")

         }

        

         override def zoom(scale:Double)

         {

             radius=radius*scale      }

     }

     object MyDraw

     {

         def main(args:Array[String])

         {

             val p=new Point(10,30)

             p.draw

            

             val line1=new Line(Point(0,0),Point(20,20))

             line1.draw

             line1.moveTo(Point(5,5))

             line1.draw

             line1.zoom(2)

             line1.draw

            

             val cir=new Circle(Point(10,10),5)

             cir.draw

             cir.moveTo(Point(30,20))

             cir.draw

             cir.zoom(0.5)

             cir.draw   

        }

        

     }

    3. 统计学生成绩

  • 相关阅读:
    区间dp_学习笔记
    状态压缩dp_学习笔记
    第十一届蓝桥杯C/C++ J题网络分析(带权并查集水题)
    状态机dp学习笔记_AcWing
    洛谷P4052 [JSOI2007]文本生成器(AC自动机+DP)
    洛谷P5840 [COCI2015]Divljak (AC自动机+fail树上dfs序+树上差分线段树维护)
    洛谷P3401 [USACO12JAN]Video Game G(AC自动机+记忆化搜索)
    HDU3613 Best Reward (exKMP/manacher)
    洛谷P2375 [NOI2014]动物园(KMP+倍增优化)
    ICPC2017南宁站题解(A,E,F,H,I,J,L,M)
  • 原文地址:https://www.cnblogs.com/zhang12345/p/12252953.html
Copyright © 2020-2023  润新知