Skip to content

Commit

Permalink
Fixed ReplacingMergeTree EngineSpec parsing: is_deleted column presen…
Browse files Browse the repository at this point in the history
…ce caused error
  • Loading branch information
AlexTheKing committed Aug 13, 2024
1 parent 3486fd2 commit 406335c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 406335c

Please sign in to comment.