Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Error while scanning column of type `array<decimal(10,2)>` into Go type `[]float64`

Aperta
#213 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go, sql
Ambito
databases

Direzione di ricerca

Esegui la riproduzione segnalata di Test_Float64_Conversion, quindi leggi internal/rows/arrowbased/columnValues.go nella sezione intorno a listValueContainer.Value, identificato come origine del valore string. Il lavoro è completato quando la scansione di una colonna array<decimal(10,2)> in []float64 riesce senza l’errore di conversione database/sql segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

I have a table that has a column AMOUNTS with a type array<decimal(10,2)>, which I expect to scan into a field type []float64.
This is the test I wrote to reproduce it:

func (s *DatabricksRepositorySuite) Test_Float64_Conversion() {
	query := `SELECT AMOUNTS FROM components WHERE AMOUNTS IS NOT NULL AND array_size(AMOUNTS) > 0 LIMIT 1`
	var result []float64
	err := s.repository.db.QueryRow(query).Scan(&result)
	s.NoError(err)
}

When I run my query, I get this error:

sql: Scan error on column index 0, name "AMOUNTS": unsupported Scan, storing driver.Value type string into type *[]float64

Source

This error comes from the standard library in Go: the value for that field is provided by the SDK as a string, but the destination is []float64, so it fails. I also dove into Databricks' SDK source code and found the place [2] where the string is generated.

[1] Golang source - convertAssignRows
[2] Databricks SDK - listValueContainer.Value

Workaround

I created a custom type for the fields I have that use arrays:

import (
	"database/sql/driver"
	"encoding/json"
	"errors"
)

type databricksArray[T any] struct {
	parsedValue []T
}

func (f *databricksArray[T]) Scan(value interface{}) error {
	switch typedValue := value.(type) {
	case []T:
		f.parsedValue = typedValue
		return nil
	case string:
		return f.parseString(typedValue)
	default:
		return errors.New("error while handling databricks type")
	}
}

func (f *databricksArray[T]) parseString(value string) error {
	// This is a workaround for Databricks returning float arrays as strings
	// Example: `[1.0, 2.0, 3.0]`
	// We need to convert it to an array
	// This should be removed if/when Databricks fixes this issue
	valueBytes := []byte(value)
	var parsedValue []T
	if err := json.Unmarshal(valueBytes, &parsedValue); err != nil {
		return err
	}
	f.parsedValue = parsedValue
	return nil
}

func (f *databricksArray[T]) Value() (driver.Value, error) {
	return f.parsedValue, nil
}

func (f *databricksArray[T]) Slice() []T {
	if f == nil {
		return nil
	}
	return f.parsedValue
}

So my field

Amount []float64 `db:"AMOUNTS"`

is now

Amount databricksArray[float64] `db:"AMOUNTS"`

and I call Amount.Slice() when I want to read its value.

Lingua principale
Go
Stelle
53
Fork
66
Merge medio
21h 29m
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di databricks/databricks-sql-go

Tutte le issue di databricks/databricks-sql-go

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.