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

regression: nil values can't be used for arrays #164

Closed
punkeel opened this issue Apr 9, 2019 · 0 comments
Closed

regression: nil values can't be used for arrays #164

punkeel opened this issue Apr 9, 2019 · 0 comments

Comments

@punkeel
Copy link

punkeel commented Apr 9, 2019

Passing nil as a value for an Array(T) column used to work, but is broken in master:

To reproduce it locally, I wrote the following script and created a test table.

-- auto-generated definition
create table my_table
(
  id       Int32,
  anything Array(Int8)
)
  engine = Memory;

The following code runs fine with (id) VALUES (?) but breaks with (id, anything) VALUES (?, ?). When the lines annotated with @HERE are uncommented, the script breaks

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/kshvakov/clickhouse"
)

func main() {
	conn, err := sql.Open("clickhouse", "tcp://127.0.0.1:32769")
	if err != nil {
		panic(err)
	}
	fmt.Println("Connected!")

	err = (*conn).Ping()
	if err != nil {
		panic(err)
	}
	fmt.Println("Pinged!") // to force the connection

	tx, err := (*conn).Begin()
	if err != nil {
		panic(err)
	}
	fmt.Println("Got tx!")

	q := "INSERT INTO my_table (id) VALUES (?);"
        // q = "INSERT INTO my_table (id, anything) VALUES (?, ?);" // @HERE
	stmt, err := tx.Prepare(q)
	if err != nil {
		panic(err)
	}
	fmt.Println("Got stmt!")

	stmtParams := make([]interface{}, 0)
	stmtParams = append(stmtParams, sql.NamedArg{Name: "id", Value: 10})
	// stmtParams = append(stmtParams, sql.NamedArg{Name: "anything", Value: nil})  // @HERE

	fmt.Println("Executing!")
	_, err = stmt.Exec(stmtParams...)
	if err != nil {
		panic(err)
	}

	fmt.Println("Done!")
}

Expected behavior: a NULL/default value should be inserted in ClickHouse.
What happens instead:

panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
reflect.valueInterface(0x0, 0x0, 0x0, 0xc000000001, 0x0, 0x0)
	/usr/local/Cellar/go/1.11.5/libexec/src/reflect/value.go:983 +0x1a0
reflect.Value.Interface(0x0, 0x0, 0x0, 0x12904b0, 0x0)
	/usr/local/Cellar/go/1.11.5/libexec/src/reflect/value.go:978 +0x44
github.com/kshvakov/clickhouse/lib/data.(*Block).AppendRow(0xc0000b2500, 0xc0000aa480, 0x2, 0x2, 0x1400801, 0xc0000aa480)
	/Users/maxime/go/pkg/mod/github.com/kshvakov/clickhouse@v0.0.0-20190401201540-2efe1299a06714f7c1e39b710afcc489c5b7cb01/lib/data/block.go:135 +0x230
github.com/kshvakov/clickhouse.(*stmt).execContext(0xc000090b40, 0x12940e0, 0xc000096008, 0xc0000aa480, 0x2, 0x2, 0x141f8a0, 0x0, 0x0, 0x1705110)
	/Users/maxime/go/pkg/mod/github.com/kshvakov/clickhouse@v0.0.0-20190401201540-2efe1299a06714f7c1e39b710afcc489c5b7cb01/stmt.go:47 +0x67
github.com/kshvakov/clickhouse.(*stmt).ExecContext(0xc000090b40, 0x12940e0, 0xc000096008, 0xc0000ac2d0, 0x2, 0x2, 0xc0000f7cb0, 0xc0000f7cb8, 0x102a1f2, 0xc000000008)
	/Users/maxime/go/pkg/mod/github.com/kshvakov/clickhouse@v0.0.0-20190401201540-2efe1299a06714f7c1e39b710afcc489c5b7cb01/stmt.go:41 +0x144
database/sql.ctxDriverStmtExec(0x12940e0, 0xc000096008, 0x1294320, 0xc000090b40, 0xc0000ac2d0, 0x2, 0x2, 0x2, 0x2, 0x0, ...)
	/usr/local/Cellar/go/1.11.5/libexec/src/database/sql/ctxutil.go:65 +0x216
database/sql.resultFromStatement(0x12940e0, 0xc000096008, 0x1293e20, 0xc0000ee080, 0xc000098200, 0xc0000aa460, 0x2, 0x2, 0x0, 0x0, ...)
	/usr/local/Cellar/go/1.11.5/libexec/src/database/sql/sql.go:2342 +0x13e
database/sql.(*Stmt).ExecContext(0xc000136000, 0x12940e0, 0xc000096008, 0xc0000aa460, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.11.5/libexec/src/database/sql/sql.go:2318 +0x1f2
database/sql.(*Stmt).Exec(0xc000136000, 0xc0000aa460, 0x2, 0x2, 0x0, 0x0, 0x1, 0x2)
	/usr/local/Cellar/go/1.11.5/libexec/src/database/sql/sql.go:2330 +0x65
main.main()
	/Users/maxime/Code/repro_clickhouse/main.go:41 +0x47a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants