Github user manishgupta88 commented on a diff in the pull request: https://github.com/apache/carbondata/pull/2671#discussion_r214022747 --- Diff: store/sdk/src/main/java/org/apache/carbondata/sdk/file/AvroCarbonWriter.java --- @@ -213,6 +181,126 @@ private Object avroFieldToObject(Schema.Field avroField, Object fieldValue) { } out = new ArrayObject(arrayChildObjects); break; + case UNION: + // Union type will be internally stored as Struct<col:type> + // Fill data object only if fieldvalue is instance of datatype + // For other field datatypes, fill value as Null + List<Schema> unionFields = avroField.schema().getTypes(); + int notNullUnionFieldsCount = 0; + for (Schema unionField : unionFields) { + if (!unionField.getType().equals(Schema.Type.NULL)) { + notNullUnionFieldsCount++; + } + } + Object[] values = new Object[notNullUnionFieldsCount]; + int j = 0; + for (Schema unionField : unionFields) { + if (!unionField.getType().equals(Schema.Type.NULL)) { + if (checkFieldValueType(unionField.getType(), fieldValue)) { + values[j] = avroFieldToObjectForUnionType(unionField, fieldValue, avroField); + } else { + values[j] = null; + } --- End diff -- 1. Remove else block 2. Combine above 2 if conditions into 1 using && operator 3. break the loop once if check is success
---