Skip to content
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

[GLUTEN-7344][CH] Fix the error default database name and table name for the mergetree file format when using path based #7346

Merged
merged 1 commit into from
Sep 25, 2024
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 @@ -29,6 +29,8 @@ import java.{util => ju}

trait ClickHouseTableV2Base {

val DEFAULT_DATABASE = "clickhouse_db"

def deltaProperties(): ju.Map[String, String]

def deltaCatalog(): Option[CatalogTable]
Expand All @@ -39,7 +41,7 @@ trait ClickHouseTableV2Base {

lazy val dataBaseName = deltaCatalog
.map(_.identifier.database.getOrElse("default"))
.getOrElse("clickhouse")
.getOrElse(DEFAULT_DATABASE)

lazy val tableName = deltaCatalog
.map(_.identifier.table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object MergeTreePartsPartitionsUtil extends Logging {
(table.catalogTable.get.identifier.database.get, table.catalogTable.get.identifier.table)
} else {
// for file_format.`file_path`
("default", "file_format")
(table.DEFAULT_DATABASE, table.deltaPath.toUri.getPath)
}
val engine = "MergeTree"
val relativeTablePath = fileIndex.deltaLog.dataPath.toUri.getPath.substring(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,4 +1337,63 @@ class GlutenClickHouseMergeTreePathBasedWriteSuite
assert(df.queryExecution.executedPlan.isInstanceOf[LocalTableScanExec])
}
}

test(
"GLUTEN-7344: Fix the error default database name and table " +
"name for the mergetree file format when using path based") {
val dataPath = s"$basePath/lineitem_filebased_7344"
clearDataPath(dataPath)
val dataPath1 = s"$basePath/lineitem_filebased_7344_1"
clearDataPath(dataPath1)

val sourceDF = spark.sql(s"""
|select * from lineitem
|""".stripMargin)

sourceDF.write
.format("clickhouse")
.mode(SaveMode.Append)
.option("clickhouse.orderByKey", "l_shipdate,l_orderkey")
.option("clickhouse.primaryKey", "l_shipdate")
.option("clickhouse.lowCardKey", "l_returnflag,l_linestatus")
.save(dataPath)

sourceDF.write
.format("clickhouse")
.mode(SaveMode.Append)
.option("clickhouse.orderByKey", "l_shipdate,l_orderkey")
.option("clickhouse.primaryKey", "l_shipdate")
.option("clickhouse.lowCardKey", "l_returnflag,l_linestatus")
.save(dataPath1)

val df = spark.read
.format("clickhouse")
.load(dataPath)
val result = df.collect()
assertResult(600572)(result.size)

val plans = collect(df.queryExecution.executedPlan) {
case f: FileSourceScanExecTransformer => f
}
val partitions = plans(0).getPartitions
assert(partitions.nonEmpty)
assert(partitions(0).isInstanceOf[GlutenMergeTreePartition])
assert(partitions(0).asInstanceOf[GlutenMergeTreePartition].database.equals("clickhouse_db"))
assert(partitions(0).asInstanceOf[GlutenMergeTreePartition].table.equals(dataPath))

val df1 = spark.read
.format("clickhouse")
.load(dataPath1)
val result1 = df1.collect()
assertResult(600572)(result.size)

val plans1 = collect(df1.queryExecution.executedPlan) {
case f: FileSourceScanExecTransformer => f
}
val partitions1 = plans1(0).getPartitions
assert(partitions1.nonEmpty)
assert(partitions1(0).isInstanceOf[GlutenMergeTreePartition])
assert(partitions1(0).asInstanceOf[GlutenMergeTreePartition].database.equals("clickhouse_db"))
assert(partitions1(0).asInstanceOf[GlutenMergeTreePartition].table.equals(dataPath1))
}
}
Loading