-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23462][SQL] improve missing field error message in StructType
#20649
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
Conversation
|
@gatorsmile please review. Thanks! |
StructTypeStructType
|
ok to test |
|
Test build #87599 has finished for PR 20649 at commit
|
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
||
| class StructTypeSuite extends SparkFunSuite{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space before {
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add one more column?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
Test build #87608 has finished for PR 20649 at commit
|
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
||
| class StructTypeSuite extends SparkFunSuite { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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")) | ||
| } | ||
|
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Test build #87759 has finished for PR 20649 at commit
|
|
|
|
retest this please |
1 similar comment
|
retest this please |
|
Test build #87792 has finished for PR 20649 at commit
|
|
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. |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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(", ")} ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
LGTM |
|
Test build #87952 has finished for PR 20649 at commit
|
|
:( can anyone help issue the retest command? @mgaido91 @gatorsmile thanks! |
|
retest this please |
|
Test build #87953 has finished for PR 20649 at commit
|
|
hey @HyukjinKwon @gatorsmile @mgaido91 anything else you'd like to comment/change? else are we good to merge? |
|
I usually leave open it for few more days in case other reviewers have some more review comments. |
|
LGTM, cc @gatorsmile @cloud-fan |
|
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
Test build #88076 has finished for PR 20649 at commit
|
|
ping @xysun |
|
Latest code review fixes pushed. cc @HyukjinKwon |
|
Test build #88166 has finished for PR 20649 at commit
|
|
Merged to master and branch-2.3. |
## 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]>
## 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.
## 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]>
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.scalaas 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.