最近突然对spark的spark-shell发生了兴趣

它是如何启动scala的REPL的,并且在此前写入了常用的环境变量的呢?

通过查看spark的源码,找到了SparkILoop.scala

import scala.tools.nsc.interpreter.{JPrintWriter, ILoop}

/**
* A Spark-specific interactive shell.
*/
class SparkILoop(in0: Option[BufferedReader], out: JPrintWriter)
extends ILoop(in0, out) {
def this(in0: BufferedReader, out: JPrintWriter) = this(Some(in0), out)
def this() = this(None, new JPrintWriter(Console.out, true)) def initializeSpark() {
intp.beQuietDuring {
processLine("""
@transient val sc = {
val _sc = org.apache.spark.repl.Main.createSparkContext()
println("Spark context available as sc.")
_sc
}
""")
processLine("""
@transient val sqlContext = {
val _sqlContext = org.apache.spark.repl.Main.createSQLContext()
println("SQL context available as sqlContext.")
_sqlContext
}
""")
processLine("import org.apache.spark.SparkContext._")
processLine("import sqlContext.implicits._")
processLine("import sqlContext.sql")
processLine("import org.apache.spark.sql.functions._")
}
}
...
}

可以看出SparkILoop继承自scala.tools.nsc.interpreter.ILoop

紧接着着看了ILoop的api doc

终于找到了启动ILoop的方法:

import scala.tools.nsc.interpreter.ILoop
import scala.tools.nsc.Settings val loop = new ILoop
loop.process(new Settings)

scala的REPL shell的调用的更多相关文章

  1. shell脚本调用spark-sql

    为了更方便的查询并产生报表, 需要使用shell脚本调用spark-sql spark/bin/spark-sql --master spark://host:7077 -f ${SQL_FILE} ...

  2. shell脚本调用C语言之字符串切分之strtok函数

    今天上午在写一个需求,要求的比较急,要求当天完成,我大致分析了一下,可以采用从shell脚本中插入一连串的日期,通过调用proc生成的可执行文件,将日期传入后台数据库,在数据库中进行计算.需要切分日期 ...

  3. shell脚本调用C语言之字符串切分函数——strtok

    今天上午在写一个需求,要求的比较急,要求当天完成,我大致分析了一下,可以采用从shell脚本中插入一连串的日期,通过调用proc生成的可执行文件,将日期传入后台数据库,在数据库中进行计算.需要切分日期 ...

  4. shell中调用R语言并传入参数的两种步骤

    shell中调用R语言并传入参数的两种方法 第一种: Rscript myscript.R R脚本的输出 第二种: R CMD BATCH myscript.R # Check the output ...

  5. shell中调用jenkins API批量运行历史任务

    shell中调用jenkins API批量运行jenkins带参数的任务: #!/bin/sh #startdate=20150127 startdate=20150201 while [ " ...

  6. shell 获得调用的python脚本的print值和错误log

    1. shell 获得调用的python脚本的print值 python test.py > out.log 2.shell 获得调用的python脚本的错误log python test.py ...

  7. Shell脚本调用ftp上传文件

    Shell脚本调用ftp上传文件 1.脚本如下 ftp -n<<! open x.x.x.x ###x.x.x.x为ftp地址 user username password ###user ...

  8. Shell脚本调用SQL文格式

    Shell脚本调用SQL文格式 1. 定义需要执行的SQL文,以及需要输出文件 OUTFILE=\${DATADIR}/\${FILENAME} SQLFILE=\${DATADIR}/check_t ...

  9. Miniconda 安装 & Pip module 安装 & Shell 脚本调用 Miniconda 虚拟环境手册(实战项目应用)

    (实战项目应用) 1. 下载Miniconda 两个安装方式: 方式1:wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Min ...

随机推荐

  1. 使用X-UA-Compatible来设置IE兼容模式

    转自:http://www.cnblogs.com/libra/archive/2009/03/24/1420731.html 英文原文:http://msdn.microsoft.com/en-us ...

  2. 【转】SQL中Group By的使用

    1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By All 7.Group By与聚合函 ...

  3. Sort--快速排序

    快速排序 1 public class QuickSort{ 2 3 public static int Partition(int[] a,int low,int high){ 4 int pivo ...

  4. POJ3922 A simple stone game

    网上有很多解题报告,我的理解就是可以用类似数学归纳的方法证明,就是取一个数,让对手进入必败态. 详细见论文.

  5. HDU-4418 Time travel 概率DP,高斯消元

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4418 题意:简单来说就是给你1个环(n - 1 , n - 2 …… 0 ,1 , 2 , 3 …… ...

  6. decorview that was originally added here or java.lang.IllegalArgumentException: View not attached to window manager

    使用Dialog的时候,没少出现下面这两个报错 12-11 17:47:49.776: E/WindowManager(11461): android.view.WindowLeaked: Activ ...

  7. Java中的IP对象以及本地域名解析

    本地域名解析操作步骤: 1.打开C:\WINDOWS\system32\drivers\etc目录 2.找到host文件,用记事本打开 3.添加“空间IP  域名” package WebProgra ...

  8. 高效使用Bitmaps(三) 神奇的Cache

    转载:http://my.oschina.net/rengwuxian/blog/184650 应用的场景 假设你开发了一个聊天程序,它的好友列表中显示从网络获取的好友头像.可是如果用户发现每次进入好 ...

  9. Windows 窗体启动和关闭的事件顺序

    本文系转载学习. 对于关注对 Windows 窗体应用程序中引发的每个事件按次序进行处理的开发人员来说,事件引发的顺序特别重要.当某种情况需要小心处理事件时(如重绘窗体的某些部分时),必须知道事件在运 ...

  10. selenium 自动化测试面试题及答案

    写在开始: 这些问题和答案,都是自己在网上找的,整理的,有任何问题,概不负责.主要感谢博主Ray,http://www.cnblogs.com/tsbc/p/4922368.html 1.seleni ...