Skip to content

[SPARK-23462][SQL] improve missing field error message in StructType - #20649

Closed
xysun wants to merge 6 commits into
apache:masterfrom
xysun:SPARK-23462
Closed

[SPARK-23462][SQL] improve missing field error message in StructType#20649
xysun wants to merge 6 commits into
apache:masterfrom
xysun:SPARK-23462

Conversation

@xysun

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

@gatorsmile please review. Thanks!

@xysunxysun changed the title [SPARK-23452][SQL] improve missing field error message in StructType[SPARK-23462][SQL] improve missing field error message in StructTypeFeb 21, 2018
@gatorsmile

Copy link
Copy Markdown
Member

ok to test

@SparkQA

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

done

@SparkQA

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown

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

xysun commented Feb 28, 2018

Copy link
Copy Markdown
ContributorAuthor

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

@xysun

Copy link
Copy Markdown
ContributorAuthor

retest this please

1 similar comment
@gatorsmile

Copy link
Copy Markdown
Member

retest this please

@SparkQA

Copy link
Copy Markdown

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

xysun commented Mar 4, 2018

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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)?

@xysunxysunMar 5, 2018

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

done

@jiangxb1987

Copy link
Copy Markdown
Contributor

LGTM

@SparkQA

Copy link
Copy Markdown

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

xysun commented Mar 5, 2018

Copy link
Copy Markdown
ContributorAuthor

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

@HyukjinKwon

Copy link
Copy Markdown
Member

retest this please

@SparkQA

Copy link
Copy Markdown

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

xysun commented Mar 6, 2018

Copy link
Copy Markdown
ContributorAuthor

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

@HyukjinKwon

Copy link
Copy Markdown
Member

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

@jiangxb1987

Copy link
Copy Markdown
Contributor

LGTM, cc @gatorsmile@cloud-fan

@gatorsmile

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

done

@SparkQA

Copy link
Copy Markdown

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
Copy Markdown
Member

ping @xysun

@xysun

Copy link
Copy Markdown
ContributorAuthor

Latest code review fixes pushed. cc @HyukjinKwon

@SparkQA

Copy link
Copy Markdown

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
Copy Markdown
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 <xiayunsun@gmail.com>
Closes#20649 from xysun/SPARK-23462.
(cherry picked from commit b304e07)
Signed-off-by: hyukjinkwon <gurwls223@gmail.com>
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 <xiayunsun@gmail.com>
Closesapache#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 <xiayunsun@gmail.com>
Closesapache#20649 from xysun/SPARK-23462.
(cherry picked from commit b304e07)
Signed-off-by: hyukjinkwon <gurwls223@gmail.com>
Sign up for freeto 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

@xysun@gatorsmile@SparkQA@jiangxb1987@HyukjinKwon@kiszk@cloud-fan@mgaido91