Skip to content
Draft
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 @@ -475,75 +475,72 @@ class VeloxIcebergSuite extends IcebergSuite {
)
}
}
ignore("disabled test") {
test("iceberg native write respects target file size bytes") {
withTable("iceberg_small_target_tbl") {
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.page-size-bytes' = '1024B',
| 'write.target-file-size-bytes' = '8192'
|)
|""".stripMargin)

checkAnswer(
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"))
)
|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 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
val commandPlan =
df.queryExecution.executedPlan.asInstanceOf[CommandResultExec].commandPhysicalPlan

assert(commandPlan.isInstanceOf[VeloxIcebergAppendDataExec])
assert(commandPlan.isInstanceOf[VeloxIcebergAppendDataExec])

checkAnswer(
spark.sql("SELECT COUNT(*) FROM iceberg_small_target_tbl"),
Seq(Row(1000L)))
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))
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.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.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("[", ", ", "]")}")
}
assert(
files.max < 64L * 1024L,
s"Expected small target file size to keep max file size reasonably small, " +
s"but got files=${files.mkString("[", ", ", "]")}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/velox/utils/ConfigExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ std::shared_ptr<facebook::velox::config::ConfigBase> createHiveConnectorSessionC
configs[facebook::velox::connector::hive::HiveConfig::kReadTimestampUnitSession] = std::string("6");
configs[facebook::velox::connector::hive::HiveConfig::kMaxPartitionsPerWritersSession] =
conf->get<std::string>(kMaxPartitions, "10000");
configs[facebook::velox::connector::hive::HiveConfig::kParquetMaxTargetFileSize] =
configs[facebook::velox::connector::hive::HiveConfig::kParquetMaxTargetFileSizeSession] =
conf->get<std::string>(kParquetMaxTargetFileSize, "0B"); // 0 means no limit on target file size
configs[facebook::velox::connector::hive::HiveConfig::kIgnoreMissingFilesSession] =
conf->get<bool>(kIgnoreMissingFiles, false) ? "true" : "false";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ trait IcebergWriteExec extends ColumnarV2TableWriteExec {
}

protected def getTargetFileSizeBytes: String = {
IcebergWriteUtil.getWriteConf(write).targetDataFileSize().toString
normalizeCapacityString(IcebergWriteUtil.getWriteConf(write).targetDataFileSize().toString)
}

protected def getDictSizeBytes: String = {
Expand Down
Loading