Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,29 @@ object SparkFormatTable {
}
}

private def alignPartitionSpec(
inferred: PartitionSpec,
partitionSchema: StructType): PartitionSpec = {
if (inferred.partitionColumns.isEmpty && partitionSchema.nonEmpty) {
PartitionSpec(partitionSchema, inferred.partitions)
} else {
inferred
}
}

// Extend from MetadataLogFileIndex to override partitionSchema
private class PartitionedMetadataLogFileIndex(
sparkSession: SparkSession,
path: Path,
parameters: Map[String, String],
userSpecifiedSchema: Option[StructType],
override val partitionSchema: StructType)
extends MetadataLogFileIndex(sparkSession, path, parameters, userSpecifiedSchema)
extends MetadataLogFileIndex(sparkSession, path, parameters, userSpecifiedSchema) {

override def partitionSpec(): PartitionSpec = {
alignPartitionSpec(super.partitionSpec(), partitionSchema)
}
}

// Extend from InMemoryFileIndex to override partitionSchema
private class PartitionedInMemoryFileIndex(
Expand All @@ -118,7 +133,12 @@ object SparkFormatTable {
userSpecifiedSchema,
fileStatusCache,
userSpecifiedPartitionSpec,
metadataOpsTimeNs)
metadataOpsTimeNs) {

override def partitionSpec(): PartitionSpec = {
alignPartitionSpec(super.partitionSpec(), partitionSchema)
}
}
}

trait PartitionedFormatTable extends SupportsPartitionManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,27 @@ class PaimonFormatTableTest extends PaimonSparkTestWithRestCatalogBase {
}
}

test(
"PartitionedFormatTable: engine impl should return empty result when selecting a partition column on an empty table") {
val tableName = "engine_empty_partition_select"
withTable(tableName) {
val location = s"${tempDBDir.getCanonicalPath}/engine_empty_partition_select"
sql(s"""CREATE TABLE $tableName (clickid STRING, geo STRING, dt STRING, hour STRING)
|USING parquet PARTITIONED BY (dt, hour) LOCATION '$location'
|TBLPROPERTIES ('format-table.implementation'='engine')
|""".stripMargin)
fileIO.mkdirs(new Path(location))
checkAnswer(sql(s"SELECT clickid, hour FROM $tableName WHERE dt='20260418'"), Nil)
checkAnswer(sql(s"SELECT clickid, dt FROM $tableName WHERE hour='00'"), Nil)
checkAnswer(
sql(s"""SELECT clickid, max(hour) AS max_hour FROM $tableName
|WHERE dt='20260418' AND hour <= '11' AND geo IS NOT NULL
|GROUP BY clickid""".stripMargin),
Nil
)
}
}

test("Paimon format table: show partitions") {
withTable("t") {
sql("""
Expand Down