Copilot commented on code in PR #162: URL: https://github.com/apache/iotdb-client-go/pull/162#discussion_r3412173909
########## database/conn.go: ########## @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package iotdb_go + +import ( + "context" + "fmt" + "log" + "net" + "os" + "time" + + "github.com/apache/iotdb-client-go/v2/client" + "github.com/apache/iotdb-client-go/v2/database/column" + "github.com/pkg/errors" +) + +func dial(ctx context.Context, addr string, num int, opt *Options) (*connect, error) { + if addr == "" { + return nil, errors.New("empty addr") + } + // 使用 net.SplitHostPort 分割地址和端口 + host, port, err := net.SplitHostPort(addr) + if err != nil { + return nil, err + } + var ( + conn client.SessionPool + debugf = func(format string, v ...any) {} + ) + + if opt.Debug { + if opt.Debugf != nil { + debugf = func(format string, v ...any) { + opt.Debugf( + "[iotdb][%s][id=%d] "+format, + append([]interface{}{opt.Addr, num}, v...)..., + ) + } + } else { + debugf = log.New(os.Stdout, fmt.Sprintf("[iotdb][%s][id=%d]", opt.Addr, num), 0).Printf + } + } Review Comment: This debug prefix passes opt.Addr (a []string) to a %s format verb, which produces malformed logs and hides the actual address being dialed. Use the addr string for both the prefix and the Debugf args. ########## database/bind.go: ########## @@ -0,0 +1,370 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package iotdb_go + +import ( + std_driver "database/sql/driver" + "fmt" + "reflect" + "regexp" + "strings" + "time" + + "github.com/apache/iotdb-client-go/v2/database/driver" + "github.com/pkg/errors" +) + +var ( + ErrInvalidTimezone = errors.New("invalid timezone value") +) + +func Named(name string, value any) driver.NamedValue { + return driver.NamedValue{ + Name: name, + Value: value, + } +} + +type TimeUnit uint8 + +const ( + Seconds TimeUnit = iota + MilliSeconds + MicroSeconds + NanoSeconds +) + +type GroupSet struct { + Value []any +} + +type ArraySet []any + +func DateNamed(name string, value time.Time, scale TimeUnit) driver.NamedDateValue { + return driver.NamedDateValue{ + Name: name, + Value: value, + Scale: uint8(scale), + } +} + +var ( + bindNumericRe = regexp.MustCompile(`\$[0-9]+`) + bindPositionalRe = regexp.MustCompile(`[^\\][?]`) +) Review Comment: bindPositionalRe doesn't match a positional placeholder at the beginning of the query (because it requires a preceding non-\\ character). That can cause mixed numeric/positional placeholders like "?$1" to go undetected and be handled incorrectly. ########## database/iotdb_std.go: ########## @@ -0,0 +1,230 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package iotdb_go + +import ( + "context" + "database/sql" + "database/sql/driver" + "errors" + "io" + "log" + "net" + "os" + "syscall" +) + +var globalConnID int64 + +func init() { + var debugf = func(format string, v ...any) {} + sql.Register("iotdb", &stdDriver{debugf: debugf}) +} + +// isConnBrokenError returns true if the error class indicates that the +// db connection is no longer usable and should be marked bad +func isConnBrokenError(err error) bool { + if errors.Is(err, io.EOF) || errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) { + return true + } + if _, ok := err.(*net.OpError); ok { + return true + } + return false +} + +type stdDriver struct { + opt *Options + conn stdConnect + commit func() error + debugf func(format string, v ...any) +} + +var _ driver.Conn = (*stdDriver)(nil) +var _ driver.ConnBeginTx = (*stdDriver)(nil) +var _ driver.ExecerContext = (*stdDriver)(nil) +var _ driver.QueryerContext = (*stdDriver)(nil) +var _ driver.ConnPrepareContext = (*stdDriver)(nil) + +func (std *stdDriver) Open(dsn string) (_ driver.Conn, err error) { + var opt Options + if err := opt.fromDSN(dsn); err != nil { + std.debugf("Open dsn error: %v\n", err) + return nil, err + } + var debugf = func(format string, v ...any) {} + if opt.Debug { + debugf = log.New(os.Stdout, "[iotdb-std][opener] ", 0).Printf + } + opt.ClientInfo.Comment = []string{"database/sql"} + return (&stdConnOpener{opt: &opt, debugf: debugf}).Connect(context.Background()) +} + +var _ driver.Driver = (*stdDriver)(nil) + +func (std *stdDriver) ResetSession(ctx context.Context) error { + if std.conn.isBad() { + std.debugf("Resetting session because connection is bad") + return driver.ErrBadConn + } + return nil +} + +var _ driver.SessionResetter = (*stdDriver)(nil) + +func (std *stdDriver) Ping(ctx context.Context) error { + if std.conn.isBad() { + std.debugf("Ping: connection is bad") + return driver.ErrBadConn + } + + return std.conn.ping(ctx) +} + +var _ driver.Pinger = (*stdDriver)(nil) + +// Begin starts and returns a new transaction. +// +// Deprecated: Drivers should implement ConnBeginTx instead (or additionally). +func (std *stdDriver) Begin() (driver.Tx, error) { + if std.conn.isBad() { + std.debugf("Begin: connection is bad") + return nil, driver.ErrBadConn + } + return std, nil +} + +func (std *stdDriver) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { + if std.conn.isBad() { + std.debugf("BeginTx: connection is bad") + return nil, driver.ErrBadConn + } + + return std, nil +} + +func (std *stdDriver) Commit() error { + if std.commit == nil { + return nil + } + defer func() { + std.commit = nil + }() + + if err := std.commit(); err != nil { + if isConnBrokenError(err) { + std.debugf("Commit got EOF error: resetting connection") + return driver.ErrBadConn + } + std.debugf("Commit error: %v\n", err) + return err + } + return nil +} + +func (std *stdDriver) Rollback() error { + std.commit = nil + //std.conn.close() + return nil +} + +var _ driver.Tx = (*stdDriver)(nil) + +func (std *stdDriver) CheckNamedValue(nv *driver.NamedValue) error { return nil } + +var _ driver.NamedValueChecker = (*stdDriver)(nil) + +// Prepare returns a prepared statement, bound to this connection. +func (std *stdDriver) Prepare(query string) (driver.Stmt, error) { + return std.PrepareContext(context.Background(), query) +} + +func (std *stdDriver) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { + if std.conn.isBad() { + std.debugf("QueryContext: connection is bad") + return nil, driver.ErrBadConn + } + + r, err := std.conn.query(ctx, func(nativeTransport, error) {}, query, rebind(args)...) + if isConnBrokenError(err) { + std.debugf("QueryContext got a fatal error, resetting connection: %v\n", err) + return nil, driver.ErrBadConn + } + if err != nil { + std.debugf("QueryContext error: %v\n", err) + return nil, err + } + return &stdRows{ + rows: r, + debugf: std.debugf, + }, nil +} + +func (std *stdDriver) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { + if std.conn.isBad() { + std.debugf("PrepareContext: connection is bad") + return nil, driver.ErrBadConn + } + + std.commit = std.conn.commit + return &stdBatch{ + debugf: std.debugf, + }, nil +} Review Comment: PrepareContext currently returns a stdBatch that doesn't capture the query and ultimately cannot execute (Exec returns "not implemented" and ExecContext returns driver.ErrSkip). This makes prepared statements fail at runtime in a non-obvious way; either implement a real Stmt that executes the prepared query, or return a clear error indicating prepared statements aren't supported. ########## database/iotdb_std.go: ########## @@ -0,0 +1,230 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package iotdb_go + +import ( + "context" + "database/sql" + "database/sql/driver" + "errors" + "io" + "log" + "net" + "os" + "syscall" +) + +var globalConnID int64 + +func init() { + var debugf = func(format string, v ...any) {} + sql.Register("iotdb", &stdDriver{debugf: debugf}) +} + +// isConnBrokenError returns true if the error class indicates that the +// db connection is no longer usable and should be marked bad +func isConnBrokenError(err error) bool { + if errors.Is(err, io.EOF) || errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) { + return true + } + if _, ok := err.(*net.OpError); ok { + return true + } + return false +} + +type stdDriver struct { + opt *Options + conn stdConnect + commit func() error + debugf func(format string, v ...any) +} + +var _ driver.Conn = (*stdDriver)(nil) +var _ driver.ConnBeginTx = (*stdDriver)(nil) +var _ driver.ExecerContext = (*stdDriver)(nil) +var _ driver.QueryerContext = (*stdDriver)(nil) +var _ driver.ConnPrepareContext = (*stdDriver)(nil) + +func (std *stdDriver) Open(dsn string) (_ driver.Conn, err error) { + var opt Options + if err := opt.fromDSN(dsn); err != nil { + std.debugf("Open dsn error: %v\n", err) + return nil, err + } + var debugf = func(format string, v ...any) {} + if opt.Debug { + debugf = log.New(os.Stdout, "[iotdb-std][opener] ", 0).Printf + } + opt.ClientInfo.Comment = []string{"database/sql"} Review Comment: When Debug is enabled, Open always uses the default logger and ignores opt.Debugf. This makes debugging inconsistent with stdConnOpener.Driver/Connect, which honors the custom Debugf callback. ########## database/column/bool.go: ########## @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import ( + "github.com/apache/iotdb-client-go/v2/client" +) + +type Bool struct { + name string +} + +func (b *Bool) Name() string { + return b.name +} +func (b *Bool) Type() Type { + return "BOOLEAN" +} +func (b *Bool) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 Review Comment: Bool.Row returns 0 (an int) for the non-pointer zero value path, which is inconsistent with BOOLEAN columns and can break scanning/conversion. It should return false. ########## database/column/int32.go: ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import "github.com/apache/iotdb-client-go/v2/client" + +type Int32 struct { + name string +} + +func (i *Int32) Name() string { + return i.name +} +func (i *Int32) Type() Type { + return "INT32" +} +func (i *Int32) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetInt(i.name) + if err != nil { + if ptr { + return nil + } + return 0 + } + if ptr { + return &value + } + return value +} Review Comment: Int32.Row returns untyped 0 on error/nil (becomes int) and returns int32 values for the normal path. For database/sql driver.Rows, it's safer/spec-compliant to return int64 for integer values so scanning/conversion is consistent. ########## database/column/double.go: ########## @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import ( + "github.com/apache/iotdb-client-go/v2/client" +) + +type Double struct { + name string +} + +func (d *Double) Name() string { + return d.name +} +func (d *Double) Type() Type { + return "DOUBLE" +} +func (d *Double) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetDouble(d.name) + if err != nil { + if ptr { + return nil + } + return 0 + } + if ptr { + return &value + } + return value +} Review Comment: Double.Row returns an untyped 0 (which becomes int) on the non-pointer nil/error paths. For DOUBLE columns, return float64(0) to keep types consistent for database/sql scanning. ########## database/column/bool.go: ########## @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import ( + "github.com/apache/iotdb-client-go/v2/client" +) + +type Bool struct { + name string +} + +func (b *Bool) Name() string { + return b.name +} +func (b *Bool) Type() Type { + return "BOOLEAN" +} +func (b *Bool) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetBoolean(b.name) + if err != nil { + if ptr { + return nil + } + return 0 Review Comment: On GetBoolean error, Bool.Row again returns 0 (int) for the non-pointer path; return false to keep the driver value type consistent for BOOLEAN. ########## database/column/int64.go: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import ( + "reflect" + + "github.com/apache/iotdb-client-go/v2/client" +) + +type Int64 struct { + name string +} + +func (i *Int64) Name() string { + return i.name +} +func (i *Int64) Type() Type { + return "INT64" +} +func (i *Int64) Rows() int { + return 0 +} +func (i *Int64) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetLong(i.name) + if err != nil { + if ptr { + return nil + } + return 0 + } + if ptr { + return &value + } + return value +} Review Comment: Int64.Row returns the untyped constant 0 on nil/error paths, which becomes an int when stored in an interface{}. Return int64(0) so the value type stays consistent with INT64. ########## database/column/date.go: ########## @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import "github.com/apache/iotdb-client-go/v2/client" + +type Date struct { + name string +} + +func (b *Date) Name() string { + return b.name +} +func (b *Date) Type() Type { + return "DATE" +} + +func (b *Date) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 Review Comment: Date.Row returns 0 (int) for the non-pointer nil path, but DATE columns are time.Time. Return time.Time{} instead to keep scan types consistent. ########## database/column/date.go: ########## @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import "github.com/apache/iotdb-client-go/v2/client" + +type Date struct { + name string +} + +func (b *Date) Name() string { + return b.name +} +func (b *Date) Type() Type { + return "DATE" +} + +func (b *Date) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetDate(b.name) + if err != nil { + if ptr { + return nil + } + return 0 Review Comment: On GetDate error, Date.Row again returns 0 (int) for the non-pointer path. Return time.Time{} so DATE values remain time.Time for database/sql scanning. ########## database/column/date.go: ########## @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import "github.com/apache/iotdb-client-go/v2/client" Review Comment: Date.Row needs to return time.Time{} for non-pointer zero/error paths, which requires importing time. Convert the single-line import to an import block including time. ########## database/conn.go: ########## @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package iotdb_go + +import ( + "context" + "fmt" + "log" + "net" + "os" + "time" + + "github.com/apache/iotdb-client-go/v2/client" + "github.com/apache/iotdb-client-go/v2/database/column" + "github.com/pkg/errors" +) + +func dial(ctx context.Context, addr string, num int, opt *Options) (*connect, error) { + if addr == "" { + return nil, errors.New("empty addr") + } + // 使用 net.SplitHostPort 分割地址和端口 + host, port, err := net.SplitHostPort(addr) + if err != nil { + return nil, err + } + var ( + conn client.SessionPool + debugf = func(format string, v ...any) {} + ) + + if opt.Debug { + if opt.Debugf != nil { + debugf = func(format string, v ...any) { + opt.Debugf( + "[iotdb][%s][id=%d] "+format, + append([]interface{}{opt.Addr, num}, v...)..., + ) + } + } else { + debugf = log.New(os.Stdout, fmt.Sprintf("[iotdb][%s][id=%d]", opt.Addr, num), 0).Printf + } + } + var ( + config = &client.PoolConfig{ + Host: host, + Port: port, + UserName: opt.UserName, + Password: opt.Password, + } Review Comment: dial() builds a fresh client.PoolConfig with only Host/Port/UserName/Password, which discards DSN/Options values already parsed into opt.PoolConfig (FetchSize, TimeZone, ConnectRetryMax, Database, etc.). As a result, those settings are never applied to the session pool. ########## database/column/blob.go: ########## @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import "github.com/apache/iotdb-client-go/v2/client" + +type Blob struct { + name string +} + +func (b *Blob) Name() string { + return b.name +} +func (b *Blob) Type() Type { + return "BLOB" +} + +func (b *Blob) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetBlob(b.name) + if err != nil { + if ptr { + return nil + } + return 0 + } + if ptr { + return &value + } + return value +} Review Comment: Blob.Row returns &value where value is already a *client.Binary, producing a **client.Binary. Also, when ptr==false it returns *client.Binary, which is not a valid database/sql driver.Value; callers will typically expect []byte for BLOB columns. ########## database/column/float.go: ########## @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package column + +import ( + "github.com/apache/iotdb-client-go/v2/client" +) + +type Float struct { + name string +} + +func (f *Float) Name() string { + return f.name +} +func (f *Float) Type() Type { + return "FLOAT" +} + +func (f *Float) Row(stat *client.SessionDataSet, ptr bool) any { + if stat == nil { + if ptr { + return nil + } + return 0 + } + value, err := stat.GetFloat(f.name) + if err != nil { + if ptr { + return nil + } + return 0 + } + if ptr { + return &value + } + return value +} Review Comment: Float.Row returns untyped 0 on error/nil (becomes int) and returns float32 values. database/sql drivers should return float64 for floating-point values to stay within the supported driver.Value set and avoid conversion edge cases. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
