Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class AbstractIcebergWriteExec extends IcebergWriteExec {
MAX_TARGET_FILE_SIZE_SESSION.key -> getTargetFileSizeBytes
).foreach {
case (key, value) =>
if (SQLConf.get.getConfString(key, null) != null) {
if (SQLConf.get.getConfString(key, null) == null) {
icebergProperties.put(key, value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package org.apache.gluten.execution.enhanced

import org.apache.gluten.execution._
import org.apache.gluten.tags.EnhancedFeaturesTest

import org.apache.spark.sql.{DataFrame, Row}
import org.apache.spark.sql.execution.CommandResultExec
import org.apache.spark.sql.execution.GlutenImplicits._
Expand Down Expand Up @@ -465,4 +464,68 @@ class VeloxIcebergSuite extends IcebergSuite {
)
}
}
test("iceberg native write respects target file size bytes") {
withTable("iceberg_small_target_tbl") {
spark.sql("""
|CREATE TABLE iceberg_small_target_tbl (
| id INT,
| payload STRING
|) USING iceberg
|TBLPROPERTIES (
| 'write.format.default' = 'parquet',
| 'write.parquet.compression-codec' = 'uncompressed',
| 'write.parquet.row-group-size-bytes' = '4096',
| 'write.parquet.page-size-bytes' = '1024B',
| 'write.target-file-size-bytes' = '8192'
|)
|""".stripMargin)

checkAnswer(
spark.sql("""
|SHOW TBLPROPERTIES iceberg_small_target_tbl
|('write.target-file-size-bytes')
|""".stripMargin),
Seq(Row("write.target-file-size-bytes", "8192")))

val df = spark.sql("""
|INSERT INTO iceberg_small_target_tbl
|SELECT /*+ COALESCE(1) */
| CAST(id AS INT),
| concat(
| CAST(id AS STRING),
| '-',
| sha2(CAST(id AS STRING), 256),
| '-',
| sha2(CAST(id + 1000 AS STRING), 256)
| )
|FROM range(1000)
|""".stripMargin)

val commandPlan =
df.queryExecution.executedPlan.asInstanceOf[CommandResultExec].commandPhysicalPlan

assert(commandPlan.isInstanceOf[VeloxIcebergAppendDataExec])

checkAnswer(
spark.sql("SELECT COUNT(*) FROM iceberg_small_target_tbl"),
Seq(Row(1000L)))

val files = spark.sql("""
|SELECT file_size_in_bytes
|FROM default.iceberg_small_target_tbl.files
|""".stripMargin).collect().map(_.getLong(0))

assert(files.nonEmpty)

assert(
files.length > 1,
s"Expected write.target-file-size-bytes=8192 to create multiple files, " +
s"but got files=${files.mkString("[", ", ", "]")}")

assert(
files.max < 64L * 1024L,
s"Expected small target file size to keep max file size reasonably small, " +
s"but got files=${files.mkString("[", ", ", "]")}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.gluten.execution
import org.apache.gluten.backendsapi.BackendsApiManager

import org.apache.iceberg.{FileFormat, PartitionField, PartitionSpec, Schema, TableProperties}
import org.apache.iceberg.TableProperties.{ORC_COMPRESSION, ORC_COMPRESSION_DEFAULT, PARQUET_COMPRESSION, PARQUET_COMPRESSION_DEFAULT, PARQUET_PAGE_SIZE_BYTES, PARQUET_PAGE_SIZE_BYTES_DEFAULT, WRITE_TARGET_FILE_SIZE_BYTES, WRITE_TARGET_FILE_SIZE_BYTES_DEFAULT}
import org.apache.iceberg.TableProperties.{ORC_COMPRESSION, ORC_COMPRESSION_DEFAULT, PARQUET_COMPRESSION, PARQUET_COMPRESSION_DEFAULT, PARQUET_PAGE_SIZE_BYTES, PARQUET_PAGE_SIZE_BYTES_DEFAULT}
import org.apache.iceberg.avro.AvroSchemaUtil
import org.apache.iceberg.spark.source.IcebergWriteUtil
import org.apache.iceberg.types.Type.TypeID
Expand Down Expand Up @@ -50,15 +50,14 @@ trait IcebergWriteExec extends ColumnarV2TableWriteExec {
}

protected def getParquetPageSizeBytes: String = {
val config = IcebergWriteUtil.getWriteProperty(write)
config.getOrDefault(
val tableProps = IcebergWriteUtil.getTable(write).properties()
tableProps.getOrDefault(
normalizeCapacityString(PARQUET_PAGE_SIZE_BYTES),
normalizeCapacityString(PARQUET_PAGE_SIZE_BYTES_DEFAULT.toString))
}

protected def getTargetFileSizeBytes: String = {
val config = IcebergWriteUtil.getWriteProperty(write)
config.getOrDefault(WRITE_TARGET_FILE_SIZE_BYTES, WRITE_TARGET_FILE_SIZE_BYTES_DEFAULT.toString)
IcebergWriteUtil.getWriteConf(write).targetDataFileSize().toString
}

protected def getPartitionSpec: PartitionSpec = {
Expand Down
Loading