Skip to content

Commit

Permalink
Fix issues with rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
JAicewizard committed Jul 13, 2024
1 parent c8f828a commit 9bf034a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 64 deletions.
28 changes: 0 additions & 28 deletions data_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
10 changes: 5 additions & 5 deletions udtf.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type (

pinnedValue[T any] struct {
pinner *runtime.Pinner
value T
value T
}

threadedTableSource interface {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 0 additions & 31 deletions vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

0 comments on commit 9bf034a

Please sign in to comment.