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

[C API] Add SQLNULL to the duckdb types #13999

Merged
merged 2 commits into from
Sep 18, 2024
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
2 changes: 2 additions & 0 deletions src/include/duckdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ typedef enum DUCKDB_TYPE {
DUCKDB_TYPE_ANY = 34,
// duckdb_varint
DUCKDB_TYPE_VARINT = 35,
// SQLNULL type
DUCKDB_TYPE_SQLNULL = 36,
} duckdb_type;
//! An enum over the returned state of different functions.
typedef enum duckdb_state { DuckDBSuccess = 0, DuckDBError = 1 } duckdb_state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ typedef enum DUCKDB_TYPE {
DUCKDB_TYPE_ANY = 34,
// duckdb_varint
DUCKDB_TYPE_VARINT = 35,
// SQLNULL type
DUCKDB_TYPE_SQLNULL = 36,
} duckdb_type;
//! An enum over the returned state of different functions.
typedef enum duckdb_state { DuckDBSuccess = 0, DuckDBError = 1 } duckdb_state;
Expand Down
4 changes: 4 additions & 0 deletions src/main/capi/helper-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ LogicalTypeId ConvertCTypeToCPP(duckdb_type c_type) {
return LogicalTypeId::TIMESTAMP_TZ;
case DUCKDB_TYPE_ANY:
return LogicalTypeId::ANY;
case DUCKDB_TYPE_SQLNULL:
return LogicalTypeId::SQLNULL;
default: // LCOV_EXCL_START
D_ASSERT(0);
return LogicalTypeId::INVALID;
Expand Down Expand Up @@ -154,6 +156,8 @@ duckdb_type ConvertCPPTypeToC(const LogicalType &sql_type) {
return DUCKDB_TYPE_ARRAY;
case LogicalTypeId::ANY:
return DUCKDB_TYPE_ANY;
case LogicalTypeId::SQLNULL:
return DUCKDB_TYPE_SQLNULL;
default: // LCOV_EXCL_START
D_ASSERT(0);
return DUCKDB_TYPE_INVALID;
Expand Down
11 changes: 11 additions & 0 deletions test/api/capi/capi_scalar_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,22 @@ void CountNULLValues(duckdb_function_info, duckdb_data_chunk input, duckdb_vecto
auto result_data = (uint64_t *)duckdb_vector_get_data(output);
for (idx_t row_idx = 0; row_idx < input_size; row_idx++) {
idx_t null_count = 0;
idx_t other_null_count = 0;
for (idx_t col_idx = 0; col_idx < column_count; col_idx++) {
if (!duckdb_validity_row_is_valid(validity_masks[col_idx], row_idx)) {
null_count++;
}

// Alternative code path using SQLNULL.
auto duckdb_vector = duckdb_data_chunk_get_vector(input, col_idx);
auto logical_type = duckdb_vector_get_column_type(duckdb_vector);
auto type_id = duckdb_get_type_id(logical_type);
if (type_id == DUCKDB_TYPE_SQLNULL) {
other_null_count++;
}
duckdb_destroy_logical_type(&logical_type);
}
REQUIRE(null_count == other_null_count);
result_data[row_idx] = null_count;
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/api/capi/test_capi_any_invalid_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ TEST_CASE("Test logical type creation with unsupported types", "[capi]") {
}
}

TEST_CASE("Test INVALID and ANY", "[capi]") {
TEST_CASE("Test INVALID, ANY and SQLNULL", "[capi]") {
auto sql_null_type = duckdb_create_logical_type(DUCKDB_TYPE_SQLNULL);
duckdb_destroy_logical_type(&sql_null_type);

auto any_type = duckdb_create_logical_type(DUCKDB_TYPE_ANY);
auto invalid_type = duckdb_create_logical_type(DUCKDB_TYPE_INVALID);

Expand Down
Loading