Skip to content

Commit f46cb56

Browse files
unit test for create table statment
1 parent 3e3f825 commit f46cb56

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Sources/ClickHouseVapor/ClickHouseEngine.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public struct ClickHouseEngineReplacingMergeTree: ClickHouseEngine {
7777
PRIMARY KEY (\(ids.joined(separator: ",")))
7878
"""
7979
if let partitionBy = partitionBy {
80-
query += "PARTITION BY (\(partitionBy))"
80+
query += " PARTITION BY (\(partitionBy))"
8181
}
82-
query += "ORDER BY (\(order.joined(separator: ",")))"
82+
query += " ORDER BY (\(order.joined(separator: ",")))"
8383
return query
8484
}
8585
}

Tests/ClickHouseVaporTests/ClickHouseVaporTests.swift

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ final class ClickHouseVaporTests: XCTestCase {
7878
model.fixed = [ "", "123456", "12345678901234" ]
7979
model.timestamp = [ 100, 200, 300 ]
8080
model.temperature = [ 11.1, 10.4, 8.9 ]
81+
82+
let createQuery = TestModel.engine.createTableQuery(columns: model.properties)
83+
XCTAssertEqual(createQuery, """
84+
CREATE TABLE IF NOT EXISTS `test` (timestamp Int64,stationID LowCardinality(String),fixed LowCardinality(FixedString(10)),temperature Float32)
85+
ENGINE = ReplacingMergeTree()
86+
PRIMARY KEY (timestamp,stationID) PARTITION BY (toYYYYMM(toDateTime(timestamp))) ORDER BY (timestamp,stationID)
87+
""")
8188

8289
try! TestModel.createTable(on: app.clickHouse).wait()
8390
try! model.insert(on: app.clickHouse).wait()

0 commit comments

Comments
 (0)