Skip to content

Commit

Permalink
test: add binder tests for errors
Browse files Browse the repository at this point in the history
Add a test for every error not covered, as reported by lcov for lines
changed after the stringFormat change.
  • Loading branch information
Riolku committed Oct 14, 2023
1 parent 7446e6d commit 564a9ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ static void validateByColumnKeyword(FileType fileType, bool byColumn) {

static void validateCopyNpyFilesMatchSchema(uint32_t numFiles, TableSchema* schema) {
if (schema->properties.size() != numFiles) {
throw BinderException(
stringFormat("Number of npy files is not equal to number of properties in table {}.",
schema->tableName));
throw BinderException(stringFormat("Number of numpy files ({}) is not equal to the number "
"of properties in the table {}: {}.",
numFiles, schema->tableName, schema->properties.size()));
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/binder/bind/bind_create_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "binder/bound_create_macro.h"
#include "common/exception/binder.h"
#include "common/string_format.h"
#include "common/string_utils.h"
#include "parser/create_macro.h"

using namespace kuzu::common;
Expand All @@ -13,6 +14,7 @@ namespace binder {
std::unique_ptr<BoundStatement> Binder::bindCreateMacro(const Statement& statement) {
auto& createMacro = reinterpret_cast<const CreateMacro&>(statement);
auto macroName = createMacro.getMacroName();
StringUtils::toUpper(macroName);
if (catalog.getReadOnlyVersion()->containMacro(macroName)) {
throw BinderException{stringFormat("Macro {} already exists.", macroName)};
}
Expand All @@ -23,7 +25,7 @@ std::unique_ptr<BoundStatement> Binder::bindCreateMacro(const Statement& stateme
auto scalarMacro =
std::make_unique<function::ScalarMacroFunction>(createMacro.getMacroExpression()->copy(),
createMacro.getPositionalArgs(), std::move(defaultArgs));
return std::make_unique<BoundCreateMacro>(macroName, std::move(scalarMacro));
return std::make_unique<BoundCreateMacro>(std::move(macroName), std::move(scalarMacro));
}

} // namespace binder
Expand Down
14 changes: 14 additions & 0 deletions test/test_files/exceptions/binder/binder_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,17 @@ Binder exception: Invalid number of arguments for macro ADD4.
-STATEMENT COPY (MATCH (a:person) RETURN a) TO 'person.npy';
---- error
Binder exception: COPY TO currently only supports csv and parquet files.

-CASE DuplicateMacro
-STATEMENT CREATE MACRO inc(x) AS x + 1
---- ok
-STATEMENT CREATE MACRO INC(x, y) AS x + y
---- error
Binder exception: Macro INC already exists.

-CASE WrongNumOfNumpyFiles
-STATEMENT CREATE NODE TABLE temp(ID INT64, PRIMARY KEY(ID));
---- ok
-STATEMENT COPY temp FROM ("${KUZU_ROOT_DIRECTORY}/dataset/npy-20k/id_int64.npy", "${KUZU_ROOT_DIRECTORY}/dataset/npy-20k/two_dim_float.npy") BY COLUMN;
---- error
Binder exception: Number of numpy files (2) is not equal to the number of properties in the table temp: 1.

0 comments on commit 564a9ae

Please sign in to comment.