Github user manishgupta88 commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2671#discussion_r214244301
  
    --- Diff: 
store/sdk/src/main/java/org/apache/carbondata/sdk/file/AvroCarbonWriter.java ---
    @@ -213,6 +181,124 @@ 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) && 
checkFieldValueType(
    +              unionField.getType(), fieldValue)) {
    +            values[j] = avroFieldToObjectForUnionType(unionField, 
fieldValue, avroField);
    +            break;
    +          }
    +          if (notNullUnionFieldsCount != 1) {
    +            j++;
    +          }
    +        }
    --- End diff --
    
    Modify the code as below
            int j = 0;
            for (Schema unionField : unionFields) {
              if (unionField.getType().equals(Schema.Type.NULL) ) {
                 continue;
              }
               if (checkFieldValueType(unionField.getType(), fieldValue)) {
                values[j] = avroFieldToObjectForUnionType(unionField, 
fieldValue, avroField);
                break;
              }
              j++;
            }


---

Reply via email to