>>提君博客原创  http://www.cnblogs.com/tijun/  <<

提君博客原创

1.进入命令窗口

./bin/spark-shell

附上帮助指令,查看一些帮助信息

scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
:edit <id>|<line> edit history
:help [command] print this summary or command-specific help
:history [num] show the history (optional num is commands to show)
:h? <string> search the history
:imports [name name ...] show import history, identifying sources of names
:implicits [-v] show the implicits in scope
:javap <path|class> disassemble a file or class name
:line <id>|<line> place line(s) at the end of history
:load <path> interpret lines in a file
:paste [-raw] [path] enter paste mode or paste a file
:power enable power user mode
:quit exit the interpreter
:replay [options] reset the repl and replay all previous commands
:require <path> add a jar to the classpath
:reset [options] reset the repl to its initial state, forgetting all session entries
:save <path> save replayable session to a file
:sh <command line> run a shell command (result is implicitly => List[String])
:settings <options> update compiler options, if possible; see reset
:silent disable/enable automatic printing of results
:type [-v] <expr> display the type of an expression without evaluating it
:kind [-v] <expr> display the kind of expression's type
:warnings show the suppressed warnings from the most recent line which had any

2.使用spark加载文件,创建Dataset

scala> val textFile = spark.read.textFile("hdfs://cluster1/input/README.txt")
textFile: org.apache.spark.sql.Dataset[String] = [value: string]

3.使用sc加载文件,创建RDD

scala> val textFile=sc.textFile("hdfs://cluster1/input/README.txt")
textFile: org.apache.spark.rdd.RDD[String] = hdfs://cluster1/input/README.txt MapPartitionsRDD[1] at textFile at <console>:24

4.统计textFile里面有多少行(item)

提君博客原创

scala> textFile.count()    // Number of items in this Dataset
res0: Long =

5.查看第一个iterm

scala> textFile.first()   // First item in this Dataset
res1: String = For the latest information about Hadoop, please visit our website at:

上面都挺简单,下面来一个完整的wordcount

>>提君博客原创  http://www.cnblogs.com/tijun/  <<

6.wordcount

scala> val wordsRdd=textFile.flatMap(line=>line.split(" "))
wordsRdd: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[] at flatMap at <console>: scala> val kvsRdd=wordsRdd.map(word=>(word,))
kvsRdd: org.apache.spark.rdd.RDD[(String, Int)] = MapPartitionsRDD[] at map at <console>: scala> val countRdd=kvsRdd.reduceByKey(_+_)
countRdd: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[] at reduceByKey at <console>: scala> countRdd.collect()
res2: Array[(String, Int)] = Array((under,), (this,), (distribution,), (Technology,), (country,), (is,), (Jetty,), (currently,), (permitted.,), (check,), (have,), (Security,), (U.S.,), (with,), (BIS,), (This,), (mortbay.org.,), ((ECCN),), (using,), (security,), (Department,), (export,), (reside,), (any,), (algorithms.,), (from,), (re-export,), (has,), (SSL,), (Industry,), (Administration,), (details,), (provides,), (http://hadoop.apache.org/core/,1), (country's,1), (Unrestricted,1), (740.13),1), (policies,1), (country,,1), (concerning,1), (uses,1), (Apache,1), (possession,,2), (information,2), (our,2), (as,1), ("",18), (Bureau,1), (wiki,,1), (please,2), (form,1), (information.,1), (ENC,1), (Export,2), (included,1), (asymmetric,1), (Commodity,1), (For,1),...

本篇先暂时写到这里,后续再继续完善。

提君博客原创

>>提君博客原创  http://www.cnblogs.com/tijun/  <<

spark-shell简单使用介绍(scala)的更多相关文章

  1. Spark Shell简单使用

    基础 Spark的shell作为一个强大的交互式数据分析工具,提供了一个简单的方式学习API.它可以使用Scala(在Java虚拟机上运行现有的Java库的一个很好方式)或Python.在Spark目 ...

  2. Spark学习进度-Spark环境搭建&Spark shell

    Spark环境搭建 下载包 所需Spark包:我选择的是2.2.0的对应Hadoop2.7版本的,下载地址:https://archive.apache.org/dist/spark/spark-2. ...

  3. 在Scala IDEA for Eclipse或IDEA里程序编译实现与在Spark Shell下的对比(其实就是那么一回事)

    不多说,直接上干货! 比如,我这里拿主成分分析(PCA). 1.主成分分析(PCA)的概念介绍 主成分分析(PCA) 是一种对数据进行旋转变换的统计学方法,其本质是在线性空间中进行一个基变换,使得变换 ...

  4. 01 . Shell详细入门介绍及简单应用

    Shell简介 Shell 是一个 C 语言编写的脚本语言,它是用户与 Linux 的桥梁,用户输入命令交给 Shell 解释处理Shell 将相应的操作传递给内核(Kernel),内核把处理的结果输 ...

  5. Spark源码分析之Spark Shell(上)

    终于开始看Spark源码了,先从最常用的spark-shell脚本开始吧.不要觉得一个启动脚本有什么东东,其实里面还是有很多知识点的.另外,从启动脚本入手,是寻找代码入口最简单的方法,很多开源框架,其 ...

  6. 1. Spark的安装及介绍

    *以下内容由<Spark快速大数据分析>整理所得. 读书笔记的第一部分是记录如何安装Spark?同时,简单介绍下Spark. 一.Spark安装 二.Spark介绍 一.Spark安装 如 ...

  7. 02、体验Spark shell下RDD编程

    02.体验Spark shell下RDD编程 1.Spark RDD介绍 RDD是Resilient Distributed Dataset,中文翻译是弹性分布式数据集.该类是Spark是核心类成员之 ...

  8. Spark集群 + Akka + Kafka + Scala 开发(2) : 开发一个Spark应用

    前言 在Spark集群 + Akka + Kafka + Scala 开发(1) : 配置开发环境,我们已经部署好了一个Spark的开发环境. 本文的目标是写一个Spark应用,并可以在集群中测试. ...

  9. Spark集群 + Akka + Kafka + Scala 开发(1) : 配置开发环境

    目标 配置一个spark standalone集群 + akka + kafka + scala的开发环境. 创建一个基于spark的scala工程,并在spark standalone的集群环境中运 ...

随机推荐

  1. Python之TabError: inconsistent use of tabs and spaces in indentation和ModuleNotFoundError:No module named 'win32api'

    1.TabError: inconsistent use of tabs and spaces in indentation 这是我的代码,感觉没啥不对, 后来运行之后出现了下面的错误,我也是弄了好久 ...

  2. P1217 [USACO1.5]回文质数 Prime Palindromes(技巧+暴力枚举+线性筛)

    技巧:就是偶数位的回文数字一定不是质数---------证明:奇数位之和sum1==偶数位之和sum2的数字可以被11整除.(11除外,这是一个坑点) 最高位,最低位必须是 1, 3, 7, 9 暴力 ...

  3. Python:Day16 闭包、装饰器

    def outer(): x = 10 def inner(): #条件一.inner就是一个内部函数 print(x) #条件二.引用外部作用域的一个变量,因为x在函数外部的,所以是外部作用域的变量 ...

  4. Python IDLE 增加清屏功能

    (Python2,Python3 通用) 保存如下代码到 ClearWindow.py """ Clear Window Extension Version: 0.2 A ...

  5. Java NIO2:NIO概述

    一.概述 从JDK1.4开始,Java提供了一系列改进的输入/输出处理的新特性,被统称为NIO(即New I/O).新增了许多用于处理输入输出的类,这些类都被放在java.nio包及子包下,并且对原j ...

  6. 十二省联考 - JLOI2019 游记

    十二省联考 - JLOI 2019 游记 想了想,还是起一个副标题吧 一场失败的胜利 Day -inf 想了想,还是从头开始说吧. 其实考完NOIP之后,大概估算一下,吉林省队的数量还算是比较乐观的, ...

  7. MySQL常用SQL语句/函数/存储过程

    一句话总结 SELECT count(*) FROM user WHERE id>0 GROUP BY name HAVING count(*)>1 ORDER BY count(*)DE ...

  8. C#使用ILGenerator动态生成函数

    游戏服务器里面总是有一大堆的配置文件需要读取, 而且这些配置文件的读取: * 要不然做成弱类型的, 就是一堆字符串或者数字, 不能看出来错误(需要重新检测一次) * 要不然做成强类型的, 每种类型都需 ...

  9. docker创建nginx+php-fpm+mysql环境(一分钟搭建lnmp)

    下载镜像 docker pull bitnami/php-fpm #下载php-fpm镜像 docker pull nginx #下载nginx镜像docker pull mysql:5.5.59 # ...

  10. 海康威视笔试(C++)

    1. select和epoll的区别 2.服务器并发量之高性能服务器设计 3.SQL关键字 4.TCP乱序和重传的问题 5.c++对象内存分配问题 6.c++多线程 join的用法: Thread类的 ...