<?php
$scale = array(
"A" => "Do",
"B" => "Re",
"C" => 'Mi',
"D" => 'Fa',
"E" => 'So',
"F" => 'La',
"G" => 'Ti'
);
if (isset($_POST['notes']))
{
$query=$_POST['notes'];
foreach ($scale as $key => $sound)
{
if ($query == $key)
{
echo $sound;
}
}
}
?>
<form action="MusicalScale.php" method="post">
<label>Enter in a music note</label> <input type="text" name="notes"><br>
<input type="submit" value="Submit">
</form>
我只需要映射那些p(14)不为空的行。我如何在scala上执行此操作?
答案 0 :(得分:0)
val labResult = RDDlab.filter(p => p(14).toString != null && !p(14).toString.isEmpty).map(p => LabResult(p(1).toString, dateFormat.parse(p(8).toString), p(7).toString, p(14).toString.toDouble))
用户filter
即可。
答案 1 :(得分:0)
我建议在这里使用StringUtils来过滤掉空字符串和空字符串。
import org.apache.commons.lang3.StringUtils
val labResult = RDDlab.filter(p => StringUtils.isNotEmpty(p(14).toString)).map(p => LabResult(p(1).toString, dateFormat.parse(p(8).toString), p(7).toString, p(14).toString.toDouble))
答案 2 :(得分:0)
对于此Scala提供了collect
方法,该方法可以与pattern matching
和pattern guards
巧妙地结合使用。
val labResult =
RDDlab
.collect{
case p if p(14) != null && p(14).toString.isDefined =>
LabResult(
p(1).toString,
dateFormat.parse(p(8).toString),
p(7).toString,
p(14).toStr
)
}