Skip to content

SPARK-3177 (on Master Branch) #2204

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

Closed
wants to merge 1 commit into from
Closed

SPARK-3177 (on Master Branch) #2204

wants to merge 1 commit into from

Conversation

chesterxgchen
Copy link

The JIRA and PR was original created for branch-1.1, and move to master branch now.
Chester

The Issue is due to that yarn-alpha and yarn have different APIs for certain class fields. In this particular case, the ClientBase using reflection to to address this issue, and we need to different way to test the ClientBase's method. Original ClientBaseSuite using getFieldValue() method to do this. But it doesn't work for yarn-alpha as the API returns an array of String instead of just String (which is the case for Yarn-stable API).

To fix the test, I add a new method

def getFieldValue2[A: ClassTag, A1: ClassTag, B](clazz: Class[], field: String,
defaults: => B)
(mapTo: A => B)(mapTo1: A1 => B) : B =
Try(clazz.getField(field)).map(
.get(null)).map {
case v: A => mapTo(v)
case v1: A1 => mapTo1(v1)
case _ => defaults
}.toOption.getOrElse(defaults)

to handle the cases where the field type can be either type A or A1. In this new method the type A or A1 is pattern matched and corresponding mapTo function (mapTo or mapTo1) is used.

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@chesterxgchen
Copy link
Author

I have tested against 2.0.5-alpha, 2.0.6-alpha (yarn-alpha) and 2.3.0-cdh5.0.0 (yarn-stable)
all yarn-alpha/test and yarn-stable/test are passed.

@@ -232,6 +233,15 @@ class ClientBaseSuite extends FunSuite with Matchers {
def getFieldValue[A, B](clazz: Class[_], field: String, defaults: => B)(mapTo: A => B): B =
Try(clazz.getField(field)).map(_.get(null).asInstanceOf[A]).toOption.map(mapTo).getOrElse(defaults)

def getFieldValue2[A: ClassTag, A1: ClassTag, B](clazz: Class[_], field: String,
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need ClassTag ?

Copy link
Author

Choose a reason for hiding this comment

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

without ClassTag, you will get the following warnings:

abstract type pattern A is unchecked since it is eliminated by erasure
abstract type pattern A1 is unchecked since it is eliminated by erasure

so that
case v: A => mapTo(v)
case v1: A1 => mapTo1(v1)

will not match

with ClassTag, the runtime type are returned and above match will work as expected

Copy link
Member

Choose a reason for hiding this comment

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

This is not true.

Copy link
Author

Choose a reason for hiding this comment

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

Can you elaborate this ? What's not true ?

Remove the classTag and run the unit test and see yourself.

Sent from my iPhone

On Sep 2, 2014, at 11:00 PM, Prashant Sharma notifications@github.com wrote:

In yarn/common/src/test/scala/org/apache/spark/deploy/yarn/ClientBaseSuite.scala:

@@ -232,6 +233,15 @@ class ClientBaseSuite extends FunSuite with Matchers {
def getFieldValue[A, B](clazz: Class[], field: String, defaults: => B)(mapTo: A => B): B =
Try(clazz.getField(field)).map(
.get(null).asInstanceOf[A]).toOption.map(mapTo).getOrElse(defaults)

  • def getFieldValue2[A: ClassTag, A1: ClassTag, B](clazz: Class[_], field: String,
    This is not true.


Reply to this email directly or view it on GitHub.

@SparkQA
Copy link

SparkQA commented Sep 5, 2014

Can one of the admins verify this patch?

@andrewor14
Copy link
Contributor

ok to test

@SparkQA
Copy link

SparkQA commented Sep 9, 2014

QA tests have started for PR 2204 at commit 77be5d0.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Sep 9, 2014

QA tests have finished for PR 2204 at commit 77be5d0.

  • This patch fails unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@chesterxgchen
Copy link
Author

The unit test failed sql/test:test
I run it locally, with the same configuration, the test passed.

the changes is for yarn unit test, it doesn't affect the sql/test.

On Tue, Sep 9, 2014 at 10:44 AM, Apache Spark QA notifications@github.com
wrote:

QA tests have finished
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/20046/consoleFull
for PR 2204 at commit 77be5d0
77be5d0
.

  • This patch fails unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


Reply to this email directly or view it on GitHub
#2204 (comment).

@@ -232,6 +233,15 @@ class ClientBaseSuite extends FunSuite with Matchers {
def getFieldValue[A, B](clazz: Class[_], field: String, defaults: => B)(mapTo: A => B): B =
Try(clazz.getField(field)).map(_.get(null).asInstanceOf[A]).toOption.map(mapTo).getOrElse(defaults)

def getFieldValue2[A: ClassTag, A1: ClassTag, B](clazz: Class[_], field: String,
defaults: => B)
(mapTo: A => B)(mapTo1: A1 => B) : B =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you structure this as follows:

def getFieldValue[...](
    arg1: String,
    arg2: String,
    ...)(mapTo: A => B)(mapTo1: A1 => B): B = {
  Try(...)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

(the style in the rest of this file is not a great example to follow!)

… certain class fields. In this particular case, the ClientBase using reflection to to address this issue, and we need to different way to test the ClientBase's method. Original ClientBaseSuite using getFieldValue() method to do this. But it doesn't work for yarn-alpha as the API returns an array of String instead of just String (which is the case for Yarn-stable API).

 To fix the test, I add a new method

  def getFieldValue2[A: ClassTag, A1: ClassTag, B](
      clazz: Class[_],
      field: String,
      defaults: => B) (mapTo:  A => B)(mapTo1: A1 => B) : B =
    Try(clazz.getField(field)).map(_.get(null)).map {
      case v: A => mapTo(v)
      case v1: A1 => mapTo1(v1)
      case _ => defaults
    }.toOption.getOrElse(defaults)

to handle the cases where the field type can be either type A or A1. In this new method the type A or A1 is pattern matched and corresponding mapTo function (mapTo or mapTo1) is used.

Reformat based on Andrew's request
@chesterxgchen
Copy link
Author

Reformatted based on Andrew's comment #2204

@SparkQA
Copy link

SparkQA commented Sep 15, 2014

QA tests have started for PR 2204 at commit e72a6ea.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Sep 15, 2014

QA tests have finished for PR 2204 at commit e72a6ea.

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

@andrewor14
Copy link
Contributor

@tgravescs

@tgravescs
Copy link
Contributor

looks good. I tested it on hadoop 0.23 and it works also.

@asfgit asfgit closed this in 7d1a372 Sep 17, 2014
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.

6 participants