Skip to content

Fixing a scala compilation problem #1855

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

Merged
merged 2 commits into from
Jan 6, 2022

Conversation

masseyke
Copy link
Member

@masseyke masseyke commented Jan 6, 2022

The code in ScalaValueWriter::doWriteScala was not compiling on the 7.17 branch. The problem is that the () reference to Unit was confusing the compiler. This commit makes the reference to Unit more explicit, and adds a test to make sure that Unit is being handled as expected.

@masseyke
Copy link
Member Author

masseyke commented Jan 6, 2022

Specifically, this was failing on the 7.17 branch:

./gradlew :elasticsearch-spark-13:assemble

Copy link
Member

@jbaiera jbaiera left a comment

Choose a reason for hiding this comment

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

LGTM, minor nit and optional simplification

case Some(None) => false
case Some(_) => true
case None => true
case _ => false
Copy link
Member

Choose a reason for hiding this comment

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

Is the catch all needed here? This confused me for a second

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops good point!

@@ -61,7 +61,14 @@ class ScalaValueWriter(writeUnknownTypes: Boolean = false) extends JdkValueWrite
generator.writeBeginObject()
for ((k, v) <- m) {
if (shouldKeep(parentField, k.toString)) {
if (v != None && v!= null && v != () || hasWriteNullValues) {
val nonEmptyValue = Option(v) match {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val nonEmptyValue = Option(v) match {
val hasValue = Option(v) match {

Can we swap the variable name? nonEmptyValue=false reads weird in my head

case None => true
case _ => false
}
if (nonEmptyValue || hasWriteNullValues) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (nonEmptyValue || hasWriteNullValues) {
if (hasValue || hasWriteNullValues) {

If applying above suggestion

@masseyke masseyke merged commit 2a63ea1 into elastic:master Jan 6, 2022
@masseyke
Copy link
Member Author

masseyke commented Jan 6, 2022

Relates #1478

@masseyke masseyke deleted the fix/scala-compilation-problem branch January 6, 2022 19:54
masseyke added a commit to masseyke/elasticsearch-hadoop that referenced this pull request Jan 6, 2022
Fixing a scala compilation problem that happened with certain scala compilers.
masseyke added a commit to masseyke/elasticsearch-hadoop that referenced this pull request Jan 6, 2022
Fixing a scala compilation problem that happened with certain scala compilers.
masseyke added a commit that referenced this pull request Jan 6, 2022
Fixing a scala compilation problem that happened with certain scala compilers.
masseyke added a commit that referenced this pull request Jan 6, 2022
Fixing a scala compilation problem that happened with certain scala compilers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants