Skip to content

Commit

Permalink
[SPARK-15707][SQL] Make Code Neat - Use map instead of if check.
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?
In forType function of object RandomDataGenerator, the code following:
if (maybeSqlTypeGenerator.isDefined){
  ....
  Some(generator)
} else{
 None
}
will be changed. Instead, maybeSqlTypeGenerator.map will be used.

## How was this patch tested?
All of the current unit tests passed.

Author: Weiqing Yang <[email protected]>

Closes apache#13448 from Sherry302/master.
  • Loading branch information
weiqingy authored and srowen committed Jun 4, 2016
1 parent 091f81e commit 0f307db
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,15 @@ object RandomDataGenerator {
// convert it to catalyst value to call udt's deserialize.
val toCatalystType = CatalystTypeConverters.createToCatalystConverter(udt.sqlType)

if (maybeSqlTypeGenerator.isDefined) {
val sqlTypeGenerator = maybeSqlTypeGenerator.get
val generator = () => {
maybeSqlTypeGenerator.map { sqlTypeGenerator =>
() => {
val generatedScalaValue = sqlTypeGenerator.apply()
if (generatedScalaValue == null) {
null
} else {
udt.deserialize(toCatalystType(generatedScalaValue))
}
}
Some(generator)
} else {
None
}
case unsupportedType => None
}
Expand Down

0 comments on commit 0f307db

Please sign in to comment.