pvary commented on a change in pull request #3079:
URL: https://github.com/apache/hive/pull/3079#discussion_r819618344
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/exec/SerializationUtilities.java
##########
@@ -810,31 +811,44 @@ private static void serializeObjectByKryo(Kryo kryo,
Object plan, OutputStream o
}
/**
- * Serializes expression via Kryo.
- * @param expr Expression.
+ * Serializes any object via Kryo. Type information will be serialized as
well, allowing dynamic deserialization
+ * without the need to pass the class.
+ * @param object The object to serialize.
* @return Bytes.
*/
- public static byte[] serializeExpressionToKryo(ExprNodeGenericFuncDesc expr)
{
- return serializeObjectToKryo(expr);
+ public static byte[] serializeObjectWithTypeInformation(Serializable object)
{
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Kryo kryo = borrowKryo();
+ try (Output output = new Output(baos)) {
+ kryo.writeClassAndObject(output, object);
+ } finally {
+ releaseKryo(kryo);
+ }
+ return baos.toByteArray();
}
/**
* Deserializes expression from Kryo.
* @param bytes Bytes containing the expression.
* @return Expression; null if deserialization succeeded, but the result
type is incorrect.
*/
- public static ExprNodeGenericFuncDesc deserializeExpressionFromKryo(byte[]
bytes) {
- return deserializeObjectFromKryo(bytes, ExprNodeGenericFuncDesc.class);
+ public static <T> T deserializeObjectWithTypeInformation(byte[] bytes) {
+ Kryo kryo = borrowKryo();
+ try (Input inp = new Input(new ByteArrayInputStream(bytes))) {
+ return (T) kryo.readClassAndObject(inp);
+ } finally {
+ releaseKryo(kryo);
+ }
}
public static String serializeExpression(ExprNodeGenericFuncDesc expr) {
- return new String(Base64.encodeBase64(serializeExpressionToKryo(expr)),
- StandardCharsets.UTF_8);
+ return new String(Base64.encodeBase64(serializeObjectToKryo(expr)),
+ StandardCharsets.UTF_8);
Review comment:
nit: keep 4 spaces 😄
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]