-
Notifications
You must be signed in to change notification settings - Fork 113
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
Initialise column types during appender creation #171
Conversation
I added a map to track all as-of-now unsupported types in the appender. We can incrementally add these (if they make sense in Go). |
@taniabogatsch in if v == nil {
setNull(&info, a.currSize)
continue
} To be able to append a list with a null value in it, the slice has to be of type
Here's a test to show what I mean, I'm investigating possible solutions to this. func TestAppenderNullBasicList(t *testing.T) {
connector, con, appender := prepareAppender(t, `CREATE TABLE test (int_slice bigint[])`)
defer con.Close()
defer connector.Close()
// An empty list must also initialize the logical types.
err := appender.AppendRow([]int64{})
require.NoError(t, err)
err = appender.AppendRow([]int64{1, 2, 3})
require.NoError(t, err)
err = appender.AppendRow(nil)
require.NoError(t, err)
p := func(i int64) *int64 {
return &i
}
err = appender.AppendRow([]*int64{p(1), p(2), nil, p(4)})
require.NoError(t, err)
err = appender.Close()
require.NoError(t, err)
// Verify results.
db := sql.OpenDB(connector)
res, err := db.QueryContext(
context.Background(),
`SELECT int_slice FROM test`)
require.NoError(t, err)
defer res.Close()
var strResult []string
strResult = append(strResult, "[]")
strResult = append(strResult, "[1 2 3]")
strResult = append(strResult, "<nil>")
strResult = append(strResult, "[1 2 <nil> 4]")
i := 0
for res.Next() {
var strS string
var intS []any
err := res.Scan(
&intS,
)
if err != nil {
strS = "<nil>"
} else {
strS = fmt.Sprintf("%v", intS)
}
require.Equal(t, strResult[i], strS, fmt.Sprintf("row %d: expected %v, got %v", i, strResult[i], strS))
i++
}
} |
Also, cc @marcboeker, what is your take on allowing (nil)-pointers as types in the appender? I understand it is an elegant solution to better support That is, we focus on column type initialization in this PR. Then, we can approach the whole |
#167 is merged now 🙂 |
@taniabogatsch Since Appender isn't really a |
@disq - fair point! I'll disentangle this PR to focus on the type creation/initialization. Then, I'll open a separate PR and port my |
I am closing this to favor #177 and another (soon-to-be) PR for better |
As discussed in #168, this PR adds support for initializing the column types of a data chunk when creating an appender.
The PR builds on #167. I'll undraft it once #167 is merged.