Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create-macro transaction constraints #1857

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/include/common/statement_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ class StatementTypeUtils {
return statementType == StatementType::COPY;
}

static bool isDDLOrCopyCSV(StatementType statementType) {
return isDDL(statementType) || isCopyCSV(statementType);
static bool isCreateMacro(StatementType statementType) {
return statementType == StatementType::CREATE_MACRO;
}

static bool allowActiveTransaction(StatementType statementType) {
return isDDL(statementType) || isCopyCSV(statementType) || isCreateMacro(statementType);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void Connection::beginTransactionIfAutoCommit(PreparedStatement* preparedStateme
}
if (!preparedStatement->allowActiveTransaction() && activeTransaction) {
throw ConnectionException(
"DDL and CopyCSV statements are automatically wrapped in a "
"DDL, CopyCSV, createMacro statements are automatically wrapped in a "
"transaction and committed. As such, they cannot be part of an "
"active transaction, please commit or rollback your previous transaction and "
"issue a ddl query without opening a transaction.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/prepared_statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace kuzu {
namespace main {

bool PreparedStatement::allowActiveTransaction() const {
return !common::StatementTypeUtils::isDDLOrCopyCSV(preparedSummary.statementType);
return !common::StatementTypeUtils::allowActiveTransaction(preparedSummary.statementType);
}

bool PreparedStatement::isSuccess() const {
Expand Down
6 changes: 3 additions & 3 deletions test/runner/e2e_copy_transaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ TEST_F(TinySnbCopyCSVTransactionTest, CopyCSVStatementWithActiveTransactionError
conn->beginWriteTransaction();
auto result = conn->query(copyPersonTableCMD);
ASSERT_EQ(result->getErrorMessage(),
"DDL and CopyCSV statements are automatically wrapped in a transaction and committed. "
"As such, they cannot be part of an active transaction, please commit or rollback your "
"previous transaction and issue a ddl query without opening a transaction.");
"DDL, CopyCSV, createMacro statements are automatically wrapped in a transaction and "
"committed. As such, they cannot be part of an active transaction, please commit or "
"rollback your previous transaction and issue a ddl query without opening a transaction.");
}

} // namespace testing
Expand Down
8 changes: 8 additions & 0 deletions test/runner/e2e_create_macro_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,13 @@ TEST_F(CreateMacroTestTrxTest, createMacroReadTrxError) {
"Can't execute a write query inside a read-only transaction.");
}

TEST_F(CreateMacroTestTrxTest, createMacroWithActiveTrxError) {
conn->beginWriteTransaction();
ASSERT_EQ(conn->query("CREATE MACRO var_macro(x) AS x")->getErrorMessage(),
"DDL, CopyCSV, createMacro statements are automatically wrapped in a transaction and "
"committed. As such, they cannot be part of an active transaction, please commit or "
"rollback your previous transaction and issue a ddl query without opening a transaction.");
}

} // namespace testing
} // namespace kuzu
7 changes: 4 additions & 3 deletions test/runner/e2e_ddl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ class TinySnbDDLTest : public DBTest {
auto result = conn->query(query);
ASSERT_FALSE(result->isSuccess());
ASSERT_EQ(result->getErrorMessage(),
"DDL and CopyCSV statements are automatically wrapped in a transaction and committed. "
"As such, they cannot be part of an active transaction, please commit or rollback your "
"previous transaction and issue a ddl query without opening a transaction.");
"DDL, CopyCSV, createMacro statements are automatically wrapped in a transaction and "
"committed. As such, they cannot be part of an active transaction, please commit or "
"rollback your previous transaction and issue a ddl query without opening a "
"transaction.");
}

void executeQueryWithoutCommit(std::string query) {
Expand Down
Loading