From 406335cffd45737dbbac1c52f47663d84b82506d Mon Sep 17 00:00:00 2001 From: Alexandr Beitsiuk Date: Tue, 13 Aug 2024 15:53:41 +0200 Subject: [PATCH] Fixed ReplacingMergeTree EngineSpec parsing: is_deleted column presence caused error --- .../com/clickhouse/spark/parse/AstVisitor.scala | 2 +- .../clickhouse/spark/parse/SQLParserSuite.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/clickhouse-core/src/main/scala/com/clickhouse/spark/parse/AstVisitor.scala b/clickhouse-core/src/main/scala/com/clickhouse/spark/parse/AstVisitor.scala index f4f4f8fc..d4a71496 100644 --- a/clickhouse-core/src/main/scala/com/clickhouse/spark/parse/AstVisitor.scala +++ b/clickhouse-core/src/main/scala/com/clickhouse/spark/parse/AstVisitor.scala @@ -102,7 +102,7 @@ class AstVisitor extends ClickHouseSQLBaseVisitor[AnyRef] with Logging { case eg: String if "ReplacingMergeTree" equalsIgnoreCase eg => ReplacingMergeTreeEngineSpec( engine_clause = engineExpr, - version_column = seqToOption(engineArgs).map(_.asInstanceOf[FieldRef]), + version_column = engineArgs.lift(0).map(_.asInstanceOf[FieldRef]), _sorting_key = tupleIfNeeded(orderByOpt.toList), _primary_key = tupleIfNeeded(pkOpt.toList), _partition_key = tupleIfNeeded(partOpt.toList), diff --git a/clickhouse-core/src/test/scala/com/clickhouse/spark/parse/SQLParserSuite.scala b/clickhouse-core/src/test/scala/com/clickhouse/spark/parse/SQLParserSuite.scala index 181e7f88..8ade7055 100644 --- a/clickhouse-core/src/test/scala/com/clickhouse/spark/parse/SQLParserSuite.scala +++ b/clickhouse-core/src/test/scala/com/clickhouse/spark/parse/SQLParserSuite.scala @@ -83,6 +83,20 @@ class SQLParserSuite extends AnyFunSuite { assert(actual === expected) } + test("parse ReplacingMergeTree - 3") { + val ddl = "ReplacingMergeTree(ts, is_deleted) " + + "PARTITION BY toYYYYMM(created) ORDER BY id SETTINGS index_granularity = 8192" + val actual = parser.parseEngineClause(ddl) + val expected = ReplacingMergeTreeEngineSpec( + engine_clause = "ReplacingMergeTree(ts, is_deleted)", + version_column = Some(FieldRef("ts")), + _sorting_key = TupleExpr(FieldRef("id") :: Nil), + _partition_key = TupleExpr(List(FuncExpr("toYYYYMM", List(FieldRef("created"))))), + _settings = Map("index_granularity" -> "8192") + ) + assert(actual === expected) + } + test("parse ReplicatedReplacingMergeTree - 1") { val ddl = "ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/wj_report/wj_respondent', '{replica}') " + "PARTITION BY toYYYYMM(created) ORDER BY id SETTINGS index_granularity = 8192"