Skip to content

Conversation

@xysun
Copy link
Contributor

@xysun xysun commented Feb 21, 2018

What changes were proposed in this pull request?

The error message s"""Field "$name" does not exist.""" is thrown when looking up an unknown field in StructType. In the error message, we should also contain the information about which columns/fields exist in this struct.

How was this patch tested?

Added new unit tests.

Note: I created a new StructTypeSuite.scala as I couldn't find an existing suite that's suitable to place these tests. I may be missing something so feel free to propose new locations.

Please review http://spark.apache.org/contributing.html before opening a pull request.

@xysun
Copy link
Contributor Author

xysun commented Feb 21, 2018

@gatorsmile please review. Thanks!

@xysun xysun changed the title [SPARK-23452][SQL] improve missing field error message in StructType [SPARK-23462][SQL] improve missing field error message in StructType Feb 21, 2018
@gatorsmile
Copy link
Member

ok to test

@SparkQA
Copy link

SparkQA commented Feb 22, 2018

Test build #87599 has finished for PR 20649 at commit e1a5ccf.

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

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.types.StructType

class StructTypeSuite extends SparkFunSuite{
Copy link
Member

Choose a reason for hiding this comment

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

Add a space before {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

class StructTypeSuite extends SparkFunSuite{

test("SPARK-23462 lookup a single missing field should output existing fields") {
val s = StructType.fromDDL("a INT")
Copy link
Member

Choose a reason for hiding this comment

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

add one more column?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@SparkQA
Copy link

SparkQA commented Feb 22, 2018

Test build #87608 has finished for PR 20649 at commit 22f89f8.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class StructTypeSuite extends SparkFunSuite

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.types.StructType

class StructTypeSuite extends SparkFunSuite {
Copy link
Member

Choose a reason for hiding this comment

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

Could we put this file under sql/catalyst/src/test/scala/org/apache/spark/sql/types or move the test cases into DataTypeSuite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved

throw new IllegalArgumentException(s"""Field "$name" does not exist."""))
throw new IllegalArgumentException(
s"""Field "$name" does not exist.
|Available fields: ${fieldNamesSet.mkString(",")}""".stripMargin))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we add a space after the comma? I think it can help readability

throw new IllegalArgumentException(
s"Field ${nonExistFields.mkString(",")} does not exist.")
s"""Fields ${nonExistFields.mkString(",")} does not exist.
|Available fields: ${fieldNamesSet.mkString(",")}""".stripMargin)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

if (nonExistFields.nonEmpty) {
throw new IllegalArgumentException(
s"Field ${nonExistFields.mkString(",")} does not exist.")
s"""Fields ${nonExistFields.mkString(",")} does not exist.
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

throw new IllegalArgumentException(s"""Field "$name" does not exist."""))
throw new IllegalArgumentException(
s"""Field "$name" does not exist.
|Available fields: ${fieldNamesSet.mkString(",")}""".stripMargin))
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

val e = intercept[IllegalArgumentException](s.fieldIndex("c")).getMessage
assert(e.contains("Available fields: a,b"))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this empty line should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all done


class StructTypeSuite extends SparkFunSuite {

test("SPARK-23462 lookup a single missing field should output existing fields") {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Would it be better to combine these three tests into one? It could reduce the total test time.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a bug fix, so please don't include the JIRA number in the test case description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed JIRA number.
@kiszk i still prefer to keep separate tests as they are calling separate methods. Let me know if you feel strongly against it.

@SparkQA
Copy link

SparkQA commented Feb 28, 2018

Test build #87759 has finished for PR 20649 at commit 8cdb1d5.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class StructTypeSuite extends SparkFunSuite

@xysun
Copy link
Contributor Author

xysun commented Feb 28, 2018

I'm getting some weird compile errors on local even when based off previous successful commit.. checking..

@xysun
Copy link
Contributor Author

xysun commented Feb 28, 2018

retest this please

1 similar comment
@gatorsmile
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Feb 28, 2018

Test build #87792 has finished for PR 20649 at commit 8cdb1d5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class StructTypeSuite extends SparkFunSuite

@xysun
Copy link
Contributor Author

xysun commented Mar 4, 2018

hey @gatorsmile @kiszk @jiangxb1987 @HyukjinKwon @mgaido91 any more comments?

if (nonExistFields.nonEmpty) {
throw new IllegalArgumentException(
s"Field ${nonExistFields.mkString(",")} does not exist.")
s"""Fields ${nonExistFields.mkString(", ")} does not exist.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: nonExistFields can contain only one field, so maybe Fields -> Field(s)?

Copy link
Contributor Author

@xysun xysun Mar 5, 2018

Choose a reason for hiding this comment

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

"Field(s) ... do(es) not exist." like this? A bit weird...
maybe just "Fields ... do not exist"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not existing field(s): ${nonExistFields.mkString(", ")} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jiangxb1987
Copy link
Contributor

LGTM

@SparkQA
Copy link

SparkQA commented Mar 5, 2018

Test build #87952 has finished for PR 20649 at commit b2d1888.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@xysun
Copy link
Contributor Author

xysun commented Mar 5, 2018

:( can anyone help issue the retest command? @mgaido91 @gatorsmile thanks!

@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Mar 5, 2018

Test build #87953 has finished for PR 20649 at commit b2d1888.

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

@xysun
Copy link
Contributor Author

xysun commented Mar 6, 2018

hey @HyukjinKwon @gatorsmile @mgaido91 anything else you'd like to comment/change? else are we good to merge?
Thanks!

@HyukjinKwon
Copy link
Member

I usually leave open it for few more days in case other reviewers have some more review comments.

@jiangxb1987
Copy link
Contributor

LGTM, cc @gatorsmile @cloud-fan

@gatorsmile
Copy link
Member

retest this please

throw new IllegalArgumentException(s"""Field "$name" does not exist."""))
throw new IllegalArgumentException(
s"""Field "$name" does not exist.
|Available fields: ${fieldNamesSet.mkString(", ")}""".stripMargin))
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we use fieldNames to keep the field order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@SparkQA
Copy link

SparkQA commented Mar 8, 2018

Test build #88076 has finished for PR 20649 at commit b2d1888.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

ping @xysun

@xysun
Copy link
Contributor Author

xysun commented Mar 12, 2018

Latest code review fixes pushed. cc @HyukjinKwon

@SparkQA
Copy link

SparkQA commented Mar 12, 2018

Test build #88166 has finished for PR 20649 at commit 78e037d.

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

@HyukjinKwon
Copy link
Member

Merged to master and branch-2.3.

asfgit pushed a commit that referenced this pull request Mar 12, 2018
## What changes were proposed in this pull request?

The error message ```s"""Field "$name" does not exist."""``` is thrown when looking up an unknown field in StructType. In the error message, we should also contain the information about which columns/fields exist in this struct.

## How was this patch tested?

Added new unit tests.

Note: I created a new `StructTypeSuite.scala` as I couldn't find an existing suite that's suitable to place these tests. I may be missing something so feel free to propose new locations.

Please review http://spark.apache.org/contributing.html before opening a pull request.

Author: Xiayun Sun <[email protected]>

Closes #20649 from xysun/SPARK-23462.

(cherry picked from commit b304e07)
Signed-off-by: hyukjinkwon <[email protected]>
@asfgit asfgit closed this in b304e07 Mar 12, 2018
mstewart141 pushed a commit to mstewart141/spark that referenced this pull request Mar 24, 2018
## What changes were proposed in this pull request?

The error message ```s"""Field "$name" does not exist."""``` is thrown when looking up an unknown field in StructType. In the error message, we should also contain the information about which columns/fields exist in this struct.

## How was this patch tested?

Added new unit tests.

Note: I created a new `StructTypeSuite.scala` as I couldn't find an existing suite that's suitable to place these tests. I may be missing something so feel free to propose new locations.

Please review http://spark.apache.org/contributing.html before opening a pull request.

Author: Xiayun Sun <[email protected]>

Closes apache#20649 from xysun/SPARK-23462.
peter-toth pushed a commit to peter-toth/spark that referenced this pull request Oct 6, 2018
## What changes were proposed in this pull request?

The error message ```s"""Field "$name" does not exist."""``` is thrown when looking up an unknown field in StructType. In the error message, we should also contain the information about which columns/fields exist in this struct.

## How was this patch tested?

Added new unit tests.

Note: I created a new `StructTypeSuite.scala` as I couldn't find an existing suite that's suitable to place these tests. I may be missing something so feel free to propose new locations.

Please review http://spark.apache.org/contributing.html before opening a pull request.

Author: Xiayun Sun <[email protected]>

Closes apache#20649 from xysun/SPARK-23462.

(cherry picked from commit b304e07)
Signed-off-by: hyukjinkwon <[email protected]>
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.

8 participants