Skip to content

Commit c3332f6

Browse files
committed
Address review: private SourceEntry, const fields, deduplicate batch logic, hoist columns
- Make SourceEntry private in RecordBatchRowProcessor - Make m_arrowTypeId and m_columnName const - Replace duplicated first-batch loop with fetchNextBatch call - Hoist columns() out of rebindSource loop Signed-off-by: Arham Chopra <arham.chopra@cubistsystematic.com>
1 parent d039d0d commit c3332f6

3 files changed

Lines changed: 15 additions & 29 deletions

File tree

cpp/csp/adapters/arrow/ColumnDispatcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class ColumnDispatcher
5757

5858
virtual void * getCurValueUntyped() = 0;
5959

60-
::arrow::Type::type m_arrowTypeId;
61-
std::string m_columnName;
60+
const ::arrow::Type::type m_arrowTypeId;
61+
const std::string m_columnName;
6262
};
6363

6464
// Factory: create a typed ColumnDispatcher for an arrow field.

cpp/csp/adapters/arrow/RecordBatchRowProcessor.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,7 @@ void RecordBatchRowProcessor::bindSources(
102102
}
103103

104104
// Pull first non-empty batch
105-
for( ;; )
106-
{
107-
auto status = entry.source -> ReadNext( &entry.currentBatch );
108-
CSP_TRUE_OR_THROW_RUNTIME( status.ok(),
109-
"bindSources: failed to read first batch: " << status.ToString() );
110-
111-
if( !entry.currentBatch )
112-
break;
113-
114-
entry.numRows = entry.currentBatch -> num_rows();
115-
entry.currentRow = 0;
116-
rebindSource( entry );
117-
118-
if( entry.numRows > 0 )
119-
break;
120-
}
105+
fetchNextBatch( entry );
121106

122107
m_sources.push_back( std::move( entry ) );
123108
}
@@ -143,8 +128,9 @@ bool RecordBatchRowProcessor::fetchNextBatch( SourceEntry & entry )
143128

144129
void RecordBatchRowProcessor::rebindSource( SourceEntry & entry )
145130
{
131+
auto & cols = entry.currentBatch -> columns();
146132
for( size_t i = 0; i < entry.dispatchers.size(); ++i )
147-
entry.dispatchers[i] -> bindColumn( entry.currentBatch -> column( entry.colIndices[i] ).get() );
133+
entry.dispatchers[i] -> bindColumn( cols[entry.colIndices[i]].get() );
148134
}
149135

150136
bool RecordBatchRowProcessor::skipRow()

cpp/csp/adapters/arrow/RecordBatchRowProcessor.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ class RecordBatchRowProcessor
3131
int colIndex;
3232
};
3333

34-
struct SourceEntry
35-
{
36-
::arrow::RecordBatchReader * source = nullptr;
37-
std::shared_ptr<::arrow::RecordBatch> currentBatch;
38-
int64_t numRows = 0;
39-
int64_t currentRow = 0;
40-
std::vector<int> colIndices;
41-
std::vector<ColumnDispatcher *> dispatchers;
42-
};
43-
4434
RecordBatchRowProcessor() = default;
4535

4636
// (Re)create dispatchers for the given schema and requested columns.
@@ -74,6 +64,16 @@ class RecordBatchRowProcessor
7464
bool readRowAndAdvance();
7565

7666
private:
67+
struct SourceEntry
68+
{
69+
::arrow::RecordBatchReader * source = nullptr;
70+
std::shared_ptr<::arrow::RecordBatch> currentBatch;
71+
int64_t numRows = 0;
72+
int64_t currentRow = 0;
73+
std::vector<int> colIndices;
74+
std::vector<ColumnDispatcher *> dispatchers;
75+
};
76+
7777
std::vector<std::unique_ptr<ColumnDispatcher>> m_dispatchers;
7878
std::unordered_map<std::string, ColumnDispatcher *> m_nameToDispatcher;
7979
std::vector<SourceEntry> m_sources;

0 commit comments

Comments
 (0)