lidavidm commented on code in PR #13986:
URL: https://github.com/apache/arrow/pull/13986#discussion_r963789473
##########
python/pyarrow/_flight.pyx:
##########
@@ -289,6 +289,33 @@ cdef class Action(_Weakrefable):
type(action)))
return (<Action> action).action
+ def serialize(self):
+ """Get the wire-format representation of this type.
+
+ Useful when interoperating with non-Flight systems (e.g. REST
+ services) that may want to return Flight types.
+
+ """
+ return GetResultValue(self.action.SerializeToString())
+
+ @classmethod
+ def deserialize(cls, serialized):
+ """Parse the wire-format representation of this type.
+
+ Useful when interoperating with non-Flight systems (e.g. REST
+ services) that may want to return Flight types.
+
+ """
+ cdef Action action = Action.__new__(Action)
+ action.action = GetResultValue(
+ CAction.Deserialize(tobytes(serialized)))
+ return action
+
+ def __eq__(self, Action other):
+ # TODO (qhoang): question for myself, do we need to push this down
Review Comment:
Yes, just inherit from `util::EqualityComparable` on the C++ side and
implement `Equals` - then you can just declare an `operator==` in Cython to use
instead of doing this
Or I guess you can do something like this:
https://github.com/apache/arrow/blob/a5ecb0ff0774805b0f912e231eaedf42e7194c36/cpp/src/arrow/flight/types.h#L143-L150
Then just add the declaration in Cython (ActionType is actually missing its
declaration):
https://github.com/apache/arrow/blob/a5ecb0ff0774805b0f912e231eaedf42e7194c36/python/pyarrow/includes/libarrow_flight.pxd#L58
##########
cpp/src/arrow/flight/flight_internals_test.cc:
##########
@@ -83,6 +83,44 @@ TEST(FlightTypes, LocationUnknownScheme) {
}
TEST(FlightTypes, RoundTripTypes) {
+ ActionType action_type{"action-type1", "action-type1-description"};
+ ASSERT_OK_AND_ASSIGN(std::string action_type_serialized,
+ action_type.SerializeToString());
+ ASSERT_OK_AND_ASSIGN(ActionType action_type_deserialized,
+ ActionType::Deserialize(action_type_serialized));
+ ASSERT_TRUE(action_type.Equals(action_type_deserialized));
+
+ Criteria criteria{"criteria1"};
+ ASSERT_OK_AND_ASSIGN(std::string criteria_serialized,
criteria.SerializeToString());
+ ASSERT_OK_AND_ASSIGN(Criteria criteria_deserialized,
+ Criteria::Deserialize(criteria_serialized));
+ ASSERT_EQ(criteria.expression, criteria_deserialized.expression);
+
+ Action action{"action1", Buffer::FromString("action1-content")};
+ ASSERT_OK_AND_ASSIGN(std::string action_serialized,
action.SerializeToString());
+ ASSERT_OK_AND_ASSIGN(Action action_deserialized,
+ Action::Deserialize(action_serialized));
+ ASSERT_EQ(action.type, action_deserialized.type);
+ ASSERT_TRUE((action.body == action_deserialized.body) ||
+ (action.body != nullptr && action_deserialized.body != nullptr &&
+ action.body->Equals(*action_deserialized.body)));
+
+ Result result{Buffer::FromString("result1-content")};
+ ASSERT_OK_AND_ASSIGN(std::string result_serialized,
result.SerializeToString());
+ ASSERT_OK_AND_ASSIGN(Result result_deserialized,
+ Result::Deserialize(result_serialized));
+ ASSERT_TRUE((result.body == result_deserialized.body) ||
Review Comment:
Hmm, why does this assertion have to be so complicated?
--
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]