Skip to content

Commit

Permalink
C++ client: remove all Stringf/Streamf and related (#4900)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosak authored Nov 30, 2023
1 parent 39c70a4 commit 7e596a6
Show file tree
Hide file tree
Showing 34 changed files with 147 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "deephaven/client/client.h"
#include "deephaven/client/utility/arrow_util.h"
#include "deephaven/dhcore/utility/utility.h"
#include "deephaven/third_party/fmt/format.h"

namespace deephaven::client::utility {
namespace internal {
Expand Down Expand Up @@ -209,7 +210,6 @@ const char * const TypeConverterTraits<std::optional<T>>::kDeephavenTypeName =
template<typename T>
TypeConverter TypeConverter::CreateNew(const std::vector<T> &values) {
using deephaven::client::utility::OkOrThrow;
using deephaven::dhcore::utility::Stringf;

typedef TypeConverterTraits<T> traits_t;

Expand All @@ -227,7 +227,7 @@ TypeConverter TypeConverter::CreateNew(const std::vector<T> &values) {
}
auto builder_res = builder.Finish();
if (!builder_res.ok()) {
auto message = Stringf("Error building array of type %o: %o", traits_t::kDeephavenTypeName,
auto message = fmt::format("Error building array of type {}: {}", traits_t::kDeephavenTypeName,
builder_res.status().ToString());
}
auto array = builder_res.ValueUnsafe();
Expand All @@ -237,7 +237,6 @@ TypeConverter TypeConverter::CreateNew(const std::vector<T> &values) {
template<>
inline TypeConverter TypeConverter::CreateNew(const std::vector<deephaven::dhcore::DateTime> &values) {
using deephaven::client::utility::OkOrThrow;
using deephaven::dhcore::utility::Stringf;

// TODO(kosak): put somewhere
constexpr const char *kDeephavenTypeName = "java.time.ZonedDateTime";
Expand All @@ -255,7 +254,7 @@ inline TypeConverter TypeConverter::CreateNew(const std::vector<deephaven::dhcor
}
auto builder_res = builder.Finish();
if (!builder_res.ok()) {
auto message = Stringf("Error building array of type %o: %o",
auto message = fmt::format("Error building array of type {}: {}",
kDeephavenTypeName, builder_res.status().ToString());
}
auto array = builder_res.ValueUnsafe();
Expand Down
17 changes: 8 additions & 9 deletions cpp-client/deephaven/dhclient/src/impl/table_handle_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "deephaven/dhcore/container/row_sequence.h"
#include "deephaven/dhcore/ticking/ticking.h"
#include "deephaven/dhcore/utility/utility.h"
#include "deephaven/third_party/fmt/format.h"
#include "deephaven/third_party/fmt/ranges.h"

using io::deephaven::proto::backplane::grpc::AddTableRequest;
using io::deephaven::proto::backplane::grpc::AddTableResponse;
Expand Down Expand Up @@ -77,8 +79,6 @@ using deephaven::dhcore::ticking::TickingUpdate;
using deephaven::dhcore::utility::GetWhat;
using deephaven::dhcore::utility::MakeReservedVector;
using deephaven::dhcore::utility::separatedList;
using deephaven::dhcore::utility::Streamf;
using deephaven::dhcore::utility::Stringf;

using UpdateByOperationProto = io::deephaven::proto::backplane::grpc::UpdateByRequest::UpdateByOperation;

Expand Down Expand Up @@ -621,13 +621,12 @@ void TableHandleImpl::LookupHelper(const std::string &column_name,
}
}

auto render = [](std::ostream &s, ElementTypeId::Enum item) {
// TODO(kosak): render this as a human-readable string.
s << static_cast<int>(item);
};
auto message = Stringf("Column lookup for %o: Expected Arrow type: one of {%o}. Actual type %o",
column_name, separatedList(valid_types.begin(), valid_types.end(), ", ", render),
static_cast<int>(actual_type));
auto renderable_valid_types = MakeReservedVector<int32_t>(valid_types.size());
for (const auto &item : valid_types) {
renderable_valid_types.push_back(static_cast<int32_t>(item));
}
auto message = fmt::format("Column lookup for {}: Expected Arrow type: one of {{{}}}. Actual type {}",
column_name, renderable_valid_types, static_cast<int>(actual_type));
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "deephaven/dhcore/utility/utility.h"

using deephaven::client::impl::MoveVectorData;
using deephaven::dhcore::utility::Streamf;
using deephaven::dhcore::utility::Stringf;
using deephaven::dhcore::utility::ObjectId;
using io::deephaven::proto::backplane::grpc::CreateInputTableRequest;
using io::deephaven::proto::backplane::grpc::EmptyTableRequest;
Expand Down
17 changes: 9 additions & 8 deletions cpp-client/deephaven/dhclient/src/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

#include "deephaven/client/impl/util.h"
#include "deephaven/dhcore/utility/utility.h"
#include "deephaven/third_party/fmt/format.h"

using arrow::flight::FlightClient;
using deephaven::client::impl::MoveVectorData;
using deephaven::dhcore::utility::Bit_cast;
using deephaven::dhcore::utility::GetWhat;
using deephaven::dhcore::utility::Stringf;
using io::deephaven::proto::backplane::grpc::AddTableRequest;
using io::deephaven::proto::backplane::grpc::AddTableResponse;
using io::deephaven::proto::backplane::grpc::AjRajTablesRequest;
Expand Down Expand Up @@ -149,8 +149,8 @@ std::shared_ptr<Server> Server::CreateFromTarget(

auto location_res = arrow::flight::Location::Parse(flight_target);
if (!location_res.ok()) {
auto message = Stringf("Location::Parse(%o) failed, error = %o",
flight_target, location_res.status());
auto message = fmt::format("Location::Parse({}) failed, error = {}",
flight_target, location_res.status().ToString());
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}

Expand All @@ -166,7 +166,7 @@ std::shared_ptr<Server> Server::CreateFromTarget(

auto client_res = arrow::flight::FlightClient::Connect(*location_res, options);
if (!client_res.ok()) {
auto message = Stringf("FlightClient::Connect() failed, error = %o", client_res.status());
auto message = fmt::format("FlightClient::Connect() failed, error = {}", client_res.status().ToString());
throw std::runtime_error(message);
}
gpr_log(GPR_DEBUG,
Expand All @@ -192,8 +192,8 @@ std::shared_ptr<Server> Server::CreateFromTarget(
auto result = cfs->GetConfigurationConstants(&ctx, cc_req, &cc_resp);

if (!result.ok()) {
auto message = Stringf("Can't get configuration constants. Error %o: %o",
result.error_code(), result.error_message());
auto message = fmt::format("Can't get configuration constants. Error {}: {}",
static_cast<int>(result.error_code()), result.error_message());
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}

Expand Down Expand Up @@ -364,7 +364,8 @@ void Server::SendRpc(const std::function<grpc::Status(grpc::ClientContext *)> &c

auto status = callback(&ctx);
if (!status.ok()) {
auto message = Stringf("Error %o. Message: %o", status.error_code(), status.error_message());
auto message = fmt::format("Error {}. Message: {}", static_cast<int>(status.error_code()),
status.error_message());
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}

Expand Down Expand Up @@ -469,7 +470,7 @@ std::optional<std::chrono::milliseconds> ExtractExpirationInterval(
const auto *end = begin + target_value.size();
auto [ptr, ec] = std::from_chars(begin, end, millis);
if (ec != std::errc() || ptr != end) {
auto message = Stringf("Failed to parse %o as an integer", target_value);
auto message = fmt::format("Failed to parse {} as an integer", target_value);
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}
// As a matter of policy we use half of whatever the server tells us is the expiration time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ using deephaven::dhcore::ticking::BarrageProcessor;
using deephaven::dhcore::ticking::TickingCallback;
using deephaven::dhcore::utility::MakeReservedVector;
using deephaven::dhcore::utility::separatedList;
using deephaven::dhcore::utility::Streamf;
using deephaven::dhcore::utility::Stringf;
using deephaven::dhcore::utility::VerboseCast;
using deephaven::client::arrowutil::ArrowInt8ColumnSource;
using deephaven::client::arrowutil::ArrowInt16ColumnSource;
Expand Down Expand Up @@ -302,7 +300,7 @@ ColumnSourceAndSize ArrayToColumnSource(const arrow::Array &array) {
const auto *list_array = VerboseCast<const arrow::ListArray *>(DEEPHAVEN_LOCATION_EXPR(&array));

if (list_array->length() != 1) {
auto message = Stringf("Expected array of length 1, got %o", array.length());
auto message = fmt::format("Expected array of length 1, got {}", array.length());
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}

Expand Down
7 changes: 3 additions & 4 deletions cpp-client/deephaven/dhclient/src/update_by.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

using deephaven::client::impl::MoveVectorData;
using deephaven::client::impl::UpdateByOperationImpl;
using deephaven::dhcore::utility::Stringf;
// typedef io::deephaven::proto::backplane::grpc::UpdateByDelta UpdateByDelta;
using io::deephaven::proto::backplane::grpc::UpdateByEmOptions;

Expand Down Expand Up @@ -45,7 +44,7 @@ UpdateByNullBehavior convertDeltaControl(DeltaControl dc) {
case DeltaControl::kValueDominates: return UpdateByNullBehavior::VALUE_DOMINATES;
case DeltaControl::kZeroDominates: return UpdateByNullBehavior::ZERO_DOMINATES;
default: {
auto message = Stringf("Unexpected DeltaControl %o", static_cast<int>(dc));
auto message = fmt::format("Unexpected DeltaControl {}", static_cast<int>(dc));
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}
}
Expand All @@ -58,7 +57,7 @@ BadDataBehaviorProtoEnum convertBadDataBehavior(BadDataBehavior bdb) {
case BadDataBehavior::kThrow: return BadDataBehaviorProtoEnum::THROW;
case BadDataBehavior::kPoison: return BadDataBehaviorProtoEnum::POISON;
default: {
auto message = Stringf("Unexpected BadDataBehavior %o", static_cast<int>(bdb));
auto message = fmt::format("Unexpected BadDataBehavior {}", static_cast<int>(bdb));
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}
}
Expand Down Expand Up @@ -95,7 +94,7 @@ MathContextProto convertMathContext(MathContext mctx) {
break;
}
default: {
auto message = Stringf("Unexpected MathContext %o", static_cast<int>(mctx));
auto message = fmt::format("Unexpected MathContext {}", static_cast<int>(mctx));
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}
}
Expand Down
4 changes: 1 addition & 3 deletions cpp-client/deephaven/dhclient/src/utility/arrow_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#include "deephaven/client/utility/arrow_util.h"

#include <ostream>
#include <vector>
#include <arrow/status.h>
#include <arrow/type.h>
#include <arrow/flight/types.h>
#include "deephaven/dhcore/utility/utility.h"

Expand All @@ -17,7 +15,7 @@ void OkOrThrow(const deephaven::dhcore::utility::DebugInfo &debug_info,
return;
}

auto msg = Stringf("Status: %o. Caller: %o", status, debug_info);
auto msg = fmt::format("Status: {}. Caller: {}", status.ToString(), debug_info);
throw std::runtime_error(msg);
}

Expand Down
4 changes: 1 addition & 3 deletions cpp-client/deephaven/dhclient/src/utility/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <grpc/support/log.h>

using deephaven::dhcore::utility::GetWhat;
using deephaven::dhcore::utility::Streamf;
using deephaven::dhcore::utility::Stringf;

namespace deephaven::client::utility {
std::shared_ptr<Executor> Executor::Create(std::string id) {
Expand Down Expand Up @@ -45,7 +43,7 @@ void Executor::Invoke(std::function<void()> f) {
std::unique_lock guard(mutex_);
auto needs_notify = todo_.empty();
if (cancelled_) {
auto message = Stringf("Executor '%o' is cancelled: ignoring Invoke()\n", id_);
auto message = fmt::format("Executor '{}' is cancelled: ignoring Invoke()\n", id_);
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(message));
}
todo_.push_back(std::move(f));
Expand Down
4 changes: 2 additions & 2 deletions cpp-client/deephaven/dhclient/src/utility/table_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "deephaven/client/utility/table_maker.h"
#include "deephaven/client/utility/arrow_util.h"
#include "deephaven/dhcore/utility/utility.h"
#include "deephaven/third_party/fmt/format.h"

using deephaven::client::TableHandle;
using deephaven::client::utility::OkOrThrow;
using deephaven::client::utility::ValueOrThrow;
using deephaven::dhcore::utility::Stringf;

#include <memory>

Expand All @@ -29,7 +29,7 @@ void TableMaker::FinishAddColumn(std::string name, internal::TypeConverter info)
numRows_ = info.Column()->length();
} else if (numRows_ != info.Column()->length()) {
throw std::runtime_error(DEEPHAVEN_LOCATION_STR(
Stringf("Column sizes not consistent: expected %o, have %o", numRows_,
fmt::format("Column sizes not consistent: expected {}, have {}", numRows_,
info.Column()->length())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <vector>
#include "deephaven/dhcore/column/column_source.h"
#include "deephaven/dhcore/container/row_sequence.h"
#include "deephaven/third_party/fmt/format.h"
#include "deephaven/third_party/fmt/ostream.h"

namespace deephaven::dhcore::clienttable {
/**
Expand Down Expand Up @@ -161,3 +163,4 @@ class ClientTable {
std::vector<std::shared_ptr<RowSequence>> row_sequences) const;
};
} // namespace deephaven::dhcore::clienttable

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <ostream>
#include <set>

#include "deephaven/third_party/fmt/format.h"
#include "deephaven/third_party/fmt/ostream.h"

namespace deephaven::dhcore::container {
class RowSequenceIterator;

Expand Down Expand Up @@ -164,3 +167,6 @@ class RowSequenceBuilder {
size_t size_ = 0;
};
} // namespace deephaven::dhcore::container

// Add the specialization for the RowSequence formatter
template<> struct fmt::formatter<deephaven::dhcore::container::RowSequence> : fmt::ostream_formatter {};
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ void VisitElementTypeId(ElementTypeId::Enum type_id, T *visitor) {
break;
}
default: {
auto message = deephaven::dhcore::utility::Stringf("Unrecognized ElementTypeId %o",
static_cast<int>(type_id));
auto message = fmt::format("Unrecognized ElementTypeId {}", static_cast<int>(type_id));
throw std::runtime_error(message);
}
}
Expand Down
Loading

0 comments on commit 7e596a6

Please sign in to comment.