public class SparkContext
extends Object
implements org.apache.spark.internal.Logging
SparkContext
should be active per JVM. You must stop()
the
active SparkContext
before creating a new one.
param: config a Spark Config object describing the application configuration. Any settings in
this config overrides the default configs as well as system properties.Constructor and Description |
---|
SparkContext()
Create a SparkContext that loads settings from system properties (for instance, when
launching with ./bin/spark-submit).
|
SparkContext(SparkConf config) |
SparkContext(String master,
String appName,
SparkConf conf)
Alternative constructor that allows setting common Spark properties directly
|
SparkContext(String master,
String appName,
String sparkHome,
scala.collection.Seq<String> jars,
scala.collection.Map<String,String> environment)
Alternative constructor that allows setting common Spark properties directly
|
Modifier and Type | Method and Description |
---|---|
void |
addArchive(String path)
:: Experimental ::
Add an archive to be downloaded and unpacked with this Spark job on every node.
|
void |
addFile(String path)
Add a file to be downloaded with this Spark job on every node.
|
void |
addFile(String path,
boolean recursive)
Add a file to be downloaded with this Spark job on every node.
|
void |
addJar(String path)
Adds a JAR dependency for all tasks to be executed on this
SparkContext in the future. |
void |
addJobTag(String tag)
Add a tag to be assigned to all the jobs started by this thread.
|
void |
addSparkListener(SparkListenerInterface listener)
:: DeveloperApi ::
Register a listener to receive up-calls from events that happen during execution.
|
scala.Option<String> |
applicationAttemptId() |
String |
applicationId()
A unique identifier for the Spark application.
|
String |
appName() |
scala.collection.Seq<String> |
archives() |
RDD<scala.Tuple2<String,PortableDataStream>> |
binaryFiles(String path,
int minPartitions)
Get an RDD for a Hadoop-readable dataset as PortableDataStream for each file
(useful for binary data)
|
RDD<byte[]> |
binaryRecords(String path,
int recordLength,
org.apache.hadoop.conf.Configuration conf)
Load data from a flat binary file, assuming the length of each record is constant.
|
<T> Broadcast<T> |
broadcast(T value,
scala.reflect.ClassTag<T> evidence$9)
Broadcast a read-only variable to the cluster, returning a
Broadcast object for reading it in distributed functions. |
void |
cancelAllJobs()
Cancel all jobs that have been scheduled or are running.
|
void |
cancelJob(int jobId)
Cancel a given job if it's scheduled or running.
|
void |
cancelJob(int jobId,
String reason)
Cancel a given job if it's scheduled or running.
|
void |
cancelJobGroup(String groupId)
Cancel active jobs for the specified group.
|
void |
cancelJobsWithTag(String tag)
Cancel active jobs that have the specified tag.
|
void |
cancelStage(int stageId)
Cancel a given stage and all jobs associated with it.
|
void |
cancelStage(int stageId,
String reason)
Cancel a given stage and all jobs associated with it.
|
void |
clearCallSite()
Clear the thread-local property for overriding the call sites
of actions and RDDs.
|
void |
clearJobGroup()
Clear the current thread's job group ID and its description.
|
void |
clearJobTags()
Clear the current thread's job tags.
|
<T> CollectionAccumulator<T> |
collectionAccumulator()
Create and register a
CollectionAccumulator , which starts with empty list and accumulates
inputs by adding them into the list. |
<T> CollectionAccumulator<T> |
collectionAccumulator(String name)
Create and register a
CollectionAccumulator , which starts with empty list and accumulates
inputs by adding them into the list. |
int |
defaultMinPartitions()
Default min number of partitions for Hadoop RDDs when not given by user
Notice that we use math.min so the "defaultMinPartitions" cannot be higher than 2.
|
int |
defaultParallelism()
Default level of parallelism to use when not given by user (e.g.
|
String |
deployMode() |
DoubleAccumulator |
doubleAccumulator()
Create and register a double accumulator, which starts with 0 and accumulates inputs by
add . |
DoubleAccumulator |
doubleAccumulator(String name)
Create and register a double accumulator, which starts with 0 and accumulates inputs by
add . |
<T> RDD<T> |
emptyRDD(scala.reflect.ClassTag<T> evidence$8)
Get an RDD that has no partitions or elements.
|
scala.collection.Seq<String> |
files() |
scala.collection.Seq<Schedulable> |
getAllPools()
:: DeveloperApi ::
Return pools for fair scheduler
|
scala.Option<String> |
getCheckpointDir() |
SparkConf |
getConf()
Return a copy of this SparkContext's configuration.
|
scala.collection.Map<String,scala.Tuple2<Object,Object>> |
getExecutorMemoryStatus()
Return a map from the block manager to the max memory available for caching and the remaining
memory available for caching.
|
scala.collection.immutable.Set<String> |
getJobTags()
Get the tags that are currently set to be assigned to all the jobs started by this thread.
|
String |
getLocalProperty(String key)
Get a local property set in this thread, or null if it is missing.
|
static SparkContext |
getOrCreate()
This function may be used to get or instantiate a SparkContext and register it as a
singleton object.
|
static SparkContext |
getOrCreate(SparkConf config)
This function may be used to get or instantiate a SparkContext and register it as a
singleton object.
|
scala.collection.Map<Object,RDD<?>> |
getPersistentRDDs()
Returns an immutable map of RDDs that have marked themselves as persistent via cache() call.
|
scala.Option<Schedulable> |
getPoolForName(String pool)
:: DeveloperApi ::
Return the pool associated with the given name, if one exists
|
RDDInfo[] |
getRDDStorageInfo()
:: DeveloperApi ::
Return information about what RDDs are cached, if they are in mem or on disk, how much space
they take, etc.
|
scala.Enumeration.Value |
getSchedulingMode()
Return current scheduling mode
|
org.apache.hadoop.conf.Configuration |
hadoopConfiguration()
A default Hadoop Configuration for the Hadoop code (e.g.
|
<K,V> RDD<scala.Tuple2<K,V>> |
hadoopFile(String path,
Class<? extends org.apache.hadoop.mapred.InputFormat<K,V>> inputFormatClass,
Class<K> keyClass,
Class<V> valueClass,
int minPartitions)
Get an RDD for a Hadoop file with an arbitrary InputFormat
|
<K,V,F extends org.apache.hadoop.mapred.InputFormat<K,V>> |
hadoopFile(String path,
scala.reflect.ClassTag<K> km,
scala.reflect.ClassTag<V> vm,
scala.reflect.ClassTag<F> fm)
Smarter version of hadoopFile() that uses class tags to figure out the classes of keys,
values and the InputFormat so that users don't need to pass them directly.
|
<K,V,F extends org.apache.hadoop.mapred.InputFormat<K,V>> |
hadoopFile(String path,
int minPartitions,
scala.reflect.ClassTag<K> km,
scala.reflect.ClassTag<V> vm,
scala.reflect.ClassTag<F> fm)
Smarter version of hadoopFile() that uses class tags to figure out the classes of keys,
values and the InputFormat so that users don't need to pass them directly.
|
<K,V> RDD<scala.Tuple2<K,V>> |
hadoopRDD(org.apache.hadoop.mapred.JobConf conf,
Class<? extends org.apache.hadoop.mapred.InputFormat<K,V>> inputFormatClass,
Class<K> keyClass,
Class<V> valueClass,
int minPartitions)
Get an RDD for a Hadoop-readable dataset from a Hadoop JobConf given its InputFormat and other
necessary info (e.g.
|
boolean |
isLocal() |
boolean |
isStopped() |
static scala.Option<String> |
jarOfClass(Class<?> cls)
Find the JAR from which a given class was loaded, to make it easy for users to pass
their JARs to SparkContext.
|
static scala.Option<String> |
jarOfObject(Object obj)
Find the JAR that contains the class of a particular object, to make it easy for users
to pass their JARs to SparkContext.
|
scala.collection.Seq<String> |
jars() |
boolean |
killExecutor(String executorId)
:: DeveloperApi ::
Request that the cluster manager kill the specified executor.
|
boolean |
killExecutors(scala.collection.Seq<String> executorIds)
:: DeveloperApi ::
Request that the cluster manager kill the specified executors.
|
boolean |
killTaskAttempt(long taskId,
boolean interruptThread,
String reason)
Kill and reschedule the given task attempt.
|
scala.collection.Seq<String> |
listArchives()
:: Experimental ::
Returns a list of archive paths that are added to resources.
|
scala.collection.Seq<String> |
listFiles()
Returns a list of file paths that are added to resources.
|
scala.collection.Seq<String> |
listJars()
Returns a list of jar files that are added to resources.
|
LongAccumulator |
longAccumulator()
Create and register a long accumulator, which starts with 0 and accumulates inputs by
add . |
LongAccumulator |
longAccumulator(String name)
Create and register a long accumulator, which starts with 0 and accumulates inputs by
add . |
<T> RDD<T> |
makeRDD(scala.collection.Seq<T> seq,
int numSlices,
scala.reflect.ClassTag<T> evidence$2)
Distribute a local Scala collection to form an RDD.
|
<T> RDD<T> |
makeRDD(scala.collection.Seq<scala.Tuple2<T,scala.collection.Seq<String>>> seq,
scala.reflect.ClassTag<T> evidence$3)
Distribute a local Scala collection to form an RDD, with one or more
location preferences (hostnames of Spark nodes) for each object.
|
String |
master() |
<K,V,F extends org.apache.hadoop.mapreduce.InputFormat<K,V>> |
newAPIHadoopFile(String path,
Class<F> fClass,
Class<K> kClass,
Class<V> vClass,
org.apache.hadoop.conf.Configuration conf)
Get an RDD for a given Hadoop file with an arbitrary new API InputFormat
and extra configuration options to pass to the input format.
|
<K,V,F extends org.apache.hadoop.mapreduce.InputFormat<K,V>> |
newAPIHadoopFile(String path,
scala.reflect.ClassTag<K> km,
scala.reflect.ClassTag<V> vm,
scala.reflect.ClassTag<F> fm)
Smarter version of
newApiHadoopFile that uses class tags to figure out the classes of keys,
values and the org.apache.hadoop.mapreduce.InputFormat (new MapReduce API) so that user
don't need to pass them directly. |
<K,V,F extends org.apache.hadoop.mapreduce.InputFormat<K,V>> |
newAPIHadoopRDD(org.apache.hadoop.conf.Configuration conf,
Class<F> fClass,
Class<K> kClass,
Class<V> vClass)
Get an RDD for a given Hadoop file with an arbitrary new API InputFormat
and extra configuration options to pass to the input format.
|
<T> RDD<T> |
objectFile(String path,
int minPartitions,
scala.reflect.ClassTag<T> evidence$4)
Load an RDD saved as a SequenceFile containing serialized objects, with NullWritable keys and
BytesWritable values that contain a serialized partition.
|
static void |
org$apache$spark$internal$Logging$$log__$eq(org.slf4j.Logger x$1) |
static org.slf4j.Logger |
org$apache$spark$internal$Logging$$log_() |
<T> RDD<T> |
parallelize(scala.collection.Seq<T> seq,
int numSlices,
scala.reflect.ClassTag<T> evidence$1)
Distribute a local Scala collection to form an RDD.
|
RDD<Object> |
range(long start,
long end,
long step,
int numSlices)
Creates a new RDD[Long] containing elements from
start to end (exclusive), increased by
step every element. |
void |
register(AccumulatorV2<?,?> acc)
Register the given accumulator.
|
void |
register(AccumulatorV2<?,?> acc,
String name)
Register the given accumulator with given name.
|
void |
removeJobTag(String tag)
Remove a tag previously added to be assigned to all the jobs started by this thread.
|
void |
removeSparkListener(SparkListenerInterface listener)
:: DeveloperApi ::
Deregister the listener from Spark's listener bus.
|
boolean |
requestExecutors(int numAdditionalExecutors)
:: DeveloperApi ::
Request an additional number of executors from the cluster manager.
|
boolean |
requestTotalExecutors(int numExecutors,
int localityAwareTasks,
scala.collection.immutable.Map<String,Object> hostToLocalTaskCount)
Update the cluster manager on our scheduling needs.
|
scala.collection.Map<String,ResourceInformation> |
resources() |
<T,U,R> PartialResult<R> |
runApproximateJob(RDD<T> rdd,
scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func,
ApproximateEvaluator<U,R> evaluator,
long timeout)
:: DeveloperApi ::
Run a job that can return approximate results.
|
<T,U> Object |
runJob(RDD<T> rdd,
scala.Function1<scala.collection.Iterator<T>,U> func,
scala.reflect.ClassTag<U> evidence$15)
Run a job on all partitions in an RDD and return the results in an array.
|
<T,U> void |
runJob(RDD<T> rdd,
scala.Function1<scala.collection.Iterator<T>,U> processPartition,
scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler,
scala.reflect.ClassTag<U> evidence$17)
Run a job on all partitions in an RDD and pass the results to a handler function.
|
<T,U> Object |
runJob(RDD<T> rdd,
scala.Function1<scala.collection.Iterator<T>,U> func,
scala.collection.Seq<Object> partitions,
scala.reflect.ClassTag<U> evidence$13)
Run a function on a given set of partitions in an RDD and return the results as an array.
|
<T,U> Object |
runJob(RDD<T> rdd,
scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func,
scala.reflect.ClassTag<U> evidence$14)
Run a job on all partitions in an RDD and return the results in an array.
|
<T,U> void |
runJob(RDD<T> rdd,
scala.Function2<TaskContext,scala.collection.Iterator<T>,U> processPartition,
scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler,
scala.reflect.ClassTag<U> evidence$16)
Run a job on all partitions in an RDD and pass the results to a handler function.
|
<T,U> Object |
runJob(RDD<T> rdd,
scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func,
scala.collection.Seq<Object> partitions,
scala.reflect.ClassTag<U> evidence$12)
Run a function on a given set of partitions in an RDD and return the results as an array.
|
<T,U> void |
runJob(RDD<T> rdd,
scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func,
scala.collection.Seq<Object> partitions,
scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler,
scala.reflect.ClassTag<U> evidence$11)
Run a function on a given set of partitions in an RDD and pass the results to the given
handler function.
|
<K,V> RDD<scala.Tuple2<K,V>> |
sequenceFile(String path,
Class<K> keyClass,
Class<V> valueClass)
Get an RDD for a Hadoop SequenceFile with given key and value types.
|
<K,V> RDD<scala.Tuple2<K,V>> |
sequenceFile(String path,
Class<K> keyClass,
Class<V> valueClass,
int minPartitions)
Get an RDD for a Hadoop SequenceFile with given key and value types.
|
<K,V> RDD<scala.Tuple2<K,V>> |
sequenceFile(String path,
int minPartitions,
scala.reflect.ClassTag<K> km,
scala.reflect.ClassTag<V> vm,
scala.Function0<org.apache.spark.WritableConverter<K>> kcf,
scala.Function0<org.apache.spark.WritableConverter<V>> vcf)
Version of sequenceFile() for types implicitly convertible to Writables through a
WritableConverter.
|
void |
setCallSite(String shortCallSite)
Set the thread-local property for overriding the call sites
of actions and RDDs.
|
void |
setCheckpointDir(String directory)
Set the directory under which RDDs are going to be checkpointed.
|
void |
setInterruptOnCancel(boolean interruptOnCancel)
Set the behavior of job cancellation from jobs started in this thread.
|
void |
setJobDescription(String value)
Set a human readable description of the current job.
|
void |
setJobGroup(String groupId,
String description,
boolean interruptOnCancel)
Assigns a group ID to all the jobs started by this thread until the group ID is set to a
different value or cleared.
|
void |
setLocalProperty(String key,
String value)
Set a local property that affects jobs submitted from this thread, such as the Spark fair
scheduler pool.
|
void |
setLogLevel(String logLevel)
Control our logLevel.
|
String |
sparkUser() |
long |
startTime() |
SparkStatusTracker |
statusTracker() |
void |
stop()
Shut down the SparkContext.
|
void |
stop(int exitCode)
Shut down the SparkContext with exit code that will passed to scheduler backend.
|
<T,U,R> SimpleFutureAction<R> |
submitJob(RDD<T> rdd,
scala.Function1<scala.collection.Iterator<T>,U> processPartition,
scala.collection.Seq<Object> partitions,
scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler,
scala.Function0<R> resultFunc)
Submit a job for execution and return a FutureJob holding the result.
|
RDD<String> |
textFile(String path,
int minPartitions)
Read a text file from HDFS, a local file system (available on all nodes), or any
Hadoop-supported file system URI, and return it as an RDD of Strings.
|
scala.Option<String> |
uiWebUrl() |
<T> RDD<T> |
union(RDD<T> first,
scala.collection.Seq<RDD<T>> rest,
scala.reflect.ClassTag<T> evidence$7)
Build the union of a list of RDDs passed as variable-length arguments.
|
<T> RDD<T> |
union(scala.collection.Seq<RDD<T>> rdds,
scala.reflect.ClassTag<T> evidence$6)
Build the union of a list of RDDs.
|
String |
version()
The version of Spark on which this application is running.
|
RDD<scala.Tuple2<String,String>> |
wholeTextFiles(String path,
int minPartitions)
Read a directory of text files from HDFS, a local file system (available on all nodes), or any
Hadoop-supported file system URI.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
$init$, initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, initLock, isTraceEnabled, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning, org$apache$spark$internal$Logging$$log__$eq, org$apache$spark$internal$Logging$$log_, uninitialize
public SparkContext(SparkConf config)
public SparkContext()
public SparkContext(String master, String appName, SparkConf conf)
master
- Cluster URL to connect to (e.g. mesos://host:port, spark://host:port, local[4]).appName
- A name for your application, to display on the cluster web UIconf
- a SparkConf
object specifying other Spark parameterspublic SparkContext(String master, String appName, String sparkHome, scala.collection.Seq<String> jars, scala.collection.Map<String,String> environment)
master
- Cluster URL to connect to (e.g. mesos://host:port, spark://host:port, local[4]).appName
- A name for your application, to display on the cluster web UI.sparkHome
- Location where Spark is installed on cluster nodes.jars
- Collection of JARs to send to the cluster. These can be paths on the local file
system or HDFS, HTTP, HTTPS, or FTP URLs.environment
- Environment variables to set on worker nodes.public static SparkContext getOrCreate(SparkConf config)
config
- SparkConfig
that will be used for initialisation of the SparkContext
SparkContext
(or a new one if it wasn't created before the function call)public static SparkContext getOrCreate()
This method allows not passing a SparkConf (useful if just retrieving).
SparkContext
(or a new one if wasn't created before the function call)public static scala.Option<String> jarOfClass(Class<?> cls)
cls
- class that should be inside of the jarNone
if not foundpublic static scala.Option<String> jarOfObject(Object obj)
obj
- reference to an instance which class should be inside of the jarNone
if not foundpublic static org.slf4j.Logger org$apache$spark$internal$Logging$$log_()
public static void org$apache$spark$internal$Logging$$log__$eq(org.slf4j.Logger x$1)
public long startTime()
public SparkConf getConf()
public scala.collection.Map<String,ResourceInformation> resources()
public scala.collection.Seq<String> jars()
public scala.collection.Seq<String> files()
public scala.collection.Seq<String> archives()
public String master()
public String deployMode()
public String appName()
public boolean isLocal()
public boolean isStopped()
public SparkStatusTracker statusTracker()
public scala.Option<String> uiWebUrl()
public org.apache.hadoop.conf.Configuration hadoopConfiguration()
public String sparkUser()
public String applicationId()
public scala.Option<String> applicationAttemptId()
public void setLogLevel(String logLevel)
logLevel
- The desired log level as a string.
Valid log levels include: ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARNpublic void setLocalProperty(String key, String value)
TaskContext.getLocalProperty(java.lang.String)
.
These properties are inherited by child threads spawned from this thread. This may have unexpected consequences when working with thread pools. The standard java implementation of thread pools have worker threads spawn other worker threads. As a result, local properties may propagate unpredictably.
key
- (undocumented)value
- (undocumented)public String getLocalProperty(String key)
org.apache.spark.SparkContext.setLocalProperty
.key
- (undocumented)public void setJobDescription(String value)
public void setJobGroup(String groupId, String description, boolean interruptOnCancel)
Often, a unit of execution in an application consists of multiple Spark actions or jobs. Application programmers can use this method to group all those jobs together and give a group description. Once set, the Spark web UI will associate such jobs with this group.
The application can also use org.apache.spark.SparkContext.cancelJobGroup
to cancel all
running jobs in this group. For example,
// In the main thread:
sc.setJobGroup("some_job_to_cancel", "some job description")
sc.parallelize(1 to 10000, 2).map { i => Thread.sleep(10); i }.count()
// In a separate thread:
sc.cancelJobGroup("some_job_to_cancel")
interruptOnCancel
- If true, then job cancellation will result in Thread.interrupt()
being called on the job's executor threads. This is useful to help ensure that the tasks
are actually stopped in a timely manner, but is off by default due to HDFS-1208, where HDFS
may respond to Thread.interrupt() by marking nodes as dead.groupId
- (undocumented)description
- (undocumented)public void clearJobGroup()
public void setInterruptOnCancel(boolean interruptOnCancel)
interruptOnCancel
- If true, then job cancellation will result in Thread.interrupt()
being called on the job's executor threads. This is useful to help ensure that the tasks
are actually stopped in a timely manner, but is off by default due to HDFS-1208, where HDFS
may respond to Thread.interrupt() by marking nodes as dead.
public void addJobTag(String tag)
tag
- The tag to be added. Cannot contain ',' (comma) character.
public void removeJobTag(String tag)
tag
- The tag to be removed. Cannot contain ',' (comma) character.
public scala.collection.immutable.Set<String> getJobTags()
public void clearJobTags()
public <T> RDD<T> parallelize(scala.collection.Seq<T> seq, int numSlices, scala.reflect.ClassTag<T> evidence$1)
seq
- Scala collection to distributenumSlices
- number of partitions to divide the collection intoevidence$1
- (undocumented)seq
is a mutable collection and is altered after the call
to parallelize and before the first action on the RDD, the resultant RDD will reflect the
modified collection. Pass a copy of the argument to avoid this., avoid using parallelize(Seq())
to create an empty RDD
. Consider emptyRDD
for an
RDD with no partitions, or parallelize(Seq[T]())
for an RDD of T
with empty partitions.public RDD<Object> range(long start, long end, long step, int numSlices)
start
to end
(exclusive), increased by
step
every element.
start
- the start value.end
- the end value.step
- the incremental stepnumSlices
- number of partitions to divide the collection intopublic <T> RDD<T> makeRDD(scala.collection.Seq<T> seq, int numSlices, scala.reflect.ClassTag<T> evidence$2)
This method is identical to parallelize
.
seq
- Scala collection to distributenumSlices
- number of partitions to divide the collection intoevidence$2
- (undocumented)public <T> RDD<T> makeRDD(scala.collection.Seq<scala.Tuple2<T,scala.collection.Seq<String>>> seq, scala.reflect.ClassTag<T> evidence$3)
seq
- list of tuples of data and location preferences (hostnames of Spark nodes)evidence$3
- (undocumented)public RDD<String> textFile(String path, int minPartitions)
path
- path to the text file on a supported file systemminPartitions
- suggested minimum number of partitions for the resulting RDDpublic RDD<scala.Tuple2<String,String>> wholeTextFiles(String path, int minPartitions)
For example, if you have the following files:
hdfs://a-hdfs-path/part-00000
hdfs://a-hdfs-path/part-00001
...
hdfs://a-hdfs-path/part-nnnnn
Do val rdd = sparkContext.wholeTextFile("hdfs://a-hdfs-path")
,
then rdd
contains
(a-hdfs-path/part-00000, its content)
(a-hdfs-path/part-00001, its content)
...
(a-hdfs-path/part-nnnnn, its content)
path
- Directory to the input data files, the path can be comma separated paths as the
list of inputs.minPartitions
- A suggestion value of the minimal splitting number for input data..../path/*
can be a more efficient way to read all files
in a directory rather than .../path/
or .../path
, Partitioning is determined by data locality. This may result in too few partitions
by default.
public RDD<scala.Tuple2<String,PortableDataStream>> binaryFiles(String path, int minPartitions)
For example, if you have the following files:
hdfs://a-hdfs-path/part-00000
hdfs://a-hdfs-path/part-00001
...
hdfs://a-hdfs-path/part-nnnnn
Do
val rdd = sparkContext.binaryFiles("hdfs://a-hdfs-path")
,
then rdd
contains
(a-hdfs-path/part-00000, its content)
(a-hdfs-path/part-00001, its content)
...
(a-hdfs-path/part-nnnnn, its content)
path
- Directory to the input data files, the path can be comma separated paths as the
list of inputs.minPartitions
- A suggestion value of the minimal splitting number for input data..../path/*
can be a more efficient way to read all files
in a directory rather than .../path/
or .../path
, Partitioning is determined by data locality. This may result in too few partitions
by default.
public RDD<byte[]> binaryRecords(String path, int recordLength, org.apache.hadoop.conf.Configuration conf)
path
- Directory to the input data files, the path can be comma separated paths as the
list of inputs.recordLength
- The length at which to split the recordsconf
- Configuration for setting up the dataset.
public <K,V> RDD<scala.Tuple2<K,V>> hadoopRDD(org.apache.hadoop.mapred.JobConf conf, Class<? extends org.apache.hadoop.mapred.InputFormat<K,V>> inputFormatClass, Class<K> keyClass, Class<V> valueClass, int minPartitions)
org.apache.hadoop.mapred
).
conf
- JobConf for setting up the dataset. Note: This will be put into a Broadcast.
Therefore if you plan to reuse this conf to create multiple RDDs, you need to make
sure you won't modify the conf. A safe approach is always creating a new conf for
a new RDD.inputFormatClass
- storage format of the data to be readkeyClass
- Class
of the key associated with the inputFormatClass
parametervalueClass
- Class
of the value associated with the inputFormatClass
parameterminPartitions
- Minimum number of Hadoop Splits to generate.map
function.public <K,V> RDD<scala.Tuple2<K,V>> hadoopFile(String path, Class<? extends org.apache.hadoop.mapred.InputFormat<K,V>> inputFormatClass, Class<K> keyClass, Class<V> valueClass, int minPartitions)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputsinputFormatClass
- storage format of the data to be readkeyClass
- Class
of the key associated with the inputFormatClass
parametervalueClass
- Class
of the value associated with the inputFormatClass
parameterminPartitions
- suggested minimum number of partitions for the resulting RDDmap
function.public <K,V,F extends org.apache.hadoop.mapred.InputFormat<K,V>> RDD<scala.Tuple2<K,V>> hadoopFile(String path, int minPartitions, scala.reflect.ClassTag<K> km, scala.reflect.ClassTag<V> vm, scala.reflect.ClassTag<F> fm)
val file = sparkContext.hadoopFile[LongWritable, Text, TextInputFormat](path, minPartitions)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputsminPartitions
- suggested minimum number of partitions for the resulting RDDkm
- (undocumented)vm
- (undocumented)fm
- (undocumented)map
function.public <K,V,F extends org.apache.hadoop.mapred.InputFormat<K,V>> RDD<scala.Tuple2<K,V>> hadoopFile(String path, scala.reflect.ClassTag<K> km, scala.reflect.ClassTag<V> vm, scala.reflect.ClassTag<F> fm)
val file = sparkContext.hadoopFile[LongWritable, Text, TextInputFormat](path)
path
- directory to the input data files, the path can be comma separated paths as
a list of inputskm
- (undocumented)vm
- (undocumented)fm
- (undocumented)map
function.public <K,V,F extends org.apache.hadoop.mapreduce.InputFormat<K,V>> RDD<scala.Tuple2<K,V>> newAPIHadoopFile(String path, scala.reflect.ClassTag<K> km, scala.reflect.ClassTag<V> vm, scala.reflect.ClassTag<F> fm)
newApiHadoopFile
that uses class tags to figure out the classes of keys,
values and the org.apache.hadoop.mapreduce.InputFormat
(new MapReduce API) so that user
don't need to pass them directly. Instead, callers can just write, for example:
val file = sparkContext.hadoopFile[LongWritable, Text, TextInputFormat](path)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputskm
- (undocumented)vm
- (undocumented)fm
- (undocumented)map
function.public <K,V,F extends org.apache.hadoop.mapreduce.InputFormat<K,V>> RDD<scala.Tuple2<K,V>> newAPIHadoopFile(String path, Class<F> fClass, Class<K> kClass, Class<V> vClass, org.apache.hadoop.conf.Configuration conf)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputsfClass
- storage format of the data to be readkClass
- Class
of the key associated with the fClass
parametervClass
- Class
of the value associated with the fClass
parameterconf
- Hadoop configurationmap
function.public <K,V,F extends org.apache.hadoop.mapreduce.InputFormat<K,V>> RDD<scala.Tuple2<K,V>> newAPIHadoopRDD(org.apache.hadoop.conf.Configuration conf, Class<F> fClass, Class<K> kClass, Class<V> vClass)
conf
- Configuration for setting up the dataset. Note: This will be put into a Broadcast.
Therefore if you plan to reuse this conf to create multiple RDDs, you need to make
sure you won't modify the conf. A safe approach is always creating a new conf for
a new RDD.fClass
- storage format of the data to be readkClass
- Class
of the key associated with the fClass
parametervClass
- Class
of the value associated with the fClass
parameter
map
function.public <K,V> RDD<scala.Tuple2<K,V>> sequenceFile(String path, Class<K> keyClass, Class<V> valueClass, int minPartitions)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputskeyClass
- Class
of the key associated with SequenceFileInputFormat
valueClass
- Class
of the value associated with SequenceFileInputFormat
minPartitions
- suggested minimum number of partitions for the resulting RDDmap
function.public <K,V> RDD<scala.Tuple2<K,V>> sequenceFile(String path, Class<K> keyClass, Class<V> valueClass)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputskeyClass
- Class
of the key associated with SequenceFileInputFormat
valueClass
- Class
of the value associated with SequenceFileInputFormat
map
function.public <K,V> RDD<scala.Tuple2<K,V>> sequenceFile(String path, int minPartitions, scala.reflect.ClassTag<K> km, scala.reflect.ClassTag<V> vm, scala.Function0<org.apache.spark.WritableConverter<K>> kcf, scala.Function0<org.apache.spark.WritableConverter<V>> vcf)
sparkContext.sequenceFile[String, Int](path, ...)
WritableConverters are provided in a somewhat strange way (by an implicit function) to support both subclasses of Writable and types for which we define a converter (e.g. Int to IntWritable). The most natural thing would've been to have implicit objects for the converters, but then we couldn't have an object for every subclass of Writable (you can't have a parameterized singleton object). We use functions instead to create a new converter for the appropriate type. In addition, we pass the converter a ClassTag of its type to allow it to figure out the Writable class to use in the subclass case.
path
- directory to the input data files, the path can be comma separated paths
as a list of inputsminPartitions
- suggested minimum number of partitions for the resulting RDDkm
- (undocumented)vm
- (undocumented)kcf
- (undocumented)vcf
- (undocumented)map
function.public <T> RDD<T> objectFile(String path, int minPartitions, scala.reflect.ClassTag<T> evidence$4)
path
- directory to the input data files, the path can be comma separated paths
as a list of inputsminPartitions
- suggested minimum number of partitions for the resulting RDDevidence$4
- (undocumented)public <T> RDD<T> union(scala.collection.Seq<RDD<T>> rdds, scala.reflect.ClassTag<T> evidence$6)
public <T> RDD<T> union(RDD<T> first, scala.collection.Seq<RDD<T>> rest, scala.reflect.ClassTag<T> evidence$7)
public <T> RDD<T> emptyRDD(scala.reflect.ClassTag<T> evidence$8)
public void register(AccumulatorV2<?,?> acc)
acc
- (undocumented)public void register(AccumulatorV2<?,?> acc, String name)
acc
- (undocumented)name
- (undocumented)public LongAccumulator longAccumulator()
add
.public LongAccumulator longAccumulator(String name)
add
.name
- (undocumented)public DoubleAccumulator doubleAccumulator()
add
.public DoubleAccumulator doubleAccumulator(String name)
add
.name
- (undocumented)public <T> CollectionAccumulator<T> collectionAccumulator()
CollectionAccumulator
, which starts with empty list and accumulates
inputs by adding them into the list.public <T> CollectionAccumulator<T> collectionAccumulator(String name)
CollectionAccumulator
, which starts with empty list and accumulates
inputs by adding them into the list.name
- (undocumented)public <T> Broadcast<T> broadcast(T value, scala.reflect.ClassTag<T> evidence$9)
Broadcast
object for reading it in distributed functions.
The variable will be sent to each executor only once.
value
- value to broadcast to the Spark nodesevidence$9
- (undocumented)Broadcast
object, a read-only variable cached on each machinepublic void addFile(String path)
If a file is added during execution, it will not be available until the next TaskSet starts.
path
- can be either a local file, a file in HDFS (or other Hadoop-supported
filesystems), or an HTTP, HTTPS or FTP URI. To access the file in Spark jobs,
use SparkFiles.get(fileName)
to find its download location.
public scala.collection.Seq<String> listFiles()
public void addArchive(String path)
If an archive is added during execution, it will not be available until the next TaskSet starts.
path
- can be either a local file, a file in HDFS (or other Hadoop-supported
filesystems), or an HTTP, HTTPS or FTP URI. To access the file in Spark jobs,
use SparkFiles.get(paths-to-files)
to find its download/unpacked location.
The given path should be one of .zip, .tar, .tar.gz, .tgz and .jar.
public scala.collection.Seq<String> listArchives()
public void addFile(String path, boolean recursive)
If a file is added during execution, it will not be available until the next TaskSet starts.
path
- can be either a local file, a file in HDFS (or other Hadoop-supported
filesystems), or an HTTP, HTTPS or FTP URI. To access the file in Spark jobs,
use SparkFiles.get(fileName)
to find its download location.recursive
- if true, a directory can be given in path
. Currently directories are
only supported for Hadoop-supported filesystems.
public void addSparkListener(SparkListenerInterface listener)
listener
- (undocumented)public void removeSparkListener(SparkListenerInterface listener)
listener
- (undocumented)public boolean requestTotalExecutors(int numExecutors, int localityAwareTasks, scala.collection.immutable.Map<String,Object> hostToLocalTaskCount)
numExecutors
- The total number of executors we'd like to have. The cluster manager
shouldn't kill any running executor to reach this number, but,
if all existing executors were to die, this is the number of executors
we'd want to be allocated.localityAwareTasks
- The number of tasks in all active stages that have a locality
preferences. This includes running, pending, and completed tasks.hostToLocalTaskCount
- A map of hosts to the number of tasks from all active stages
that would like to like to run on that host.
This includes running, pending, and completed tasks.public boolean requestExecutors(int numAdditionalExecutors)
numAdditionalExecutors
- (undocumented)public boolean killExecutors(scala.collection.Seq<String> executorIds)
This is not supported when dynamic allocation is turned on.
executorIds
- (undocumented)public boolean killExecutor(String executorId)
executorId
- (undocumented)public String version()
public scala.collection.Map<String,scala.Tuple2<Object,Object>> getExecutorMemoryStatus()
public RDDInfo[] getRDDStorageInfo()
public scala.collection.Map<Object,RDD<?>> getPersistentRDDs()
public scala.collection.Seq<Schedulable> getAllPools()
public scala.Option<Schedulable> getPoolForName(String pool)
pool
- (undocumented)public scala.Enumeration.Value getSchedulingMode()
public void addJar(String path)
SparkContext
in the future.
If a jar is added during execution, it will not be available until the next TaskSet starts.
path
- can be either a local file, a file in HDFS (or other Hadoop-supported filesystems),
an HTTP, HTTPS or FTP URI, or local:/path for a file on every worker node.
public scala.collection.Seq<String> listJars()
public void stop()
public void stop(int exitCode)
SparkContext.stop()
to clean up but exit with
code not equal to 0. This behavior cause resource scheduler such as ApplicationMaster
exit with success status but client side exited with failed status. Spark can call
this method to stop SparkContext and pass client side correct exit code to scheduler backend.
Then scheduler backend should send the exit code to corresponding resource scheduler
to keep consistent.
exitCode
- Specified exit code that will passed to scheduler backend in client mode.public void setCallSite(String shortCallSite)
shortCallSite
- (undocumented)public void clearCallSite()
public <T,U> void runJob(RDD<T> rdd, scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func, scala.collection.Seq<Object> partitions, scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler, scala.reflect.ClassTag<U> evidence$11)
rdd
- target RDD to run tasks onfunc
- a function to run on each partition of the RDDpartitions
- set of partitions to run on; some jobs may not want to compute on all
partitions of the target RDD, e.g. for operations like first()
resultHandler
- callback to pass each result toevidence$11
- (undocumented)public <T,U> Object runJob(RDD<T> rdd, scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func, scala.collection.Seq<Object> partitions, scala.reflect.ClassTag<U> evidence$12)
TaskContext
argument.
rdd
- target RDD to run tasks onfunc
- a function to run on each partition of the RDDpartitions
- set of partitions to run on; some jobs may not want to compute on all
partitions of the target RDD, e.g. for operations like first()
evidence$12
- (undocumented)public <T,U> Object runJob(RDD<T> rdd, scala.Function1<scala.collection.Iterator<T>,U> func, scala.collection.Seq<Object> partitions, scala.reflect.ClassTag<U> evidence$13)
rdd
- target RDD to run tasks onfunc
- a function to run on each partition of the RDDpartitions
- set of partitions to run on; some jobs may not want to compute on all
partitions of the target RDD, e.g. for operations like first()
evidence$13
- (undocumented)public <T,U> Object runJob(RDD<T> rdd, scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func, scala.reflect.ClassTag<U> evidence$14)
TaskContext
argument.
rdd
- target RDD to run tasks onfunc
- a function to run on each partition of the RDDevidence$14
- (undocumented)public <T,U> Object runJob(RDD<T> rdd, scala.Function1<scala.collection.Iterator<T>,U> func, scala.reflect.ClassTag<U> evidence$15)
rdd
- target RDD to run tasks onfunc
- a function to run on each partition of the RDDevidence$15
- (undocumented)public <T,U> void runJob(RDD<T> rdd, scala.Function2<TaskContext,scala.collection.Iterator<T>,U> processPartition, scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler, scala.reflect.ClassTag<U> evidence$16)
TaskContext
argument.
rdd
- target RDD to run tasks onprocessPartition
- a function to run on each partition of the RDDresultHandler
- callback to pass each result toevidence$16
- (undocumented)public <T,U> void runJob(RDD<T> rdd, scala.Function1<scala.collection.Iterator<T>,U> processPartition, scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler, scala.reflect.ClassTag<U> evidence$17)
rdd
- target RDD to run tasks onprocessPartition
- a function to run on each partition of the RDDresultHandler
- callback to pass each result toevidence$17
- (undocumented)public <T,U,R> PartialResult<R> runApproximateJob(RDD<T> rdd, scala.Function2<TaskContext,scala.collection.Iterator<T>,U> func, ApproximateEvaluator<U,R> evaluator, long timeout)
rdd
- target RDD to run tasks onfunc
- a function to run on each partition of the RDDevaluator
- ApproximateEvaluator
to receive the partial resultstimeout
- maximum time to wait for the job, in millisecondspublic <T,U,R> SimpleFutureAction<R> submitJob(RDD<T> rdd, scala.Function1<scala.collection.Iterator<T>,U> processPartition, scala.collection.Seq<Object> partitions, scala.Function2<Object,U,scala.runtime.BoxedUnit> resultHandler, scala.Function0<R> resultFunc)
rdd
- target RDD to run tasks onprocessPartition
- a function to run on each partition of the RDDpartitions
- set of partitions to run on; some jobs may not want to compute on all
partitions of the target RDD, e.g. for operations like first()
resultHandler
- callback to pass each result toresultFunc
- function to be executed when the result is readypublic void cancelJobGroup(String groupId)
org.apache.spark.SparkContext.setJobGroup
for more information.groupId
- (undocumented)public void cancelJobsWithTag(String tag)
org.apache.spark.SparkContext.addJobTag
.
tag
- The tag to be cancelled. Cannot contain ',' (comma) character.
public void cancelAllJobs()
public void cancelJob(int jobId, String reason)
jobId
- the job ID to cancelreason
- optional reason for cancellationInterruptedException
if the cancel message cannot be sentpublic void cancelJob(int jobId)
jobId
- the job ID to cancelInterruptedException
if the cancel message cannot be sentpublic void cancelStage(int stageId, String reason)
stageId
- the stage ID to cancelreason
- reason for cancellationInterruptedException
if the cancel message cannot be sentpublic void cancelStage(int stageId)
stageId
- the stage ID to cancelInterruptedException
if the cancel message cannot be sentpublic boolean killTaskAttempt(long taskId, boolean interruptThread, String reason)
taskId
- the task ID to kill. This id uniquely identifies the task attempt.interruptThread
- whether to interrupt the thread running the task.reason
- the reason for killing the task, which should be a short string. If a task
is killed multiple times with different reasons, only one reason will be reported.
public void setCheckpointDir(String directory)
directory
- path to the directory where checkpoint files will be stored
(must be HDFS path if running in cluster)public scala.Option<String> getCheckpointDir()
public int defaultParallelism()
public int defaultMinPartitions()