lidavidm commented on code in PR #2998: URL: https://github.com/apache/arrow-adbc/pull/2998#discussion_r2155883390
########## go/adbc/driver/databricks/statement.go: ########## @@ -0,0 +1,475 @@ +// 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 databricks + +import ( + "context" + "database/sql" + "fmt" + "reflect" + + "github.com/apache/arrow-adbc/go/adbc" + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/memory" +) + +type statementImpl struct { + conn *connectionImpl + query string + parameters []interface{} + prepared *sql.Stmt +} + +func (s *statementImpl) Close() error { + if s.prepared != nil { + return s.prepared.Close() + } + return nil +} + +func (s *statementImpl) SetOption(key, val string) error { + // No statement-specific options are supported yet + return adbc.Error{ + Code: adbc.StatusNotImplemented, + Msg: fmt.Sprintf("unsupported statement option: %s", key), + } +} + +func (s *statementImpl) SetSqlQuery(query string) error { + s.query = query + // Reset prepared statement if query changes + if s.prepared != nil { + _ = s.prepared.Close() // Ignore error on cleanup + s.prepared = nil + } + return nil +} + +func (s *statementImpl) Prepare(ctx context.Context) error { + if s.query == "" { + return adbc.Error{ + Code: adbc.StatusInvalidState, + Msg: "no query set", + } + } + + stmt, err := s.conn.db.PrepareContext(ctx, s.query) + if err != nil { + return adbc.Error{ + Code: adbc.StatusInvalidState, + Msg: fmt.Sprintf("failed to prepare statement: %v", err), + } + } + + s.prepared = stmt + return nil +} + +func (s *statementImpl) ExecuteQuery(ctx context.Context) (array.RecordReader, int64, error) { + var rows *sql.Rows + var err error + + if s.prepared != nil { + rows, err = s.prepared.QueryContext(ctx, s.parameters...) + } else if s.query != "" { + rows, err = s.conn.db.QueryContext(ctx, s.query, s.parameters...) + } else { + return nil, -1, adbc.Error{ + Code: adbc.StatusInvalidState, + Msg: "no query set", + } + } + + if err != nil { + return nil, -1, adbc.Error{ + Code: adbc.StatusInternal, + Msg: fmt.Sprintf("failed to execute query: %v", err), + } + } + + reader, rowsAffected, err := s.rowsToRecordReader(ctx, rows) Review Comment: It appears there is internally: https://github.com/databricks/databricks-sql-go/blob/main/internal/rows/arrowbased/arrowRecordIterator.go If the driver could use these lower level facilities instead of just wrapping `database/sql`, I think it would be much more compelling. Otherwise I agree with Matt that a generic adapter would make more sense if we're going to wrap `database/sql`. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org