infvg commented on code in PR #12699: URL: https://github.com/apache/gluten/pull/12699#discussion_r3721233292
########## backends-velox/src-iceberg/test/scala/org/apache/gluten/extension/OffloadIcebergWriteSuite.scala: ########## @@ -0,0 +1,63 @@ +/* + * 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.gluten.extension + +import org.apache.gluten.config.GlutenIcebergConfig + +import org.apache.spark.sql.catalyst.expressions.Attribute +import org.apache.spark.sql.execution.{LeafExecNode, SparkPlan} +import org.apache.spark.sql.internal.SQLConf + +import org.scalatest.funsuite.AnyFunSuite + +class OffloadIcebergWriteSuite extends AnyFunSuite { + + private case class DummyPlan() extends LeafExecNode { + override def output: Seq[Attribute] = Seq.empty + override protected def doExecute() = throw new UnsupportedOperationException() + } + + private case class OffloadedPlan() extends LeafExecNode { + override def output: Seq[Attribute] = Seq.empty + override protected def doExecute() = throw new UnsupportedOperationException() + } + + /** Offloads unconditionally, so the only thing that can stop it is the config gate. */ + private case class AlwaysOffload() extends OffloadIcebergWriteBase { + override protected def offloadWrite(plan: SparkPlan): SparkPlan = OffloadedPlan() + } + + private def withNativeWrite[T](enabled: Boolean)(body: => T): T = { + val conf = SQLConf.get + val key = GlutenIcebergConfig.ENABLE_NATIVE_WRITE.key + conf.setConfString(key, enabled.toString) + try body + finally conf.unsetConf(key) + } + + test("write offload rules skip offloading when native write is disabled") { Review Comment: There's already integration tests for this in VeloxIcebergSuite, we can remove this class. ########## gluten-iceberg/src/main/scala/org/apache/gluten/extension/OffloadIcebergScan.scala: ########## @@ -26,8 +26,23 @@ import org.apache.gluten.extension.injector.Injector import org.apache.spark.sql.execution.SparkPlan import org.apache.spark.sql.execution.datasources.v2.BatchScanExec -case class OffloadIcebergScan() extends OffloadSingleNode { - override def offload(plan: SparkPlan): SparkPlan = plan match { +/** + * Base of the Iceberg scan offload rule. The switch is checked here rather than at rule injection + * time so that it stays modifiable at runtime. + */ +trait OffloadIcebergScanBase extends OffloadSingleNode { Review Comment: This abstraction isn't necessary IMO, we can just move the logic to OffloadIcebergScan ########## gluten-iceberg/src/test/scala/org/apache/gluten/extension/OffloadIcebergScanSuite.scala: ########## @@ -0,0 +1,73 @@ +/* + * 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.gluten.extension + +import org.apache.gluten.config.GlutenIcebergConfig + +import org.apache.spark.sql.catalyst.expressions.Attribute +import org.apache.spark.sql.execution.{LeafExecNode, SparkPlan} +import org.apache.spark.sql.internal.SQLConf + +import org.scalatest.funsuite.AnyFunSuite + +class OffloadIcebergScanSuite extends AnyFunSuite { + + private case class DummyPlan() extends LeafExecNode { + override def output: Seq[Attribute] = Seq.empty + override protected def doExecute() = throw new UnsupportedOperationException() + } + + private case class OffloadedPlan() extends LeafExecNode { + override def output: Seq[Attribute] = Seq.empty + override protected def doExecute() = throw new UnsupportedOperationException() + } + + /** Offloads unconditionally, so the only thing that can stop it is the config gate. */ + private case class AlwaysOffload() extends OffloadIcebergScanBase { + override protected def offloadScan(plan: SparkPlan): SparkPlan = OffloadedPlan() + } + + private def withNativeRead[T](enabled: Boolean)(body: => T): T = { + val conf = SQLConf.get + val key = GlutenIcebergConfig.ENABLE_NATIVE_READ.key + conf.setConfString(key, enabled.toString) + try body + finally conf.unsetConf(key) + } + + test("scan offload rule skips offloading when native read is disabled") { Review Comment: The integration tests in IcebergSuite already test this, we can remove this class IMO -- 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]
