From ca1ba0cb5a38b17f6eace79be4d965167fcd44a8 Mon Sep 17 00:00:00 2001 From: Haoyang Li Date: Fri, 13 Dec 2024 15:22:39 +0800 Subject: [PATCH] foreach Signed-off-by: Haoyang Li --- .../spark/sql/rapids/stringFunctions.scala | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 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 10960cbe2ad..b026aa2ae9d 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,10 +1247,26 @@ case class GpuContainsAny(input: Expression, targets: Seq[UTF8String]) val boolCvs = withResource(ColumnVector.fromUTF8Strings(targetsBytes: _*)) { targetsCv => input.getBase.stringContains(targetsCv) } - withResource(boolCvs.tail) { _ => - // boolCvs.head and intermediate values are closed within the withResource in the lambda - boolCvs.tail.foldLeft(boolCvs.head)((l, r) => withResource(l) { _ => l.or(r)}) + // withResource(boolCvs.tail) { _ => + // // boolCvs.head and intermediate values are closed within the withResource in the lambda + // boolCvs.tail.foldLeft(boolCvs.head)((l, r) => withResource(l) { _ => l.or(r)}) + // } + var ret: ColumnVector = null + closeOnExcept(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 } }