This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new a9bb924480e [SPARK-40146][SQL] Simply the codegen of getting map value
a9bb924480e is described below
commit a9bb924480e4953457dad680c15ca346f71a26c8
Author: Gengliang Wang <[email protected]>
AuthorDate: Fri Aug 19 20:42:37 2022 +0900
[SPARK-40146][SQL] Simply the codegen of getting map value
### What changes were proposed in this pull request?
Simply the code generation of `GetMapValueUtil`
### Why are the changes needed?
Code generation improvement.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing UT
Closes #37580 from gengliangwang/reviseCodegen.
Authored-by: Gengliang Wang <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
.../sql/catalyst/expressions/complexTypeExtractors.scala | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
index 188baad6f11..923e4ee8ebe 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
@@ -391,21 +391,16 @@ trait GetMapValueUtil extends BinaryExpression with
ImplicitCastInputTypes {
val index = ctx.freshName("index")
val length = ctx.freshName("length")
val keys = ctx.freshName("keys")
- val found = ctx.freshName("found")
val key = ctx.freshName("key")
val values = ctx.freshName("values")
val keyType = mapType.keyType
val nullCheck = if (mapType.valueContainsNull) {
- s"""else if ($values.isNullAt($index)) {
- ${ev.isNull} = true;
- }
- """
+ s" || $values.isNullAt($index)"
} else {
""
}
val keyJavaType = CodeGenerator.javaType(keyType)
- val keyDt = ctx.addReferenceObj("keyType", keyType,
keyType.getClass.getName)
nullSafeCodeGen(ctx, ev, (eval1, eval2) => {
s"""
final int $length = $eval1.numElements();
@@ -413,19 +408,18 @@ trait GetMapValueUtil extends BinaryExpression with
ImplicitCastInputTypes {
final ArrayData $values = $eval1.valueArray();
int $index = 0;
- boolean $found = false;
- while ($index < $length && !$found) {
+ while ($index < $length) {
final $keyJavaType $key = ${CodeGenerator.getValue(keys, keyType,
index)};
if (${ctx.genEqual(keyType, key, eval2)}) {
- $found = true;
+ break;
} else {
$index++;
}
}
- if (!$found) {
+ if ($index == $length$nullCheck) {
${ev.isNull} = true;
- } $nullCheck else {
+ } else {
${ev.value} = ${CodeGenerator.getValue(values, dataType, index)};
}
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]