Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6982#discussion_r33536204
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExtractValue.scala
 ---
    @@ -209,4 +257,16 @@ case class GetMapValue(child: Expression, ordinal: 
Expression)
         val baseValue = value.asInstanceOf[Map[Any, _]]
         baseValue.get(ordinal).orNull
       }
    +
    +  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
    +    nullSafeCodeGen(ctx, ev, (result, eval1, eval2) => {
    +      s"""
    +        if ($eval1.contains($eval2)) {
    +          $result = (${ctx.boxedType(dataType)})$eval1.apply($eval2);
    +        } else {
    +          ${ev.isNull} = true;
    --- End diff --
    
    We search the map twice here(`contains` and `apply`), I was trying to fix 
it by using `map.getOrElse(key, null)` and `map.get.orNull`, but both failed as 
they need a function as parameter. One possible way is using `apply` and try 
catch the NPE but that's too nasty. Is there any better ways to search scala 
map in java?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to