srebhan commented on code in PR #34331: URL: https://github.com/apache/arrow/pull/34331#discussion_r1124268359
########## go/arrow/flight/flightsql/driver.go: ########## @@ -0,0 +1,772 @@ +// 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 flightsql + +import ( + "context" + "database/sql" + "database/sql/driver" + "errors" + "fmt" + "io" + "net/url" + "sort" + "strings" + "time" + + "github.com/apache/arrow/go/v12/arrow" + "github.com/apache/arrow/go/v12/arrow/array" + "github.com/apache/arrow/go/v12/arrow/memory" + + "google.golang.org/grpc" +) + +var ( + ErrNotSupported = errors.New("not supported") + ErrOutOfRange = errors.New("index out of range") + ErrTransactionInProgress = errors.New("transaction still in progress") +) + +type Rows struct { + schema *arrow.Schema + records []arrow.Record + currentRecord int + currentRow int +} + +// Columns returns the names of the columns. +func (r *Rows) Columns() []string { + if len(r.records) == 0 { + return nil + } + + // All records have the same columns + var cols []string + for _, c := range r.schema.Fields() { + cols = append(cols, c.Name) + } + + return cols +} + +// Close closes the rows iterator. +func (r *Rows) Close() error { + for _, rec := range r.records { + rec.Release() + } + r.currentRecord = 0 + r.currentRow = 0 + + return nil +} + +// Next is called to populate the next row of data into +// the provided slice. The provided slice will be the same +// size as the Columns() are wide. +// +// Next should return io.EOF when there are no more rows. +// +// The dest should not be written to outside of Next. Care +// should be taken when closing Rows not to modify +// a buffer held in dest. +func (r *Rows) Next(dest []driver.Value) error { + if r.currentRecord >= len(r.records) { + return io.EOF + } + record := r.records[r.currentRecord] + + if int64(r.currentRow) >= record.NumRows() { + return ErrOutOfRange + } + + for i, arr := range record.Columns() { + v, err := fromArrowType(arr, r.currentRow) + if err != nil { + return err + } + dest[i] = v + } + + r.currentRow++ + if int64(r.currentRow) >= record.NumRows() { + r.currentRecord++ + r.currentRow = 0 + } + + return nil +} + +type Result struct { + affected int64 + lastinsert int64 +} + +// LastInsertId returns the database's auto-generated ID after, for example, +// an INSERT into a table with primary key. +func (r *Result) LastInsertId() (int64, error) { + if r.lastinsert < 0 { + return -1, ErrNotSupported + } + return r.lastinsert, nil +} + +// RowsAffected returns the number of rows affected by the query. +func (r *Result) RowsAffected() (int64, error) { + if r.affected < 0 { + return -1, ErrNotSupported + } + return r.affected, ErrNotSupported Review Comment: You are right. Fixed. -- 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]
