Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-12424][ML] The implementation of ParamMap#filter is wrong. #10381

Closed
wants to merge 4 commits into from

Conversation

sarutak
Copy link
Member

@sarutak sarutak commented Dec 18, 2015

ParamMap#filter uses mutable.Map#filterKeys. The return type of filterKey is collection.Map, not mutable.Map but the result is casted to mutable.Map using asInstanceOf so we get ClassCastException.
Also, the return type of Map#filterKeys is not Serializable. It's the issue of Scala (https://issues.scala-lang.org/browse/SI-6654).

// Not using filterKeys also avoid SI-6654
val filtered = map.filter {
case (k, _) =>
k.parent == parent.uid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the indent seems to be broken

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've fixed it.

@BenFradet
Copy link
Contributor

LGTM except one minor comment.

@SparkQA
Copy link

SparkQA commented Dec 18, 2015

Test build #48008 has finished for PR 10381 at commit 95e3ff2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 18, 2015

Test build #48010 has finished for PR 10381 at commit d3fc82d.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

// returns the instance of collections.Map, not mutable.Map.
// Otherwise, we get ClassCastException.
// Not using filterKeys also avoid SI-6654
val filtered = map.filter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This could be on one line but I wouldn't change it

@SparkQA
Copy link

SparkQA commented Dec 18, 2015

Test build #48019 has finished for PR 10381 at commit 080e983.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sarutak
Copy link
Member Author

sarutak commented Dec 21, 2015

cc: @mengxr @jkbradley

@yanboliang
Copy link
Contributor

LGTM

// returns the instance of collections.Map, not mutable.Map.
// Otherwise, we get ClassCastException.
// Not using filterKeys also avoid SI-6654
val filtered = map.filter { case (k, _) => k.parent == parent.uid }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hasn't this changed the logic slightly? now you compare to parent.uid

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original logic is wrong because the type of .parent is String (this is a member of Param) while the type of parameter parent is Params.

According to the implementation of Param, the member parent of Param is passed uid of Identifiable which is a trait of Params.

class Param[T](val parent: String, val name: String, val doc: String, val isValid: T => Boolean)
  extends Serializable {

  def this(parent: Identifiable, name: String, doc: String, isValid: T => Boolean) =
    this(parent.uid, name, doc, isValid)

@SparkQA
Copy link

SparkQA commented Dec 28, 2015

Test build #48364 has finished for PR 10381 at commit ea924e9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sarutak
Copy link
Member Author

sarutak commented Dec 28, 2015

Thanks @srowen , @BenFradet and @yanboliang for the review. I'm merging this into master and branch-1.6.

asfgit pushed a commit that referenced this pull request Dec 28, 2015
ParamMap#filter uses `mutable.Map#filterKeys`. The return type of `filterKey` is collection.Map, not mutable.Map but the result is casted to mutable.Map using `asInstanceOf` so we get `ClassCastException`.
Also, the return type of Map#filterKeys is not Serializable. It's the issue of Scala (https://issues.scala-lang.org/browse/SI-6654).

Author: Kousuke Saruta <[email protected]>

Closes #10381 from sarutak/SPARK-12424.

(cherry picked from commit 07165ca)
Signed-off-by: Kousuke Saruta <[email protected]>
@asfgit asfgit closed this in 07165ca Dec 28, 2015
@sarutak sarutak deleted the SPARK-12424 branch June 4, 2021 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants