Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

# 

# Licensed to the Apache Software Foundation (ASF) under one or more 

# contributor license agreements. See the NOTICE file distributed with 

# this work for additional information regarding copyright ownership. 

# The ASF licenses this file to You under the Apache License, Version 2.0 

# (the "License"); you may not use this file except in compliance with 

# the License. You may obtain a copy of the License at 

# 

# http://www.apache.org/licenses/LICENSE-2.0 

# 

# Unless required by applicable law or agreed to in writing, software 

# distributed under the License is distributed on an "AS IS" BASIS, 

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

# See the License for the specific language governing permissions and 

# limitations under the License. 

# 

 

""" 

PySpark is the Python API for Spark. 

 

Public classes: 

 

- :class:`SparkContext`: 

Main entry point for Spark functionality. 

- :class:`RDD`: 

A Resilient Distributed Dataset (RDD), the basic abstraction in Spark. 

- :class:`Broadcast`: 

A broadcast variable that gets reused across tasks. 

- :class:`Accumulator`: 

An "add-only" shared variable that tasks can only add values to. 

- :class:`SparkConf`: 

For configuring Spark. 

- :class:`SparkFiles`: 

Access files shipped with jobs. 

- :class:`StorageLevel`: 

Finer-grained cache persistence levels. 

- :class:`TaskContext`: 

Information about the current running task, available on the workers and experimental. 

- :class:`RDDBarrier`: 

Wraps an RDD under a barrier stage for barrier execution. 

- :class:`BarrierTaskContext`: 

A :class:`TaskContext` that provides extra info and tooling for barrier execution. 

- :class:`BarrierTaskInfo`: 

Information about a barrier task. 

- :class:`InheritableThread`: 

A inheritable thread to use in Spark when the pinned thread mode is on. 

""" 

 

from functools import wraps 

import types 

 

from pyspark.conf import SparkConf 

from pyspark.rdd import RDD, RDDBarrier 

from pyspark.files import SparkFiles 

from pyspark.status import StatusTracker, SparkJobInfo, SparkStageInfo 

from pyspark.util import InheritableThread, inheritable_thread_target 

from pyspark.storagelevel import StorageLevel 

from pyspark.accumulators import Accumulator, AccumulatorParam 

from pyspark.broadcast import Broadcast 

from pyspark.serializers import MarshalSerializer, PickleSerializer 

from pyspark.taskcontext import TaskContext, BarrierTaskContext, BarrierTaskInfo 

from pyspark.profiler import Profiler, BasicProfiler 

from pyspark.version import __version__ 

from pyspark._globals import _NoValue # noqa: F401 

 

 

def since(version): 

""" 

A decorator that annotates a function to append the version of Spark the function was added. 

""" 

import re 

indent_p = re.compile(r'\n( +)') 

 

def deco(f): 

indents = indent_p.findall(f.__doc__) 

indent = ' ' * (min(len(m) for m in indents) if indents else 0) 

f.__doc__ = f.__doc__.rstrip() + "\n\n%s.. versionadded:: %s" % (indent, version) 

return f 

return deco 

 

 

def copy_func(f, name=None, sinceversion=None, doc=None): 

""" 

Returns a function with same code, globals, defaults, closure, and 

name (or provide a new name). 

""" 

# See 

# http://stackoverflow.com/questions/6527633/how-can-i-make-a-deepcopy-of-a-function-in-python 

fn = types.FunctionType(f.__code__, f.__globals__, name or f.__name__, f.__defaults__, 

f.__closure__) 

# in case f was given attrs (note this dict is a shallow copy): 

fn.__dict__.update(f.__dict__) 

93 ↛ 95line 93 didn't jump to line 95, because the condition on line 93 was never false if doc is not None: 

fn.__doc__ = doc 

95 ↛ 97line 95 didn't jump to line 97, because the condition on line 95 was never false if sinceversion is not None: 

fn = since(sinceversion)(fn) 

return fn 

 

 

def keyword_only(func): 

""" 

A decorator that forces keyword arguments in the wrapped method 

and saves actual input keyword arguments in `_input_kwargs`. 

 

Notes 

----- 

Should only be used to wrap a method where first arg is `self` 

""" 

@wraps(func) 

def wrapper(self, *args, **kwargs): 

if len(args) > 0: 

raise TypeError("Method %s forces keyword arguments." % func.__name__) 

self._input_kwargs = kwargs 

return func(self, **kwargs) 

return wrapper 

 

# To avoid circular dependencies 

from pyspark.context import SparkContext 

 

# for back compatibility 

from pyspark.sql import SQLContext, HiveContext, Row # noqa: F401 

 

__all__ = [ 

"SparkConf", "SparkContext", "SparkFiles", "RDD", "StorageLevel", "Broadcast", 

"Accumulator", "AccumulatorParam", "MarshalSerializer", "PickleSerializer", 

"StatusTracker", "SparkJobInfo", "SparkStageInfo", "Profiler", "BasicProfiler", "TaskContext", 

"RDDBarrier", "BarrierTaskContext", "BarrierTaskInfo", "InheritableThread", 

"inheritable_thread_target", "__version__", 

]