pkumarsinha commented on a change in pull request #2724:
URL: https://github.com/apache/hive/pull/2724#discussion_r741594555



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/parse/repl/metric/MetricSink.java
##########
@@ -116,14 +117,17 @@ public void run() {
           int totalMetricsSize = metrics.size();
           List<ReplicationMetrics> replicationMetricsList = new 
ArrayList<>(totalMetricsSize);
           ObjectMapper mapper = new ObjectMapper();
+          MessageEncoder encoder = 
MessageFactory.getDefaultInstanceForReplMetrics(conf);
+          MessageSerializer serializer = encoder.getSerializer();
           for (int index = 0; index < totalMetricsSize; index++) {
             ReplicationMetric metric = metrics.removeFirst();
             ReplicationMetrics persistentMetric = new ReplicationMetrics();
             persistentMetric.setDumpExecutionId(metric.getDumpExecutionId());
             
persistentMetric.setScheduledExecutionId(metric.getScheduledExecutionId());
             persistentMetric.setPolicy(metric.getPolicy());
-            
persistentMetric.setProgress(mapper.writeValueAsString(metric.getProgress()));
-            
persistentMetric.setMetadata(mapper.writeValueAsString(metric.getMetadata()));
+            
persistentMetric.setProgress(serializer.serialize(mapper.writeValueAsString(metric.getProgress())));
+            
persistentMetric.setMetadata(serializer.serialize(mapper.writeValueAsString(metric.getMetadata())));

Review comment:
       How does this justify a need to compress the metadata filed in that 
case? I think we should focus on the size in worst case and then see change 
post compression. That way we can decide on:
   a) whether we really need compressetion for metadata column
   b) if so, how much should the column size be. 

##########
File path: 
ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDeserialize.java
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.messaging.MessageEncoder;
+import org.apache.hadoop.hive.metastore.messaging.MessageFactory;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.io.Text;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+
+/**
+ * TestGenericUDFGzipJsonDeserialize.
+ */
+public class TestGenericUDFDeserialize {
+
+    @Test
+    public void testOneArg() throws HiveException {
+        GenericUDFDeserialize udf = new GenericUDFDeserialize();
+        ObjectInspector valueOI1 = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+        ObjectInspector valueOI2 = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+        UDFArgumentException ex = null;
+        try {
+            udf.initialize(new ObjectInspector[]{valueOI1});
+        } catch (UDFArgumentException e) {
+            ex = e;
+        }
+        assertNotNull("The function deserialize() accepts 2 argument.", ex);
+        ex = null;
+        try {
+            udf.initialize(new ObjectInspector[]{valueOI2, valueOI1});
+        } catch (UDFArgumentException e) {
+            ex = e;
+        }
+        assertNull("The function deserialize() accepts 2 argument.", ex);
+    }
+
+    @Test
+    public void testGZIPJsonDeserializeString() throws HiveException {
+        GenericUDFDeserialize udf = new GenericUDFDeserialize();
+        udf.initialize(new 
ObjectInspector[]{PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+                
PrimitiveObjectInspectorFactory.writableStringObjectInspector});
+        GenericUDF.DeferredObject[] args = new GenericUDF.DeferredObject[2];
+        String expectedOutput = "test";
+        MessageEncoder encoder = 
MessageFactory.getDefaultInstanceForReplMetrics(new HiveConf());
+        String serializedMsg = 
encoder.getSerializer().serialize(expectedOutput);
+        args[0] = new GenericUDF.DeferredJavaObject(new Text(serializedMsg));
+        args[1] = new GenericUDF.DeferredJavaObject(new 
Text(encoder.getMessageFormat()));
+        Object actualOutput = udf.evaluate(args).toString();
+        assertEquals("deserialize() test", expectedOutput, actualOutput != 
null ? actualOutput : null);
+    }
+
+    @Test
+    public void testInvalidMessageString() throws HiveException {
+        GenericUDFDeserialize udf = new GenericUDFDeserialize();
+        udf.initialize(new 
ObjectInspector[]{PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+                
PrimitiveObjectInspectorFactory.writableStringObjectInspector});
+        GenericUDF.DeferredObject[] args = new GenericUDF.DeferredObject[2];
+        String expectedOutput = "test";
+        MessageEncoder encoder = 
MessageFactory.getDefaultInstanceForReplMetrics(new HiveConf());
+        String serializedMsg = 
encoder.getSerializer().serialize(expectedOutput);
+        args[0] = new GenericUDF.DeferredJavaObject(new Text(serializedMsg));
+        args[1] = new GenericUDF.DeferredJavaObject(new 
Text("randomSerialization"));
+        HiveException ex = null;
+        try {
+            Object actualOutput = udf.evaluate(args).toString();
+        } catch (HiveException e) {
+            ex = e;
+        }
+        assertNotNull("Invalid message format provided.", ex);

Review comment:
       Add assertion to compare the exception message

##########
File path: 
ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDeserialize.java
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.messaging.MessageEncoder;
+import org.apache.hadoop.hive.metastore.messaging.MessageFactory;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.io.Text;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+
+/**
+ * TestGenericUDFGzipJsonDeserialize.
+ */
+public class TestGenericUDFDeserialize {
+
+    @Test
+    public void testOneArg() throws HiveException {
+        GenericUDFDeserialize udf = new GenericUDFDeserialize();
+        ObjectInspector valueOI1 = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+        ObjectInspector valueOI2 = 
PrimitiveObjectInspectorFactory.writableStringObjectInspector;
+        UDFArgumentException ex = null;
+        try {
+            udf.initialize(new ObjectInspector[]{valueOI1});
+        } catch (UDFArgumentException e) {
+            ex = e;
+        }
+        assertNotNull("The function deserialize() accepts 2 argument.", ex);
+        ex = null;
+        try {
+            udf.initialize(new ObjectInspector[]{valueOI2, valueOI1});
+        } catch (UDFArgumentException e) {
+            ex = e;
+        }
+        assertNull("The function deserialize() accepts 2 argument.", ex);
+    }
+
+    @Test
+    public void testGZIPJsonDeserializeString() throws HiveException {
+        GenericUDFDeserialize udf = new GenericUDFDeserialize();
+        udf.initialize(new 
ObjectInspector[]{PrimitiveObjectInspectorFactory.writableStringObjectInspector,
+                
PrimitiveObjectInspectorFactory.writableStringObjectInspector});
+        GenericUDF.DeferredObject[] args = new GenericUDF.DeferredObject[2];
+        String expectedOutput = "test";
+        MessageEncoder encoder = 
MessageFactory.getDefaultInstanceForReplMetrics(new HiveConf());
+        String serializedMsg = 
encoder.getSerializer().serialize(expectedOutput);
+        args[0] = new GenericUDF.DeferredJavaObject(new Text(serializedMsg));
+        args[1] = new GenericUDF.DeferredJavaObject(new 
Text(encoder.getMessageFormat()));
+        Object actualOutput = udf.evaluate(args).toString();
+        assertEquals("deserialize() test", expectedOutput, actualOutput != 
null ? actualOutput : null);
+    }
+
+    @Test
+    public void testInvalidMessageString() throws HiveException {
+        GenericUDFDeserialize udf = new GenericUDFDeserialize();
+        udf.initialize(new 
ObjectInspector[]{PrimitiveObjectInspectorFactory.writableStringObjectInspector,

Review comment:
       nit: format




-- 
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]

Reply via email to