Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/blocking_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#pragma once

#include <atomic>
#include <boost/optional.hpp>
#include <condition_variable>
#include <mutex>
#include <optional>
#include <thread>
#include <vector>

Expand All @@ -43,7 +43,7 @@ class BlockingQueue {
std::atomic<bool> closed_{false};

public:
typedef std::function<boost::optional<T>(void)> Supplier;
typedef std::function<std::optional<T>(void)> Supplier;

explicit BlockingQueue(size_t capacity) : capacity_(capacity), buffer_(capacity) {}

Expand All @@ -58,7 +58,7 @@ class BlockingQueue {

// Only one thread at a time be notified and call supplier
auto item = supplier();
if (!item) break;
if (!item.has_value()) break;

Push(*item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "arrow/result.h"
#include "arrow/status.h"

#include <optional>
#include <utility>

namespace arrow::flight::sql::odbc {
Expand Down Expand Up @@ -63,7 +64,7 @@ class UserPasswordAuthMethod : public FlightSqlAuthMethod {
void Authenticate(FlightSqlConnection& connection,
FlightCallOptions& call_options) override {
FlightCallOptions auth_call_options;
const boost::optional<Connection::Attribute>& login_timeout =
const std::optional<Connection::Attribute>& login_timeout =
connection.GetAttribute(Connection::LOGIN_TIMEOUT);
if (login_timeout && boost::get<uint32_t>(*login_timeout) > 0) {
// ODBC's LOGIN_TIMEOUT attribute and FlightCallOptions.timeout use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <boost/algorithm/string/join.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"

#include <sql.h>
Expand Down Expand Up @@ -194,7 +193,7 @@ void FlightSqlConnection::PopulateMetadataSettings(
metadata_settings_.chunk_buffer_capacity = GetChunkBufferCapacity(conn_property_map);
}

boost::optional<int32_t> FlightSqlConnection::GetStringColumnLength(
std::optional<int32_t> FlightSqlConnection::GetStringColumnLength(
const Connection::ConnPropertyMap& conn_property_map) {
const int32_t min_string_column_length = 1;

Expand All @@ -209,7 +208,7 @@ boost::optional<int32_t> FlightSqlConnection::GetStringColumnLength(
"01000", ODBCErrorCodes_GENERAL_WARNING);
}

return boost::none;
return std::nullopt;
}

bool FlightSqlConnection::GetUseWideChar(const ConnPropertyMap& conn_property_map) {
Expand Down Expand Up @@ -245,7 +244,7 @@ const FlightCallOptions& FlightSqlConnection::PopulateCallOptions(
const ConnPropertyMap& props) {
// Set CONNECTION_TIMEOUT attribute or LOGIN_TIMEOUT depending on if this
// is the first request.
const boost::optional<Connection::Attribute>& connection_timeout =
const std::optional<Connection::Attribute>& connection_timeout =
closed_ ? GetAttribute(LOGIN_TIMEOUT) : GetAttribute(CONNECTION_TIMEOUT);
if (connection_timeout && boost::get<uint32_t>(*connection_timeout) > 0) {
call_options_.timeout =
Expand Down Expand Up @@ -383,17 +382,21 @@ bool FlightSqlConnection::SetAttribute(Connection::AttributeId attribute,
}
}

boost::optional<Connection::Attribute> FlightSqlConnection::GetAttribute(
std::optional<Connection::Attribute> FlightSqlConnection::GetAttribute(
Connection::AttributeId attribute) {
switch (attribute) {
case ACCESS_MODE:
// FlightSQL does not provide this metadata.
return boost::make_optional(Attribute(static_cast<uint32_t>(SQL_MODE_READ_WRITE)));
return std::make_optional(Attribute(static_cast<uint32_t>(SQL_MODE_READ_WRITE)));
case PACKET_SIZE:
return boost::make_optional(Attribute(static_cast<uint32_t>(0)));
return std::make_optional(Attribute(static_cast<uint32_t>(0)));
default:
const auto& it = attribute_.find(attribute);
return boost::make_optional(it != attribute_.end(), it->second);
if (it != attribute_.end()) {
return std::make_optional(it->second);
} else {
return std::nullopt;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "arrow/flight/sql/odbc/odbc_impl/spi/connection.h"

#include <optional>
#include <vector>
#include "arrow/flight/api.h"
#include "arrow/flight/sql/api.h"
Expand Down Expand Up @@ -84,7 +85,7 @@ class FlightSqlConnection : public Connection {

bool SetAttribute(AttributeId attribute, const Attribute& value) override;

boost::optional<Connection::Attribute> GetAttribute(
std::optional<Connection::Attribute> GetAttribute(
Connection::AttributeId attribute) override;

Info GetInfo(uint16_t info_type) override;
Expand All @@ -111,8 +112,7 @@ class FlightSqlConnection : public Connection {
/// \note Visible for testing
void SetClosed(bool is_closed);

boost::optional<int32_t> GetStringColumnLength(
const ConnPropertyMap& conn_property_map);
std::optional<int32_t> GetStringColumnLength(const ConnPropertyMap& conn_property_map);

bool GetUseWideChar(const ConnPropertyMap& conn_property_map);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
#include "arrow/flight/types.h"
#include "gtest/gtest.h"

#include <optional>

namespace arrow::flight::sql::odbc {

TEST(AttributeTests, SetAndGetAttribute) {
FlightSqlConnection connection(OdbcVersion::V_3);
connection.SetClosed(false);

connection.SetAttribute(Connection::CONNECTION_TIMEOUT, static_cast<uint32_t>(200));
const boost::optional<Connection::Attribute> first_value =
const std::optional<Connection::Attribute> first_value =
connection.GetAttribute(Connection::CONNECTION_TIMEOUT);

EXPECT_TRUE(first_value);
Expand All @@ -37,7 +39,7 @@ TEST(AttributeTests, SetAndGetAttribute) {

connection.SetAttribute(Connection::CONNECTION_TIMEOUT, static_cast<uint32_t>(300));

const boost::optional<Connection::Attribute> change_value =
const std::optional<Connection::Attribute> change_value =
connection.GetAttribute(Connection::CONNECTION_TIMEOUT);

EXPECT_TRUE(change_value);
Expand All @@ -49,7 +51,7 @@ TEST(AttributeTests, SetAndGetAttribute) {
TEST(AttributeTests, GetAttributeWithoutSetting) {
FlightSqlConnection connection(OdbcVersion::V_3);

const boost::optional<Connection::Attribute> optional =
const std::optional<Connection::Attribute> optional =
connection.GetAttribute(Connection::CONNECTION_TIMEOUT);
connection.SetClosed(false);

Expand All @@ -72,7 +74,7 @@ TEST(MetadataSettingsTest, StringColumnLengthTest) {
std::to_string(expected_string_column_length)},
};

const boost::optional<int32_t> actual_string_column_length =
const std::optional<int32_t> actual_string_column_length =
connection.GetStringColumnLength(properties);

EXPECT_TRUE(actual_string_column_length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
#include "arrow/io/memory.h"

#include <boost/optional.hpp>
#include <optional>
#include <utility>
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"

Expand Down Expand Up @@ -92,13 +92,17 @@ bool FlightSqlStatement::SetAttribute(StatementAttributeId attribute,
}
}

boost::optional<Statement::Attribute> FlightSqlStatement::GetAttribute(
std::optional<Statement::Attribute> FlightSqlStatement::GetAttribute(
StatementAttributeId attribute) {
const auto& it = attribute_.find(attribute);
return boost::make_optional(it != attribute_.end(), it->second);
if (it != attribute_.end()) {
return std::make_optional(it->second);
} else {
return std::nullopt;
}
}

boost::optional<std::shared_ptr<ResultSetMetadata>> FlightSqlStatement::Prepare(
std::optional<std::shared_ptr<ResultSetMetadata>> FlightSqlStatement::Prepare(
const std::string& query) {
ClosePreparedStatementIfAny(prepared_statement_, call_options_);

Expand All @@ -110,7 +114,7 @@ boost::optional<std::shared_ptr<ResultSetMetadata>> FlightSqlStatement::Prepare(

const auto& result_set_metadata = std::make_shared<FlightSqlResultSetMetadata>(
prepared_statement_->dataset_schema(), metadata_settings_);
return boost::optional<std::shared_ptr<ResultSetMetadata>>(result_set_metadata);
return std::optional<std::shared_ptr<ResultSetMetadata>>(result_set_metadata);
}

bool FlightSqlStatement::ExecutePrepared() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "arrow/flight/sql/api.h"
#include "arrow/flight/types.h"

#include <optional>

namespace arrow::flight::sql::odbc {

class FlightSqlStatement : public Statement {
Expand All @@ -52,9 +54,9 @@ class FlightSqlStatement : public Statement {

bool SetAttribute(StatementAttributeId attribute, const Attribute& value) override;

boost::optional<Attribute> GetAttribute(StatementAttributeId attribute) override;
std::optional<Attribute> GetAttribute(StatementAttributeId attribute) override;

boost::optional<std::shared_ptr<ResultSetMetadata>> Prepare(
std::optional<std::shared_ptr<ResultSetMetadata>> Prepare(
const std::string& query) override;

bool ExecutePrepared() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ FlightStreamChunkBuffer::FlightStreamChunkBuffer(
std::shared_ptr<FlightStreamReader> stream_reader_ptr(std::move(result.ValueOrDie()));

BlockingQueue<std::pair<Result<FlightStreamChunk>,
std::shared_ptr<FlightSqlClient>>>::Supplier supplier = [=] {
std::shared_ptr<FlightSqlClient>>>::Supplier supplier = [=]()
-> std::optional<
std::pair<Result<FlightStreamChunk>, std::shared_ptr<FlightSqlClient>>> {
auto result = stream_reader_ptr->Next();
bool is_not_ok = !result.ok();
bool is_not_empty = result.ok() && (result.ValueOrDie().data != nullptr);
Expand All @@ -68,11 +70,12 @@ FlightStreamChunkBuffer::FlightStreamChunkBuffer(
// call. temp_flight_sql_client is intentionally null if the list of endpoint
// Locations is empty.
// After all data is fetched from reader, the temp client is closed.

// gh-48084 Replace boost::optional with std::optional
return boost::make_optional(
is_not_ok || is_not_empty,
std::make_pair(std::move(result), temp_flight_sql_client));
if (is_not_ok || is_not_empty) {
return std::make_optional(
std::make_pair(std::move(result), temp_flight_sql_client));
} else {
return std::nullopt;
}
};
queue_.AddProducer(std::move(supplier));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <boost/xpressive/xpressive.hpp>
#include <iterator>
#include <memory>
#include <optional>
#include <utility>

using ODBC::ODBCConnection;
Expand Down Expand Up @@ -531,7 +532,7 @@ void ODBCConnection::SetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
SQLRETURN ODBCConnection::GetConnectAttr(SQLINTEGER attribute, SQLPOINTER value,
SQLINTEGER buffer_length,
SQLINTEGER* output_length, bool is_unicode) {
boost::optional<Connection::Attribute> spi_attribute;
std::optional<Connection::Attribute> spi_attribute;

switch (attribute) {
// Internal connection attributes
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <optional>
#include <utility>

using ODBC::DescriptorRecord;
Expand Down Expand Up @@ -273,7 +273,7 @@ void ODBCStatement::CopyAttributesFromConnection(ODBCConnection& connection) {
bool ODBCStatement::IsPrepared() const { return is_prepared_; }

void ODBCStatement::Prepare(const std::string& query) {
boost::optional<std::shared_ptr<ResultSetMetadata> > metadata =
std::optional<std::shared_ptr<ResultSetMetadata> > metadata =
spi_statement_->Prepare(query);

if (metadata) {
Expand Down Expand Up @@ -352,7 +352,7 @@ bool ODBCStatement::Fetch(size_t rows) {
void ODBCStatement::GetStmtAttr(SQLINTEGER statement_attribute, SQLPOINTER output,
SQLINTEGER buffer_size, SQLINTEGER* str_len_ptr,
bool is_unicode) {
boost::optional<Statement::Attribute> spi_attribute;
std::optional<Statement::Attribute> spi_attribute;
switch (statement_attribute) {
// Descriptor accessor attributes
case SQL_ATTR_APP_PARAM_DESC:
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/spi/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#pragma once

#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <functional>
#include <map>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -88,7 +88,7 @@ class Connection {

/// \brief Retrieve a connection attribute
/// \param attribute [in] Attribute to be retrieved.
virtual boost::optional<Connection::Attribute> GetAttribute(
virtual std::optional<Connection::Attribute> GetAttribute(
Connection::AttributeId attribute) = 0;

/// \brief Retrieves info from the database (see ODBC's SQLGetInfo).
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/spi/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#pragma once

#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <map>
#include <optional>
#include <vector>

namespace arrow::flight::sql::odbc {
Expand Down Expand Up @@ -67,14 +67,14 @@ class Statement {
///
/// \param attribute Attribute identifier to be retrieved.
/// \return Value associated with the attribute.
virtual boost::optional<Statement::Attribute> GetAttribute(
virtual std::optional<Statement::Attribute> GetAttribute(
Statement::StatementAttributeId attribute) = 0;

/// \brief Prepares the statement.
/// Returns ResultSetMetadata if query returns a result set,
/// otherwise it returns `boost::none`.
/// otherwise it returns `std::nullopt`.
/// \param query The SQL query to prepare.
virtual boost::optional<std::shared_ptr<ResultSetMetadata>> Prepare(
virtual std::optional<std::shared_ptr<ResultSetMetadata>> Prepare(
const std::string& query) = 0;

/// \brief Execute the prepared statement.
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/flight/sql/odbc/odbc_impl/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

#pragma once

#include <cstdint>
#include <optional>
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

#include <boost/optional.hpp>

namespace arrow::flight::sql::odbc {

/// \brief Supported ODBC versions.
Expand Down Expand Up @@ -172,7 +172,7 @@ enum RowStatus : uint16_t {
};

struct MetadataSettings {
boost::optional<int32_t> string_column_length{boost::none};
std::optional<int32_t> string_column_length;
size_t chunk_buffer_capacity;
bool use_wide_char;
};
Expand Down
Loading
Loading