From 3924228af5566f8139e1b647cdc42396b4a50dc6 Mon Sep 17 00:00:00 2001 From: loneylee Date: Fri, 30 Aug 2024 14:33:42 +0800 Subject: [PATCH] fix bug --- .../spark/sql/delta/catalog/ClickHouseTableV2Base.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backends-clickhouse/src/main/scala/org/apache/spark/sql/delta/catalog/ClickHouseTableV2Base.scala b/backends-clickhouse/src/main/scala/org/apache/spark/sql/delta/catalog/ClickHouseTableV2Base.scala index 42b57e0a2ce6b..b1d9760d7303d 100644 --- a/backends-clickhouse/src/main/scala/org/apache/spark/sql/delta/catalog/ClickHouseTableV2Base.scala +++ b/backends-clickhouse/src/main/scala/org/apache/spark/sql/delta/catalog/ClickHouseTableV2Base.scala @@ -111,7 +111,7 @@ trait ClickHouseTableV2Base { Some(orderByKeys) } else { val orderByKeys = getCommaSeparatedColumns("orderByKey") - if (orderByKeys.nonEmpty) { + if (orderByKeys.isDefined) { val invalidKeys = orderByKeys.get.intersect(partitionColumns) if (invalidKeys.nonEmpty) { throw new IllegalStateException( @@ -127,7 +127,11 @@ trait ClickHouseTableV2Base { lazy val primaryKeyOption: Option[Seq[String]] = { if (orderByKeyOption.isDefined) { val primaryKeys = getCommaSeparatedColumns("primaryKey") - if (!orderByKeyOption.get.mkString(",").startsWith(primaryKeys.get.mkString(","))) { + if ( + primaryKeys.isDefined && !orderByKeyOption.get + .mkString(",") + .startsWith(primaryKeys.get.mkString(",")) + ) { throw new IllegalStateException( s"Primary key $primaryKeys must be a prefix of the sorting key") }