From c8b89221b6cb95c56155a703b020487c11f91e92 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Tue, 12 Nov 2024 14:54:59 +0800 Subject: [PATCH] [KYUUBI #6786] Skip repeated checks on convert function in TColumnGenerator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description ## Issue References ๐Ÿ”— This pull request fixes # ## Describe Your Solution ๐Ÿ”ง - `TColumnGenerator` is used for generating column-based data. This PR skips repeated checks on checking nullability of the convert function in generating single column. ## Types of changes :bookmark: - [ ] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐Ÿงช #### Behavior Without This Pull Request :coffin: #### Behavior With This Pull Request :tada: #### Related Unit Tests --- # Checklist ๐Ÿ“ - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6786 from bowenliang123/skip-converfunc-check. Closes #6786 f76f6864a [Bowen Liang] nit 930dfef3a [Bowen Liang] fix 9712274e3 [Bowen Liang] comment 9db16ef6b [Bowen Liang] nit 977d21533 [Bowen Liang] skip repeated checking on convert function Authored-by: Bowen Liang Signed-off-by: Bowen Liang --- .../kyuubi/engine/result/TColumnGenerator.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/engine/result/TColumnGenerator.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/engine/result/TColumnGenerator.scala index 7326e5a3d17..5a2acd0bdd7 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/engine/result/TColumnGenerator.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/engine/result/TColumnGenerator.scala @@ -34,18 +34,17 @@ trait TColumnGenerator[RowT] extends TRowSetColumnGetter[RowT] { val ret = new JArrayList[T](rowSize) val nulls = new JBitSet() var idx = 0 + val isConvertFuncNull = convertFunc == null rows.foreach { row => - val isNull = isColumnNullAt(row, ordinal) - if (isNull) { + val value = if (isColumnNullAt(row, ordinal)) { nulls.set(idx, true) - ret.add(defaultVal) + defaultVal + } else if (isConvertFuncNull) { + getColumnAs[T](row, ordinal) } else { - val value = Option(convertFunc) match { - case Some(f) => f(row, ordinal) - case _ => getColumnAs[T](row, ordinal) - } - ret.add(value) + convertFunc(row, ordinal) } + ret.add(value) idx += 1 } (ret, ByteBuffer.wrap(nulls.toByteArray))