Skip to content

fix: fall back on nested types for default values #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 28, 2025
Merged
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
1 change: 1 addition & 0 deletions docs/source/user-guide/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ types (regardless of the logical type). This behavior can be disabled by setting
- There is a known performance issue when pushing filters down to Parquet. See the [Comet Tuning Guide] for more
information.
- There are failures in the Spark SQL test suite when enabling these new scans (tracking issues: [#1542] and [#1545]).
- No support for default values that are nested types (e.g., maps, arrays, structs). Literal default values are supported.

[#1545]: https://github.com/apache/datafusion-comet/issues/1545
[#1542]: https://github.com/apache/datafusion-comet/issues/1542
Expand Down
1 change: 1 addition & 0 deletions docs/templates/compatibility-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The new scans currently have the following limitations:
- There is a known performance issue when pushing filters down to Parquet. See the [Comet Tuning Guide] for more
information.
- There are failures in the Spark SQL test suite when enabling these new scans (tracking issues: [#1542] and [#1545]).
- No support for default values that are nested types (e.g., maps, arrays, structs). Literal default values are supported.

[#1545]: https://github.com/apache/datafusion-comet/issues/1545
[#1542]: https://github.com/apache/datafusion-comet/issues/1542
Expand Down
22 changes: 18 additions & 4 deletions spark/src/main/scala/org/apache/comet/rules/CometScanRule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ package org.apache.comet.rules
import scala.collection.mutable.ListBuffer

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression, PlanExpression}
import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression, GenericInternalRow, PlanExpression}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.catalyst.util.MetadataColumnHelper
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData, MetadataColumnHelper}
import org.apache.spark.sql.catalyst.util.ResolveDefaultColumns.getExistenceDefaultValues
import org.apache.spark.sql.comet.{CometBatchScanExec, CometScanExec}
import org.apache.spark.sql.execution.{FileSourceScanExec, SparkPlan}
import org.apache.spark.sql.execution.datasources.HadoopFsRelation
import org.apache.spark.sql.execution.datasources.v2.BatchScanExec
import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{ArrayType, ByteType, DataType, MapType, ShortType, StructType}
import org.apache.spark.sql.types._

import org.apache.comet.{CometConf, DataTypeSupport}
import org.apache.comet.CometConf._
Expand Down Expand Up @@ -118,7 +119,20 @@ case class CometScanRule(session: SparkSession) extends Rule[SparkPlan] {
return withInfos(scanExec, fallbackReasons.toSet)
}

val typeChecker = new CometScanTypeChecker(scanImpl)
val possibleDefaultValues = getExistenceDefaultValues(scanExec.requiredSchema)
if (possibleDefaultValues.exists(d => {
d != null && (d.isInstanceOf[ArrayBasedMapData] || d
.isInstanceOf[GenericInternalRow] || d.isInstanceOf[GenericArrayData])
})) {
// Spark already converted these to Java-native types, so we can't check SQL types.
// ArrayBasedMapData, GenericInternalRow, GenericArrayData correspond to maps, structs,
// and arrays respectively.
fallbackReasons +=
"Full native scan disabled because nested types for default values are not supported"
return withInfos(scanExec, fallbackReasons.toSet)
}

val typeChecker = CometScanTypeChecker(scanImpl)
val schemaSupported =
typeChecker.isSchemaSupported(scanExec.requiredSchema, fallbackReasons)
val partitionSchemaSupported =
Expand Down
Loading