From 4f33192b366cf314a1b672c54376ff51845c3751 Mon Sep 17 00:00:00 2001 From: Haoyang Li Date: Fri, 13 Dec 2024 23:28:19 +0800 Subject: [PATCH] withResource Signed-off-by: Haoyang Li --- .../spark/sql/rapids/stringFunctions.scala | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/stringFunctions.scala b/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/stringFunctions.scala index b27d30506f8..7db9ade5746 100644 --- a/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/stringFunctions.scala +++ b/sql-plugin/src/main/scala/org/apache/spark/sql/rapids/stringFunctions.scala @@ -1247,15 +1247,22 @@ case class GpuContainsAny(input: Expression, targets: Seq[UTF8String]) val boolCvs = withResource(ColumnVector.fromUTF8Strings(targetsBytes: _*)) { targetsCv => input.getBase.stringContains(targetsCv) } - closeOnExcept(boolCvs.tail) { _ => - boolCvs.tail.foldLeft(boolCvs.head) { - (l, r) => withResource(l) { _ => - withResource(r) { _ => - l.or(r) - } + var ret: ColumnVector = null + withResource(boolCvs) { _ => + boolCvs.indices.foreach { i => + if (ret == null) { + ret = boolCvs(i) + boolCvs(i) = null + } else { + val tmp = ret.or(boolCvs(i)) + ret.close() + ret = tmp + boolCvs(i).close() + boolCvs(i) = null } } } + ret } }