diff --git a/data_chunk.go b/data_chunk.go index 79bca5bd..49311bc2 100644 --- a/data_chunk.go +++ b/data_chunk.go @@ -127,31 +127,3 @@ func (chunk *DataChunk) initFromDuckDataChunk(data C.duckdb_data_chunk) error { func (chunk *DataChunk) close() { C.duckdb_destroy_data_chunk(&chunk.data) } - -func (chunk *DataChunk) setSize() error { - if len(chunk.columns) == 0 { - C.duckdb_data_chunk_set_size(chunk.data, C.idx_t(0)) - return nil - } - - allEqual := true - maxSize := C.idx_t(chunk.columns[0].size) - for i := 0; i < len(chunk.columns); i++ { - if chunk.columns[i].size != maxSize { - allEqual = false - } - if chunk.columns[i].size > maxSize { - maxSize = chunk.columns[i].size - } - } - - if !allEqual { - return errDriver - } - C.duckdb_data_chunk_set_size(chunk.data, maxSize) - return nil -} - -func (chunk *DataChunk) GetSize() int { - return int(C.duckdb_data_chunk_get_size(chunk.data)) -} diff --git a/udtf.go b/udtf.go index dc8fb404..c3bb3c58 100644 --- a/udtf.go +++ b/udtf.go @@ -61,7 +61,7 @@ type ( pinnedValue[T any] struct { pinner *runtime.Pinner - value T + value T } threadedTableSource interface { @@ -248,7 +248,7 @@ func udfBindTyped[T tableSource](info C.duckdb_bind_info) { pinnedInstanceData := pinnedValue[tableFunctionData]{ pinner: &runtime.Pinner{}, - value: instanceData, + value: instanceData, } handle := cgo.NewHandle(pinnedInstanceData) @@ -359,7 +359,7 @@ func udf_chunk_callback(info C.duckdb_function_info, output C.duckdb_data_chunk) instance := h.Value().(pinnedValue[tableFunctionData]).value var chunk DataChunk - err := chunk.initFromChunk(output) + err := chunk.initFromDuckDataChunk(output) if err != nil { errstr := C.CString(err.Error()) defer C.free(unsafe.Pointer(errstr)) @@ -394,9 +394,9 @@ func RegisterTableUDF[TFT TableFunction](c *sql.Conn, name string, function TFT) name := C.CString(name) defer C.free(unsafe.Pointer(name)) - cfunction := pinnedValue[TFT] { + cfunction := pinnedValue[TFT]{ pinner: &runtime.Pinner{}, - value: function, + value: function, } handle := cgo.NewHandle(cfunction) diff --git a/vector.go b/vector.go index ba14501f..ca8ce71f 100644 --- a/vector.go +++ b/vector.go @@ -356,35 +356,6 @@ func (vec *vector) getChildVectors(vector C.duckdb_vector) { } } -func (vec *vector) setNull(rowIdx C.idx_t) { - C.duckdb_vector_ensure_validity_writable(vec.duckdbVector) - mask := C.duckdb_vector_get_validity(vec.duckdbVector) - C.duckdb_validity_set_row_invalid(mask, rowIdx) - - if vec.duckdbType == C.DUCKDB_TYPE_STRUCT { - for i := 0; i < len(vec.childVectors); i++ { - vec.childVectors[i].setNull(rowIdx) - } - } -} - -func setPrimitive[T any](vec *vector, rowIdx C.idx_t, val any) { - if val == nil { - vec.setNull(rowIdx) - return - } - - ptr := C.duckdb_vector_get_data(vec.duckdbVector) - xs := (*[1 << 31]T)(ptr) - xs[rowIdx] = val.(T) -} - -func (vec *vector) setTime(rowIdx C.idx_t, ticks int64) { - var ts C.duckdb_timestamp - ts.micros = C.int64_t(ticks) - setPrimitive[C.duckdb_timestamp](vec, rowIdx, ts) -} - func initPrimitive[T any](vec *vector, duckdbType C.duckdb_type) { vec.getFn = func(vec *vector, rowIdx C.idx_t) any { if vec.getNull(rowIdx) { @@ -920,7 +891,6 @@ func _setVectorStruct[S any](vec *vector, rowIdx C.idx_t, val S) error { } func setVectorVal[S any](vec *vector, rowIdx C.idx_t, val S) error { - vec.size ++ switch vec.duckdbType { case C.DUCKDB_TYPE_UTINYINT: return _setVectorNumeric[S, uint8](vec, rowIdx, val) @@ -958,7 +928,6 @@ func setVectorVal[S any](vec *vector, rowIdx C.idx_t, val S) error { case C.DUCKDB_TYPE_STRUCT: return _setVectorStruct[S](vec, rowIdx, val) default: - vec.size -- // Since we preemtively increment this, we should return errBadDuckdbType } }