Skip to content

Commit d1294e9

Browse files
authored
Merge pull request #32 from poyrazK/feat/parser-unit-tests
Add parser unit tests (81 tests) and fix IF NOT EXISTS parsing
2 parents eb8bf5d + f785e24 commit d1294e9

5 files changed

Lines changed: 893 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ if(BUILD_TESTS)
139139
add_cloudsql_test(columnar_table_tests tests/columnar_table_tests.cpp)
140140
add_cloudsql_test(heap_table_tests tests/heap_table_tests.cpp)
141141
add_cloudsql_test(lexer_tests tests/lexer_tests.cpp)
142+
add_cloudsql_test(parser_tests tests/parser_tests.cpp)
142143
add_cloudsql_test(storage_manager_tests tests/storage_manager_tests.cpp)
143144
add_cloudsql_test(rpc_server_tests tests/rpc_server_tests.cpp)
144145
add_cloudsql_test(operator_tests tests/operator_tests.cpp)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

include/parser/statement.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class CreateTableStatement : public Statement {
221221
private:
222222
std::string table_name_;
223223
std::vector<ColumnDef> columns_;
224+
bool if_not_exists_ = false;
224225

225226
public:
226227
CreateTableStatement() = default;
@@ -232,6 +233,8 @@ class CreateTableStatement : public Statement {
232233
columns_.push_back({std::move(name), std::move(type), false, false, false, nullptr});
233234
}
234235
[[nodiscard]] ColumnDef& get_last_column() { return columns_.back(); }
236+
void set_if_not_exists(bool v) { if_not_exists_ = v; }
237+
[[nodiscard]] bool if_not_exists() const { return if_not_exists_; }
235238

236239
[[nodiscard]] const std::string& table_name() const { return table_name_; }
237240
[[nodiscard]] const std::vector<ColumnDef>& columns() const { return columns_; }

src/parser/parser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,14 @@ std::unique_ptr<Statement> Parser::parse_create_table() {
287287
}
288288

289289
/* IF NOT EXISTS */
290-
if (consume(TokenType::Not)) {
290+
if (consume(TokenType::If)) {
291+
if (!consume(TokenType::Not)) {
292+
return nullptr;
293+
}
291294
if (!consume(TokenType::Exists)) {
292295
return nullptr;
293296
}
297+
stmt->set_if_not_exists(true);
294298
}
295299

296300
const Token name = next_token();

0 commit comments

Comments
 (0)