Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
8b0390d3
Commit
8b0390d3
authored
13 years ago
by
Matei Zaharia
Browse files
Options
Downloads
Patches
Plain Diff
Instantiate NullWritable properly in HadoopFile
parent
c501cff9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/scala/spark/HadoopFile.scala
+12
-2
12 additions, 2 deletions
core/src/main/scala/spark/HadoopFile.scala
with
12 additions
and
2 deletions
core/src/main/scala/spark/HadoopFile.scala
+
12
−
2
View file @
8b0390d3
...
...
@@ -3,6 +3,7 @@ package spark
import
mesos.SlaveOffer
import
org.apache.hadoop.io.LongWritable
import
org.apache.hadoop.io.NullWritable
import
org.apache.hadoop.io.Text
import
org.apache.hadoop.mapred.FileInputFormat
import
org.apache.hadoop.mapred.InputFormat
...
...
@@ -51,6 +52,15 @@ extends RDD[(K, V)](sc) {
.
asInstanceOf
[
InputFormat
[
K
,
V
]]
}
// Helper method for creating a Hadoop Writable, because the commonly used
// NullWritable class has no constructor
def
createWritable
[
T
](
clazz
:
Class
[
T
])
:
T
=
{
if
(
clazz
==
classOf
[
NullWritable
])
NullWritable
.
get
().
asInstanceOf
[
T
]
else
clazz
.
newInstance
()
}
override
def
splits
=
splits_
override
def
compute
(
theSplit
:
Split
)
=
new
Iterator
[(
K
,
V
)]
{
...
...
@@ -63,8 +73,8 @@ extends RDD[(K, V)](sc) {
val
fmt
=
createInputFormat
(
conf
)
reader
=
fmt
.
getRecordReader
(
split
.
inputSplit
.
value
,
conf
,
Reporter
.
NULL
)
val
key
:
K
=
keyClass
.
newInstance
(
)
val
value
:
V
=
valueClass
.
newInstance
(
)
val
key
:
K
=
createWritable
(
keyClass
)
val
value
:
V
=
createWritable
(
valueClass
)
var
gotNext
=
false
var
finished
=
false
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment