hvanhovell commented on code in PR #40628: URL: https://github.com/apache/spark/pull/40628#discussion_r1156364194
########## connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/UdfUtils.scala: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.connect.client + +import scala.collection.JavaConverters._ + +import org.apache.spark.api.java.function._ + +/** + * Util functions to help convert input functions between typed filter, map, flatMap, + * mapPartitions etc. These functions cannot be defined inside the client Dataset class as it will + * cause Dataset sync conflicts when used together with UDFs. Thus we define them outside, in the + * client package. + */ +private[sql] object UdfUtils { + + def mapFuncToMapPartitionsAdaptor[T, U](f: T => U): Iterator[T] => Iterator[U] = _.map(f(_)) + + def foreachFuncToForeachPartitionsAdaptor[T](f: T => Unit): Iterator[T] => Unit = + _.foreach(f(_)) + + def foreachPartitionFuncToMapPartitionsAdaptor[T]( + f: Iterator[T] => Unit): Iterator[T] => Iterator[Boolean] = x => { + f(x) + // The return constructs a minimal return iterator for mapPartitions + Iterator(true) Review Comment: Return an empty iterator? There is not point in sending anything here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
