Skip to content

Commit c529056

Browse files
committed
Fix null std::optional read issue
1 parent 003264e commit c529056

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_stream_chunk_buffer.cc

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,36 @@ FlightStreamChunkBuffer::FlightStreamChunkBuffer(
5959
util::ThrowIfNotOK(result.status());
6060
std::shared_ptr<FlightStreamReader> stream_reader_ptr(std::move(result.ValueOrDie()));
6161

62-
BlockingQueue<std::optional<
63-
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>>::Supplier
64-
supplier = [=] {
65-
auto result = stream_reader_ptr->Next();
66-
bool is_not_ok = !result.ok();
67-
bool is_not_empty = result.ok() && (result.ValueOrDie().data != nullptr);
68-
69-
// If result is valid, save the temp Flight SQL Client for future stream reader
70-
// call. temp_flight_sql_client is intentionally null if the list of endpoint
71-
// Locations is empty.
72-
// After all data is fetched from reader, the temp client is closed.
73-
if (is_not_ok || is_not_empty) {
74-
return std::make_optional(
75-
std::make_pair(std::move(result), temp_flight_sql_client));
76-
} else {
77-
return std::optional<
78-
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>{};
79-
}
80-
};
62+
BlockingQueue<std::pair<Result<FlightStreamChunk>,
63+
std::shared_ptr<FlightSqlClient>>>::Supplier supplier = [=] {
64+
auto result = stream_reader_ptr->Next();
65+
bool is_not_ok = !result.ok();
66+
bool is_not_empty = result.ok() && (result.ValueOrDie().data != nullptr);
67+
68+
// If result is valid, save the temp Flight SQL Client for future stream reader
69+
// call. temp_flight_sql_client is intentionally null if the list of endpoint
70+
// Locations is empty.
71+
// After all data is fetched from reader, the temp client is closed.
72+
if (is_not_ok || is_not_empty) {
73+
return std::make_optional(
74+
std::make_pair(std::move(result), temp_flight_sql_client));
75+
} else {
76+
return std::optional<
77+
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>{};
78+
}
79+
};
8180
queue_.AddProducer(std::move(supplier));
8281
}
8382
}
8483

8584
bool FlightStreamChunkBuffer::GetNext(FlightStreamChunk* chunk) {
86-
std::optional<std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>
85+
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>
8786
closeable_endpoint_stream_pair;
8887
if (!queue_.Pop(&closeable_endpoint_stream_pair)) {
8988
return false;
9089
}
9190

92-
Result<FlightStreamChunk> result = closeable_endpoint_stream_pair.value().first;
91+
Result<FlightStreamChunk> result = closeable_endpoint_stream_pair.first;
9392
if (!result.status().ok()) {
9493
Close();
9594
throw DriverException(result.status().message());

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_stream_chunk_buffer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ using arrow::flight::sql::FlightSqlClient;
3131
using arrow::flight::sql::odbc::BlockingQueue;
3232

3333
class FlightStreamChunkBuffer {
34-
BlockingQueue<std::optional<
35-
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>>
34+
BlockingQueue<std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>>
3635
queue_;
3736

3837
public:

cpp/src/arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/blocking_queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BlockingQueue {
5858

5959
// Only one thread at a time be notified and call supplier
6060
auto item = supplier();
61-
if (!item) break;
61+
if (!item.has_value()) break;
6262

6363
Push(*item);
6464
}

0 commit comments

Comments
 (0)