-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
[SPARK-23546][SQL] Refactor stateless methods/values in CodegenContext #20700
Conversation
@@ -773,7 +773,7 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String | |||
| ${if (i != 0) s"""$buffer.append(" ");""" else ""} | |||
| | |||
| // Append $i field into the string buffer | |||
| ${ctx.javaType(ft)} $field = ${ctx.getValue(row, ft, s"$i")}; | |||
| ${ctx.javaType(ft)} $field = ${CodeGenerator.getValue(row, ft, s"$i")}; |
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.
Some methods that are very frequently used (e.g. ctx.javaType()
) are not refactored yet. This is because this refactoring updates more files.
Test build #87828 has finished for PR 20700 at commit
|
Test build #87832 has finished for PR 20700 at commit
|
Test build #87835 has finished for PR 20700 at commit
|
Test build #87837 has finished for PR 20700 at commit
|
I like this approach. Let's see others' opinion, but it seems a good thing to do up to me. |
@mgaido91 thanks. Let me ping @cloud-fan and @viirya |
@@ -1524,4 +1348,215 @@ object CodeGenerator extends Logging { | |||
result | |||
} | |||
}) | |||
|
|||
final val JAVA_BOOLEAN = "boolean" |
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.
Is this normally spaced?
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.
Seems fine to me.
final val JAVA_FLOAT = "float" | ||
final val JAVA_DOUBLE = "double" | ||
/** | ||
* Returns true if the Java type has a special accessor and setter in [[InternalRow]]. |
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 comment is copied. But seems not totally correct. InternalRow
also has special accessor for Decimal
. But it is not a primitive type here.
val getValueMapKeyArray0 = CodeGenerator.getValue(s"$map.keyArray()", kt, "0") | ||
val getValueMapValArray0 = CodeGenerator.getValue(s"$map.valueArray()", vt, "0") | ||
val getValueMapKeyArray = CodeGenerator.getValue(s"$map.keyArray()", kt, loopIndex) | ||
val getValueMapValArray = CodeGenerator.getValue(s"$map.valueArray()", vt, loopIndex) |
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.
getMapKeyArray
and getMapValueArray
@@ -734,23 +734,26 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String | |||
val keyToStringFunc = dataToStringFunc("keyToString", kt) | |||
val valueToStringFunc = dataToStringFunc("valueToString", vt) | |||
val loopIndex = ctx.freshName("loopIndex") | |||
val getValueMapKeyArray0 = CodeGenerator.getValue(s"$map.keyArray()", kt, "0") | |||
val getValueMapValArray0 = CodeGenerator.getValue(s"$map.valueArray()", vt, "0") |
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.
getMapFirstKey
and getMapFirstValue
${javaType(elementType)} $elementA = ${getValue("a", elementType, "i")}; | ||
${javaType(elementType)} $elementB = ${getValue("b", elementType, "i")}; | ||
$jt $elementA = ${CodeGenerator.getValue("a", elementType, "i")}; | ||
$jt $elementB = ${CodeGenerator.getValue("b", elementType, "i")}; |
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.
Inside CodegenContext
, I think we can just do import CodeGenerator._
.
Test build #87881 has finished for PR 20700 at commit
|
Aha! Thanks @kiszk san for working on this! I really wanted the stateless methods to be extracted so that I can use more utils without having to pass around a I was actually working on the exact same thing last week but got carried away on other tasks so my patch is still WIP. I was hoping we can cover the ones I extracted here: rednaxelafx@249fb93#diff-8bcc5aea39c73d4bf38aef6f6951d42cR1201 The approach is different, though. I'd like to have a discussion on the tradeoffs you had in mind when you picked your approach. @kiszk WDYT? Were you intending to minimize the diff but still want to be able to access the stateless util methods as standalone functions? |
@rednaxelafx Oh, very interesting since we are doing the similar thing in West coast and Japan! I just say |
Test build #87886 has finished for PR 20700 at commit
|
Test build #87887 has finished for PR 20700 at commit
|
Test build #87889 has finished for PR 20700 at commit
|
Test build #87894 has finished for PR 20700 at commit
|
Test build #87897 has finished for PR 20700 at commit
|
Test build #87899 has finished for PR 20700 at commit
|
@rednaxelafx thanks, I integrated some of your changes into PR. |
@kiszk can you update the PR 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.
LGTM - as stated before update the description and then we should be gtg.
Good catch. I removed the old statement from the description. |
Merging to master. Thanks! |
I am having some problems with the merge script, give me a little bit of time. |
a late LGTM :) |
What changes were proposed in this pull request?
A current
CodegenContext
class has immutable value or method without mutable state, too.This refactoring moves them to
CodeGenerator
object class which can be accessed from anywhere without an instantiatedCodegenContext
in the program.How was this patch tested?
Existing tests