jduo commented on code in PR #34817:
URL: https://github.com/apache/arrow/pull/34817#discussion_r1379090779


##########
cpp/src/arrow/flight/types.cc:
##########
@@ -463,6 +463,300 @@ arrow::Result<CancelFlightInfoRequest> 
CancelFlightInfoRequest::Deserialize(
   return out;
 }
 
+// Helper for stringifying maps containing various types
+template <typename T>
+ostream& operator<<(std::map<std::string, T>) {
+  std::stringstream ss;
+
+  ss << '{';
+  std::string sep = "";
+  for (const auto& [k, v] : session_options) {
+    std::cout << sep << '[' << k << "]: '" << v << "', ";  // PHOXME 
v.ToString() not implemented yet
+    sep = ", ";
+  }
+  ss << '}';
+
+  return ss.str();
+}
+static bool CompareSessionOptionMaps(
+    const std::map<std::string, SessionOptionValue>& a,
+    const std::map<std::string, SessionOptionValue>& b) {
+  if (a.session_options.size() != b.session_options.size()) {
+    return false;
+  }
+  for (const auto & [k, v] : a.session_options) {
+    if (!b.session_options.contains(k)) {
+      return false;
+    }
+    const auto& b_v = b.session_options[k];
+    if (v.index() != b_v.index()) {
+      return false;
+    }
+    if (v != b_v) {
+      return false;
+    }
+  }
+  return true;
+}
+
+// SetSessionOptionsRequest
+
+std::string SetSessionOptionsRequest::ToString() const {
+  std::stringstream ss;
+
+  ss << "<SetSessionOptionsRequest session_options="
+     << SessionOptionMapToString(session_options); << '>';
+
+  return ss.str();
+}
+
+bool SetSessionOptionsRequest::Equals(const SetSessionOptionsRequest& other) 
const {
+  return CompareSessionOptionMaps(session_options, other.session_options);
+}
+
+arrow::Result<std::string>
+SetSessionOptionsRequest::SerializeToString() const {
+  pb::SetSessionOptionsRequest pb_request;
+  RETURN_NOT_OK(internal::ToProto(*this, &pb_request));
+
+  std::string out;
+  if (!pb_request.SerializeToString(&out)) {
+    return Status::IOError("Serialized SetSessionOptionsRequest exceeded 2GiB 
limit");
+  }
+  return out;
+}
+
+arrow::Result<SetSessionOptionsRequest>
+SetSessionOptionsRequest::Deserialize(std::string_view serialized) {
+  // TODO these & SerializeToString should all be factored out to a superclass
+  pb::SetSessionOptionsRequest pb_request;
+  if (serialized.size() > 
static_cast<size_t>(std::numeric_limits<int>::max())) {
+    return Status::Invalid(
+        "Serialized SetSessionOptionsRequest size should not exceed 2 GiB");
+  }
+  google::protobuf::io::ArrayInputStream input(serialized.data(),
+                                               
static_cast<int>(serialized.size()));
+  if (!pb_request.ParseFromZeroCopyStream(&input)) {
+    return Status::Invalid("Not a valid SetSessionOptionsRequest");
+  }
+  SetSessionOptionsRequest out;
+  RETURN_NOT_OK(internal::FromProto(pb_request, &out));
+  return out;
+}
+
+// SetSessionOptionsResult
+
+std::string SetSessionOptionsResult::ToString() const {
+  std::stringstream ss;
+
+  ss << "<SetSessionOptionsResult results=" << statuses << '>';
+
+  return ss.str();
+}
+
+bool SetSessionOptionsResult::Equals(const SetSessionOptionsResult& other) 
const {
+  if (statuses != other.statuses) {
+    return false;
+  }
+  return true;
+}
+
+arrow::Result<std::string>
+SetSessionOptionsResult::SerializeToString() const {
+  pb::SetSessionOptionsResult pb_result;
+  RETURN_NOT_OK(internal::ToProto(*this, &pb_result));
+
+  std::string out;
+  if (!pb_result.SerializeToString(&out)) {
+    return Status::IOError("Serialized SetSessionOptionsResult exceeded 2GiB 
limit");
+  }
+  return out;
+}
+
+arrow::Result<SetSessionOptionsResult>
+SetSessionOptionsResult::Deserialize(std::string_view serialized) {
+  pb::SetSessionOptionsResult pb_result;
+  if (serialized.size() > 
static_cast<size_t>(std::numeric_limits<int>::max())) {
+    return Status::Invalid(
+        "Serialized SetSessionOptionsResult size should not exceed 2 GiB");
+  }
+  google::protobuf::io::ArrayInputStream input(serialized.data(),
+                                               
static_cast<int>(serialized.size()));
+  if (!pb_result.ParseFromZeroCopyStream(&input)) {
+    return Status::Invalid("Not a valid SetSessionOptionsResult");
+  }
+  SetSessionOptionsResult out;
+  RETURN_NOT_OK(internal::FromProto(pb_result, &out));
+  return out;
+}
+
+// GetSessionOptionsRequest
+
+std::string GetSessionOptionsRequest::ToString() const {
+  return "<GetSessionOptionsRequest>";
+}
+
+bool GetSessionOptionsRequest::Equals(const GetSessionOptionsRequest& other) 
const {
+  return true;
+}
+
+arrow::Result<std::string>
+GetSessionOptionsRequest::SerializeToString() const {
+  pb::GetSessionOptionsRequest pb_request;
+  RETURN_NOT_OK(internal::ToProto(*this, &pb_request));
+
+  std::string out;
+  if (!pb_request.SerializeToString(&out)) {
+    return Status::IOError("Serialized GetSessionOptionsRequest exceeded 2GiB 
limit");
+  }
+  return out;
+}
+
+arrow::Result<GetSessionOptionsRequest>
+GetSessionOptionsRequest::Deserialize(std::string_view serialized) {
+  pb::GetSessionOptionsRequest pb_request;
+  if (serialized.size() > 
static_cast<size_t>(std::numeric_limits<int>::max())) {
+    return Status::Invalid(
+        "Serialized GetSessionOptionsRequest size should not exceed 2 GiB");
+  }
+  google::protobuf::io::ArrayInputStream input(serialized.data(),
+                                               
static_cast<int>(serialized.size()));
+  if (!pb_request.ParseFromZeroCopyStream(&input)) {
+    return Status::Invalid("Not a valid GetSessionOptionsRequest");
+  }
+  GetSessionOptionsRequest out;
+  RETURN_NOT_OK(internal::FromProto(pb_request, &out));
+  return out;
+}
+
+// GetSessionOptionsResult
+
+std::string GetSessionOptionsResult::ToString() const {
+  std::stringstream ss;
+  
+  ss << "<GetSessionOptionsResult session_options=" << session_options << '>';
+
+  return ss.str();
+}
+
+bool GetSessionOptionsResult::Equals(const GetSessionOptionsResult& other) 
const {
+  return CompareSessionOptionMaps(session_options, other.session_options);
+}
+
+arrow::Result<std::string>
+GetSessionOptionsResult::SerializeToString() const {
+  pb::GetSessionOptionsResult pb_result;
+  RETURN_NOT_OK(internal::ToProto(*this, &pb_result));
+
+  std::string out;
+  if (!pb_result.SerializeToString(&out)) {
+    return Status::IOError("Serialized GetSessionOptionsResult exceeded 2GiB 
limit");
+  }
+  return out;
+}
+
+arrow::Result<GetSessionOptionsResult>
+GetSessionOptionsResult::Deserialize(std::string_view serialized) {
+  pb::GetSessionOptionsResult pb_result;
+  if (serialized.size() > 
static_cast<size_t>(std::numeric_limits<int>::max())) {
+    return Status::Invalid(
+        "Serialized GetSessionOptionsResult size should not exceed 2 GiB");
+  }
+  google::protobuf::io::ArrayInputStream input(serialized.data(),
+                                               
static_cast<int>(serialized.size()));
+  if (!pb_result.ParseFromZeroCopyStream(&input)) {
+    return Status::Invalid("Not a valid GetSessionOptionsResult");
+  }
+  GetSessionOptionsResult out;
+  RETURN_NOT_OK(internal::FromProto(pb_result, &out));
+  return out;
+}
+
+// CloseSessionRequest
+
+std::string CloseSessionRequest::ToString() const {
+  return "<CloseSessionRequest>";
+}
+
+bool CloseSessionRequest::Equals(const CloseSessionRequest& other) const {
+  return true;
+}
+
+arrow::Result<std::string>
+CloseSessionRequest::SerializeToString() const {
+  pb::CloseSessionRequest pb_request;
+  RETURN_NOT_OK(internal::ToProto(*this, &pb_request));
+
+  std::string out;
+  if (!pb_request.SerializeToString(&out)) {
+    return Status::IOError("Serialized CloseSessionRequest exceeded 2GiB 
limit");
+  }
+  return out;
+}
+
+arrow::Result<CloseSessionRequest>
+CloseSessionRequest::Deserialize(std::string_view serialized) {
+  pb::CloseSessionRequest pb_request;
+  if (serialized.size() > 
static_cast<size_t>(std::numeric_limits<int>::max())) {
+    return Status::Invalid(
+        "Serialized CloseSessionRequest size should not exceed 2 GiB");
+  }
+  google::protobuf::io::ArrayInputStream input(serialized.data(),
+                                               
static_cast<int>(serialized.size()));
+  if (!pb_request.ParseFromZeroCopyStream(&input)) {
+    return Status::Invalid("Not a valid CloseSessionRequest");
+  }
+  CloseSessionRequest out;
+  RETURN_NOT_OK(internal::FromProto(pb_request, &out));
+  return out;
+}
+
+// CloseSessionResult
+
+std::string CloseSessionResult::ToString() const {
+  std::stringstream ss;
+
+  ss << "<CloseSessionResult result=" << status << '>';
+
+  return ss.str();
+}
+
+bool CloseSessionResult::Equals(const CloseSessionResult& other) const {

Review Comment:
   There's alot of boiler plate. Are all these methods necessary? Can this be 
refactored to use templates?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to