comphead commented on code in PR #7775:
URL: https://github.com/apache/datafusion-comet/pull/7775#discussion_r4743963926
##########
native/core/src/execution/operators/iceberg_write.rs:
##########
@@ -1028,10 +1031,16 @@ async fn run_write_task(
.fields()
.iter()
.any(|field| float_in_container(field.data_type()));
- let properties =
Arc::new(PartitionProperties::new(DictionaryChooser::try_new(
- writer_properties,
- &target_schema,
- )?));
+ let chooser = if common
+ .parquet_settings
+ .as_ref()
+ .is_some_and(|s| !s.dictionary_enabled)
+ {
+ DictionaryChooser::disabled(writer_properties)
+ } else {
+ DictionaryChooser::try_new(writer_properties, &target_schema)?
+ };
Review Comment:
This branch and the plumbing behind it look unnecessary.
`DictionaryChooser::try_new` only creates a `Candidate` when
`base.dictionary_enabled(path)` is true (`iceberg_dictionary.rs`, the
`base.dictionary_enabled(path).then(...)` line), and `build_writer_properties`
now sets it globally, so `try_new` already yields an empty `candidates`.
`wants_more` is then false, the first `push` releases the held batch at once,
and `choose` returns `base`. The PR's own test
`disabled_chooser_has_no_choices_and_returns_base` asserts exactly this for
`try_new`. I did not run it. The smallest change is the gate removal, the proto
field and `set_dictionary_enabled`. Then `DictionaryChooser::disabled`,
`has_choices`, the `choose` early return, the `take` short circuit and the new
`hold_for_dictionary` argument on `PartitionFeed::new` (three call sites) can
go. As written they also change the hold path for any schema with no dictionary
candidates (all boolean or fixed length columns), which is outsid
e this PR.
##########
native/proto/src/proto/operator.proto:
##########
@@ -835,6 +835,8 @@ message IcebergParquetWriteSettings {
// String written into parquet file metadata. JVM-side default is
// `"Apache Iceberg <ver> (Comet)"`.
string created_by = 7;
+ // Iceberg `parquet.enable.dictionary` (default true).
+ bool dictionary_enabled = 8;
Review Comment:
https://github.com/apache/datafusion-comet/pull/7776 adds field number 8
(`column_index_truncate_length`) to this same message, and `git merge-tree` on
the two heads conflicts in `operator.proto`, `iceberg_write.rs`,
`CometIcebergNativeWrite.scala`, `IcebergWriteProtoTranslation.scala`,
`iceberg.md` and two test suites. Whichever lands second has to renumber its
field to 9, and the same-number clash would not be caught by a textual merge if
someone resolves it by keeping both. A typed field per setting matches the
existing message (compression, sizes, page limits), and the gate still has to
vet values on the JVM, so I would not move these into a generic key/value map.
It is worth agreeing the merge order and the field numbers between the two PRs.
##########
spark/src/test/scala/org/apache/comet/CometIcebergWriteDetectionSuite.scala:
##########
@@ -582,13 +582,66 @@ class CometIcebergWriteDetectionSuite extends
CometTestBase with CometIcebergTes
}
}
- test("fall-back: parquet.enable.dictionary set") {
+ test("Compatible when parquet.enable.dictionary is set as a table property
or write option") {
+ withDetectionCatalog { _ =>
+ Seq("false", "true", "FALSE", "invalid").zipWithIndex.foreach { case
(value, i) =>
+ val table = s"enable_dict_$i"
+ createTable(
+ table,
+ partitionSpec = "",
+ properties = Some(s"'parquet.enable.dictionary'='$value'"))
+ assertSupportLevelIs[Compatible](table)
+ }
+ createTable("enable_dict_option", partitionSpec = "")
+ val writeExec = dfWriteExec("enable_dict_option",
"parquet.enable.dictionary" -> "false")
+ assert(
+
CometIcebergNativeWrite.getSupportLevel(writeExec).isInstanceOf[Compatible],
+ "expected Compatible for write option parquet.enable.dictionary=false")
Review Comment:
This does not show that a write option reaches the writer.
`SparkWriteConf.writeProperties()` only puts the compression codec and level
(and the variant shredding keys on 1.11) into the map the gate and
`buildParquetSettings` read, at 1.5.2, 1.10.0 and 1.11.0. So
`.option("parquet.enable.dictionary", "false")` is ignored by iceberg-java too,
and the case passes because the key is never in `ctx.properties`. The test
title, the new `iceberg.md` row and the sentence "supported as a table or write
property" overstate this. I would drop the write option case and say table
property.
##########
spark/src/test/scala/org/apache/comet/CometIcebergWriteActionSuite.scala:
##########
@@ -3289,6 +3290,192 @@ class CometIcebergWriteActionSuite
}
}
+ test("native acceleration: parquet.enable.dictionary=false matches
iceberg-java") {
+ assumeNativeAcceleration()
+ withIcebergCatalog { warehouseDir =>
+ val source = new File(warehouseDir, "dict_disabled_src").getAbsolutePath
+ withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+ spark
+ .range(0, 5000, 1, 1)
+ .selectExpr(
+ "cast(id % 3 AS INT) AS p",
+ "cast(id % 10 AS INT) AS small_int",
+ "cast((id % 7) * 1000000000L AS BIGINT) AS big_num",
+ "cast((id % 9) * 1.25 AS DECIMAL(10, 2)) AS price",
+ "cast((id % 6) * 0.5 AS DOUBLE) AS ratio",
+ "(id % 2 = 0) AS flag",
+ "concat('category_', cast(id % 5 AS STRING)) AS category",
+ "CASE WHEN id % 4 = 0 THEN NULL ELSE concat('v', cast(id % 7 AS
STRING)) END AS opt_str",
+ "CASE WHEN id % 5 = 0 THEN NULL ELSE named_struct('tag',
concat('t', cast(id % 4 AS STRING)), 'code', cast(id % 8 AS INT)) END AS
nested")
+ .write
+ .parquet(source)
+ }
+
+ val columnsDdl =
+ "p INT, small_int INT, big_num BIGINT, price DECIMAL(10, 2), ratio
DOUBLE, " +
+ "flag BOOLEAN, category STRING, opt_str STRING, nested STRUCT<tag:
STRING, code: INT>"
+
+ def assertNoDictionaryPagesOrEncodings(table: String): Unit = {
+ val dictPages = dataFileDictionaryPages(table)
+ assert(dictPages.nonEmpty, s"expected at least one data file for
$table")
+ dictPages.foreach { case (path, columns) =>
+ assert(columns.nonEmpty, s"expected columns in $path")
+ columns.foreach { case (col, hasDict) =>
+ assert(!hasDict, s"expected no dictionary pages for $col in $path
($table)")
+ }
+ }
+ dataFileFooters(table).foreach { case (path, footer) =>
+ footer.getBlocks.asScala.foreach { block =>
+ block.getColumns.asScala.foreach { chunk =>
+ val encodings = chunk.getEncodings.asScala.toSet
+ val col = chunk.getPath.toDotString
+ assert(
+ !encodings.exists(_.usesDictionary()),
+ s"expected no dictionary encodings for $col in $path ($table),
got $encodings")
+ assert(
+ encodings.contains(Encoding.PLAIN),
+ s"expected PLAIN encoding for $col in $path ($table), got
$encodings")
+ }
+ }
+ }
+ }
+
+ def collectMetrics(table: String): Row = {
+ val rows = spark
+ .sql(s"""
+ SELECT
+ sum(readable_metrics.small_int.value_count),
+ min(readable_metrics.small_int.lower_bound),
+ max(readable_metrics.small_int.upper_bound),
+ sum(readable_metrics.big_num.value_count),
+ min(readable_metrics.big_num.lower_bound),
+ max(readable_metrics.big_num.upper_bound),
+ sum(readable_metrics.price.value_count),
+ min(readable_metrics.price.lower_bound),
+ max(readable_metrics.price.upper_bound),
+ sum(readable_metrics.ratio.value_count),
+ min(readable_metrics.ratio.lower_bound),
+ max(readable_metrics.ratio.upper_bound),
+ sum(readable_metrics.flag.value_count),
+ min(readable_metrics.flag.lower_bound),
+ max(readable_metrics.flag.upper_bound),
+ sum(readable_metrics.category.value_count),
+ min(readable_metrics.category.lower_bound),
+ max(readable_metrics.category.upper_bound),
+ sum(readable_metrics.opt_str.value_count),
+ sum(readable_metrics.opt_str.null_value_count),
+ min(readable_metrics.opt_str.lower_bound),
+ max(readable_metrics.opt_str.upper_bound),
+ sum(readable_metrics.`nested.tag`.value_count),
+ sum(readable_metrics.`nested.tag`.null_value_count),
+ min(readable_metrics.`nested.tag`.lower_bound),
+ max(readable_metrics.`nested.tag`.upper_bound),
+ sum(readable_metrics.`nested.code`.value_count),
+ sum(readable_metrics.`nested.code`.null_value_count),
+ min(readable_metrics.`nested.code`.lower_bound),
+ max(readable_metrics.`nested.code`.upper_bound)
+ FROM $catalog.$ns.$table.data_files
+ """)
+ .collect()
+ assert(rows.length == 1)
+ rows.head
Review Comment:
`collectMetrics` is a 30 line `readable_metrics` query for a setting that
does not touch the footer statistics the manifest metrics are rebuilt from. The
point of this test is the dictionary page and encoding check, which the two
helpers below already do. `manifestMetricsParity` already exists in this suite
for the twin table pattern and `collectMetrics` here duplicates its inner
helper. Either drop the metrics comparison or compare one or two columns
through `manifestMetricsParity`.
--
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]