MCPcopy Create free account
hub / github.com/apache/arrow / ReadNext

Method ReadNext

cpp/src/arrow/flight/sql/example/sqlite_statement_batch_reader.cc:111–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111Status SqliteStatementBatchReader::ReadNext(std::shared_ptr<RecordBatch>* out) {
112 sqlite3_stmt* stmt_ = statement_->GetSqlite3Stmt();
113
114 const int num_fields = schema_->num_fields();
115 std::vector<std::unique_ptr<arrow::ArrayBuilder>> builders(num_fields);
116
117 for (int i = 0; i < num_fields; i++) {
118 const std::shared_ptr<Field>& field = schema_->field(i);
119 const std::shared_ptr<DataType>& field_type = field->type();
120
121 ARROW_RETURN_NOT_OK(MakeBuilder(default_memory_pool(), field_type, &builders[i]));
122 }
123
124 int64_t rows = 0;
125 while (true) {
126 if (!already_executed_) {
127 ARROW_ASSIGN_OR_RAISE(rc_, statement_->Reset());
128 if (!statement_->parameters().empty()) {
129 if (batch_index_ >= statement_->parameters().size()) {
130 *out = nullptr;
131 break;
132 }
133 ARROW_RETURN_NOT_OK(statement_->Bind(batch_index_, row_index_));
134 }
135 ARROW_ASSIGN_OR_RAISE(rc_, statement_->Step());
136 already_executed_ = true;
137 }
138
139 while (rows < kMaxBatchSize && rc_ == SQLITE_ROW) {
140 rows++;
141 for (int i = 0; i < num_fields; i++) {
142 const std::shared_ptr<Field>& field = schema_->field(i);
143 const std::shared_ptr<DataType>& field_type = field->type();
144 ArrayBuilder* array_builder = builders[i].get();
145
146 if (sqlite3_column_type(stmt_, i) == SQLITE_NULL) {
147 ARROW_RETURN_NOT_OK(array_builder->AppendNull());
148 continue;
149 }
150
151 switch (field_type->id()) {
152 // XXX This doesn't handle overflows when converting to the target
153 // integer type.
154 INT_BUILDER_CASE(Int64, stmt_, i)
155 INT_BUILDER_CASE(UInt64, stmt_, i)
156 INT_BUILDER_CASE(Int32, stmt_, i)
157 INT_BUILDER_CASE(UInt32, stmt_, i)
158 INT_BUILDER_CASE(Int16, stmt_, i)
159 INT_BUILDER_CASE(UInt16, stmt_, i)
160 INT_BUILDER_CASE(Int8, stmt_, i)
161 INT_BUILDER_CASE(UInt8, stmt_, i)
162 FLOAT_BUILDER_CASE(Double, stmt_, i)
163 FLOAT_BUILDER_CASE(Float, stmt_, i)
164 FLOAT_BUILDER_CASE(HalfFloat, stmt_, i)
165 BINARY_BUILDER_CASE(Binary, stmt_, i)
166 BINARY_BUILDER_CASE(LargeBinary, stmt_, i)
167 STRING_BUILDER_CASE(String, stmt_, i)
168 STRING_BUILDER_CASE(LargeString, stmt_, i)

Callers

nothing calls this directly

Calls 15

default_memory_poolFunction · 0.85
GetSqlite3StmtMethod · 0.80
StepMethod · 0.80
MakeBuilderFunction · 0.50
ARROW_ASSIGN_OR_RAISEFunction · 0.50
NotImplementedFunction · 0.50
MakeFunction · 0.50
OKFunction · 0.50
num_fieldsMethod · 0.45
fieldMethod · 0.45
typeMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected