You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2022/07/18 14:10:49 UTC

[GitHub] [hive] deniskuzZ commented on a diff in pull request #3438: HIVE-26388: ClassCastException when there is non string type column in source table of CTAS query.

deniskuzZ commented on code in PR #3438:
URL: https://github.com/apache/hive/pull/3438#discussion_r923419607


##########
serde/src/java/org/apache/hadoop/hive/serde2/OpenCSVSerde.java:
##########
@@ -115,12 +116,19 @@ public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDe
       final Object field = outputRowOI.getStructFieldData(obj, outputFieldRefs.get(c));
       final ObjectInspector fieldOI = outputFieldRefs.get(c).getFieldObjectInspector();
 
-      // The data must be of type String
-      final StringObjectInspector fieldStringOI = (StringObjectInspector) fieldOI;
-
       // Convert the field to Java class String, because objects of String type
       // can be stored in String, Text, or some other classes.
-      outputFields[c] = fieldStringOI.getPrimitiveJavaObject(field);
+      if (fieldOI instanceof StringObjectInspector) {
+        outputFields[c] = ((StringObjectInspector) fieldOI).getPrimitiveJavaObject(field);
+      } else if (fieldOI instanceof AbstractPrimitiveWritableObjectInspector) {
+        final AbstractPrimitiveWritableObjectInspector fieldStringOI =

Review Comment:
   could be simplified to:
   ````
   Object primitiveJavaObject = ((PrimitiveObjectInspector)fieldOI).getPrimitiveJavaObject(field);
   outputFields[c] = Objects.toString(primitiveJavaObject, null);
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org