pvary commented on code in PR #18709:
URL: https://github.com/apache/iceberg/pull/18709#discussion_r4535408858
##########
spark/v4.2/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java:
##########
@@ -44,6 +61,180 @@ public class TestSparkReadMetrics extends
TestBaseWithCatalog {
@AfterEach
public void removeTables() {
sql("DROP TABLE IF EXISTS %s", tableName);
+ sql("DROP TABLE IF EXISTS dim");
+ }
+
+ @TestTemplate
+ void effectiveSplitTargetSize() throws NoSuchTableException, IOException {
+ long tableSplitSize = 128L * 1024 * 1024;
+ long optionSplitSize = 32L * 1024 * 1024;
+ int parallelism = 1000;
+ sql(
+ "CREATE TABLE %s (id BIGINT) USING iceberg TBLPROPERTIES
('read.split.target-size'='%s')",
+ tableName, tableSplitSize);
+ spark.range(100).coalesce(1).writeTo(tableName).append();
+
+ long scanSize = 0;
+ try (CloseableIterable<FileScanTask> tasks =
+ validationCatalog.loadTable(tableIdent).newScan().planFiles()) {
+ for (FileScanTask task : tasks) {
+ scanSize += task.sizeBytes();
+ }
+ }
+ long adaptiveSplitSize = TableScanUtil.adjustSplitSize(scanSize,
parallelism, tableSplitSize);
+ assertThat(adaptiveSplitSize).isNotEqualTo(tableSplitSize);
+
+ // adaptive sizing lowers the table target for a small scan
+ withSQLConf(
+ ImmutableMap.of(
+ SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_ENABLED,
+ "true",
+ SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_PARALLELISM,
+ String.valueOf(parallelism)),
+ () -> {
+ Dataset<Row> df = spark.sql(String.format("SELECT * FROM %s",
tableName));
+ df.collect();
+ SparkPlan scan =
df.queryExecution().executedPlan().collectLeaves().head();
+
assertThat(scan.metrics().get("effectiveSplitTargetSize").get().value())
+ .isEqualTo(adaptiveSplitSize);
+ });
+
+ // without adaptive sizing, the table property is the target
+ withSQLConf(
+ ImmutableMap.of(SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_ENABLED,
"false"),
+ () -> {
+ Dataset<Row> df = spark.sql(String.format("SELECT * FROM %s",
tableName));
+ df.collect();
+ SparkPlan scan =
df.queryExecution().executedPlan().collectLeaves().head();
+
assertThat(scan.metrics().get("effectiveSplitTargetSize").get().value())
+ .isEqualTo(tableSplitSize);
+ });
+
+ // an explicit read option is used as is, even with adaptive sizing enabled
+ withSQLConf(
+ ImmutableMap.of(SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_ENABLED,
"true"),
+ () -> {
+ Dataset<Row> df =
+ spark
+ .read()
+ .format("iceberg")
+ .option(SparkReadOptions.SPLIT_SIZE,
String.valueOf(optionSplitSize))
+ .load(tableName);
+ df.collect();
+ SparkPlan scan =
df.queryExecution().executedPlan().collectLeaves().head();
+
assertThat(scan.metrics().get("effectiveSplitTargetSize").get().value())
+ .isEqualTo(optionSplitSize);
+ });
+ }
+
+ @TestTemplate
+ void effectiveSplitTargetSizeWithoutSnapshot() {
+ sql("CREATE TABLE %s (id BIGINT) USING iceberg", tableName);
+
+ // no task groups are planned for a table without a snapshot
+ Dataset<Row> df = spark.sql(String.format("SELECT * FROM %s", tableName));
+ df.collect();
+ SparkPlan scan = df.queryExecution().executedPlan().collectLeaves().head();
+
assertThat(scan.metrics().get("effectiveSplitTargetSize").get().value()).isZero();
+ }
+
+ @TestTemplate
+ void effectiveSplitTargetSizeWithRuntimeFilter() throws
NoSuchTableException, IOException {
Review Comment:
Both values check the value on 16 MB here, so this test passes even if the
metric keeps the stale pre-filter value. Should we check that it actually
changes after the runtime filter re-plans? For example, use large fake data
files so the value is 64 MB before the filter and 32 MB after.
--
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]