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

validity mask #17

Merged
merged 1 commit into from
Apr 19, 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
36 changes: 30 additions & 6 deletions src/duckdb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ module duckdb
public :: duckdb_data_chunk_reset
public :: duckdb_data_chunk_set_size
public :: duckdb_destroy_data_chunk
public :: duckdb_vector_get_column_type
public :: duckdb_vector_get_data
public :: duckdb_vector_get_validity
public :: duckdb_vector_ensure_validity_writable
! public :: duckdb_vector_assign_string_element
! public :: duckdb_vector_assign_string_element_len
public :: duckdb_list_vector_get_child
public :: duckdb_list_vector_get_size
public :: duckdb_list_vector_set_size
public :: duckdb_list_vector_reserve
public :: duckdb_struct_vector_get_child

enum, bind(c)
enumerator :: duckdb_state = 0
Expand Down Expand Up @@ -1029,6 +1040,12 @@ end function duckdb_struct_vector_get_child
! =========================================================================

! DUCKDB_API bool duckdb_validity_row_is_valid(uint64_t *validity, idx_t row);
! function duckdb_validity_row_is_valid_(validity, row) bind(c, name='duckdb_validity_row_is_valid') result(res)
! import :: c_bool, c_int64_t
! integer(c_int64_t) :: validity
! integer(c_int64_t), value :: row
! logical(c_bool) :: res
! end function duckdb_validity_row_is_valid_

! DUCKDB_API void duckdb_validity_set_row_validity(uint64_t *validity, idx_t row, bool valid);

Expand Down Expand Up @@ -1587,12 +1604,11 @@ end function duckdb_data_chunk_get_size
! =========================================================================
! Vector Interface
! =========================================================================

! function duckdb_vector_get_validity(vector) bind(c, name='duckdb_vector_get_validity') result(res)
! type(duckdb_vector) :: vector
! type(c_ptr) :: res
! res = duckdb_vector_get_validity_(vector)
! end function duckdb_vector_get_validity
function duckdb_vector_get_validity(vector) result(res)
type(duckdb_vector) :: vector
integer(int64) :: res
res = int(duckdb_vector_get_validity_(vector), kind=int64)
end function duckdb_vector_get_validity

! subroutine duckdb_vector_assign_string_element(vector, index, str)
! type(duckdb_vector) :: vector
Expand All @@ -1614,6 +1630,14 @@ end function duckdb_data_chunk_get_size
! Validity Mask Functions
! =========================================================================

! function duckdb_validity_row_is_valid(validity, row) result(res)
! integer(int64) :: validity(:)
! integer :: row
! logical :: res

! res = duckdb_validity_row_is_valid_(int(validity, c_int64_t), int(row, c_int64_t))
! end function duckdb_validity_row_is_valid

! =========================================================================
! Table Functions
! =========================================================================
Expand Down
5 changes: 3 additions & 2 deletions test/test_fortran_api.f90
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ subroutine test_data_chunk(error)
integer :: col_count, col_idx
integer :: chunk_count, chunk_idx
integer :: row_count, row_idx
integer(int64) :: validity

! Open db in in-memory mode
call check(error, duckdb_open(c_null_ptr, db) == duckdbsuccess)
Expand Down Expand Up @@ -477,7 +478,7 @@ subroutine test_data_chunk(error)
print *, "----------------------- 1"

chunk_count = duckdb_result_chunk_count(result)
print *, "chuck_count: ", chunk_count
print *, "chunck_count: ", chunk_count

print *, "----------------------- 2"

Expand All @@ -489,7 +490,7 @@ subroutine test_data_chunk(error)
do col_idx = 0, col_count - 1
! Get the column
vector = duckdb_data_chunk_get_vector(chunk, col_idx);
! uint64_t *validity = duckdb_vector_get_validity(vector);
validity = duckdb_vector_get_validity(vector)
! bool is_valid = duckdb_validity_row_is_valid(validity, row_idx);

! if (col_idx == 4) then
Expand Down