|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.spark.sql.comet.execution.shuffle |
| 21 | + |
| 22 | +import org.apache.spark.TaskContext |
| 23 | +import org.apache.spark.sql.CometTestBase |
| 24 | +import org.apache.spark.sql.vectorized.ColumnarBatch |
| 25 | + |
| 26 | +import org.apache.comet.CometConf |
| 27 | + |
| 28 | +/** |
| 29 | + * Checks the plan [[CometNativeShuffleWriter]] hands to native code. Lives in the |
| 30 | + * `execution.shuffle` package so it can call the `private[shuffle]` `buildUnifiedPlan`. |
| 31 | + */ |
| 32 | +class CometNativeShuffleWriterSuite extends CometTestBase { |
| 33 | + |
| 34 | + import testImplicits._ |
| 35 | + |
| 36 | + test("the write buffer size reaches native code in bytes") { |
| 37 | + withSQLConf( |
| 38 | + CometConf.COMET_SHUFFLE_MODE.key -> "native", |
| 39 | + "spark.sql.adaptive.enabled" -> "false") { |
| 40 | + withParquetTable((0 until 10).map(i => (i, s"row-$i")), "tbl") { |
| 41 | + val exchange = sql("SELECT * FROM tbl") |
| 42 | + .repartition(3, $"_1") |
| 43 | + .queryExecution |
| 44 | + .executedPlan |
| 45 | + .collectFirst { case value: CometShuffleExchangeExec => value } |
| 46 | + .getOrElse(fail("Expected a native Comet shuffle exchange")) |
| 47 | + val dependency = exchange.shuffleDependency |
| 48 | + .asInstanceOf[CometShuffleDependency[Int, ColumnarBatch, ColumnarBatch]] |
| 49 | + val context: TaskContext = TaskContext.empty() |
| 50 | + |
| 51 | + // Native code sizes the writers for the data and spill files from this field, in bytes. |
| 52 | + def writeBufferSize: Int = |
| 53 | + new CometNativeShuffleWriter[Int, ColumnarBatch]( |
| 54 | + dependency.nativeShuffleSpec.get, |
| 55 | + dependency.outputPartitioning.get, |
| 56 | + dependency.outputAttributes, |
| 57 | + dependency.shuffleWriteMetrics, |
| 58 | + dependency.numParts, |
| 59 | + dependency.shuffleId, |
| 60 | + context.taskAttemptId(), |
| 61 | + context, |
| 62 | + context.taskMetrics().shuffleWriteMetrics, |
| 63 | + dependency.rangePartitionBounds) |
| 64 | + .buildUnifiedPlan("unused.data") |
| 65 | + .getShuffleWriter |
| 66 | + .getWriteBufferSize |
| 67 | + |
| 68 | + assert(writeBufferSize == 1024 * 1024) |
| 69 | + withSQLConf(CometConf.COMET_SHUFFLE_NATIVE_WRITE_BUFFER_SIZE.key -> "8m") { |
| 70 | + assert(writeBufferSize == 8 * 1024 * 1024) |
| 71 | + } |
| 72 | + // A bare number is a byte count. |
| 73 | + withSQLConf(CometConf.COMET_SHUFFLE_NATIVE_WRITE_BUFFER_SIZE.key -> "65536") { |
| 74 | + assert(writeBufferSize == 65536) |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments