spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niek Bartholomeus (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-19492) Dataset, filter and pattern matching on elements
Date Wed, 15 Feb 2017 20:21:41 GMT

    [ https://issues.apache.org/jira/browse/SPARK-19492?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15868503#comment-15868503
] 

Niek Bartholomeus commented on SPARK-19492:
-------------------------------------------

I'm having this issue since starting to use spark a year ago. I thought it was a minor issue
that would get solved in the next update but it's still there in 2.1.0. The workaround is
indeed to create a val func as described above or even simpler to wrap it with a match clause:

{code}
 departments.filter{ x => x match {case Department(_, name)=>
  name == "hr"
}}
{code}

> Dataset, filter and pattern matching on elements
> ------------------------------------------------
>
>                 Key: SPARK-19492
>                 URL: https://issues.apache.org/jira/browse/SPARK-19492
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.0.2, 2.1.0
>            Reporter: Loic Descotte
>            Priority: Minor
>
> It seems it is impossible to use pattern matching to define input parameters for function
filter on datasets.
> Example :
> This one is working :
> {code}
> val departments = Seq(
>     Department(1, "hr"),
>     Department(2, "it")
> ).toDS
> departments.filter{ d=> 
>   d.name == "hr"
> }
> {code}
> but not this one :
> {code}
>  departments.filter{ case Department(_, name)=>
>   name == "hr"
> }
> {code}
> Error :
> {code}
> error: missing parameter type for expanded function
> The argument types of an anonymous function must be fully known. (SLS 8.5)
> Expected type was: ?
>     departments.filter{ case Department(_, name)=>
> {code}
> This kind of pattern matching should work (as departements dataset type is known) like
Scala collections filter function, or RDD filter function for example.
> Please note that it works on map function : 
> {code}
>  departments.map{ case Department(_, name)=>
>       name
>  }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message