jasonlin45 commented on code in PR #3325: URL: https://github.com/apache/arrow-adbc/pull/3325#discussion_r2305830276
########## go/adbc/driver/databricks/ipc_reader_adapter.go: ########## @@ -0,0 +1,183 @@ +// 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" + "fmt" + "io" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/ipc" + dbsqlrows "github.com/databricks/databricks-sql-go/rows" +) + +// Check if the rows interface supports IPC streams +type rowsWithIPCStream interface { + GetArrowIPCStreams(context.Context) (dbsqlrows.ArrowIPCStreamIterator, error) +} + +// ipcReaderAdapter uses the new IPC stream interface for zero-copy Arrow access +type ipcReaderAdapter struct { + ipcIterator dbsqlrows.ArrowIPCStreamIterator + currentReader *ipc.Reader + currentRecord arrow.Record + schema *arrow.Schema + closed bool + refCount int64 +} + +// newIPCReaderAdapter creates a RecordReader using direct IPC stream access +func newIPCReaderAdapter(ctx context.Context, rows dbsqlrows.Rows) (array.RecordReader, error) { + // Check if rows supports IPC streams + ipcRows, ok := rows.(rowsWithIPCStream) + if !ok { + return nil, fmt.Errorf("databricks rows do not support IPC stream access") + } + + // Get IPC stream iterator + ipcIterator, err := ipcRows.GetArrowIPCStreams(ctx) + if err != nil { + return nil, fmt.Errorf("failed to get IPC streams: %w", err) + } + + adapter := &ipcReaderAdapter{ + refCount: 1, + ipcIterator: ipcIterator, + } + + // Initialize the first reader + err = adapter.loadNextReader() + if err != nil && err != io.EOF { + return nil, fmt.Errorf("failed to initialize IPC reader: %w", err) + } + + return adapter, nil +} + +// loadNextReader loads the next IPC stream into a reader +func (r *ipcReaderAdapter) loadNextReader() error { + // Release current reader if any + if r.currentReader != nil { + r.currentReader.Release() + r.currentReader = nil + } + + // Get next IPC stream + if !r.ipcIterator.HasNext() { + return io.EOF + } Review Comment: @felipecrv I have some good news!! turns out it was available on the stream! Take a peek at 2e38448ca2e4273f9e4b041feaa2b16d7c0fc606 :) this also gets rid of this caching business of grabbing the first schema -- 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]
