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 @@ -399,7 +399,13 @@ case class PaimonSparkWriter(table: FileStoreTable) {
}

private def repartitionByPartitionsAndBucket(df: DataFrame): DataFrame = {
val partitionCols = tableSchema.partitionKeys().asScala.map(col).toSeq
val inputSchema = df.schema
val partitionCols = tableSchema
.partitionKeys()
.asScala
.map(tableSchema.fieldNames().indexOf(_))
.map(x => col(inputSchema.fieldNames(x)))
.toSeq
df.repartition(partitionCols ++ Seq(col(BUCKET_COL)): _*)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ class DataFrameWriteTest extends PaimonSparkTestBase {
Assertions.assertFalse(paimonTable.options().containsKey("write.merge-schema.explicit-cast"))
}

test("Paimon: DataFrameWrite partition table") {
withTable("t") {
spark.sql(s"""
|CREATE TABLE t (a INT, b STRING, dt STRING) PARTITIONED BY(dt)
|TBLPROPERTIES ('file.format' = 'avro', 'bucket' = 2, 'bucket-key' = 'b')
|""".stripMargin)

val table = loadTable("t")
val location = table.location().toString

Seq((1, "x1", "a"), (2, "x2", "b"))
.toDF("a", "b", "c")
.write
.format("paimon")
.mode("append")
.save(location)
checkAnswer(sql("SELECT * FROM t"), Row(1, "x1", "a") :: Row(2, "x2", "b") :: Nil)
}
}

fileFormats.foreach {
fileFormat =>
test(s"Paimon: DataFrameWrite.saveAsTable in ByName mode, file.format: $fileFormat") {
Expand Down