From eed17e0706af3d9d9014e662802bbe7bea21765f Mon Sep 17 00:00:00 2001 From: Ludovico Nicotina Date: Tue, 18 Apr 2023 22:14:18 +0000 Subject: [PATCH] validity mask --- src/duckdb.f90 | 36 ++++++++++++++++++++++++++++++------ test/test_fortran_api.f90 | 5 +++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/duckdb.f90 b/src/duckdb.f90 index afd4674..6e9fc48 100644 --- a/src/duckdb.f90 +++ b/src/duckdb.f90 @@ -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 @@ -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); @@ -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 @@ -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 ! ========================================================================= diff --git a/test/test_fortran_api.f90 b/test/test_fortran_api.f90 index 382a422..061e52e 100644 --- a/test/test_fortran_api.f90 +++ b/test/test_fortran_api.f90 @@ -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) @@ -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" @@ -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