I've an avro file and needs to be converted into CSV

Schema of the avro file is 

{
  "type" : "record",
  "name" : "Activity",
  "namespace" : "xyz.domain",
  "fields" : [ {
    "name" : "activityDate",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "activityTypeId",
    "type" : [ "null", "int" ],
    "default" : null
  }, {
    "name" : "campionId",
    "type" : [ "null", "int" ],
    "default" : null
  }, {
    "name" : "id",
    "type" : [ "null", "int" ],
    "default" : null
  }, {
    "name" : "SecondId",
    "type" : [ "null", "int" ],
    "default" : null
  }, {
    "name" : "GUID",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "primaryAttributeValue",
    "type" : [ "null", "string" ],
    "default" : null
  }, {
    "name" : "primaryAttributeValueId",
    "type" : [ "null", "int" ],
    "default" : null
  }, {
    "name" : "attributes",
    "type" : [ "null", {
      "type" : "array",
      "items" : {
        "type" : "record",
        "name" : "Attribute",
        "fields" : [ {
          "name" : "apiName",
          "type" : [ "null", "string" ],
          "default" : null
        }, {
          "name" : "name",
          "type" : [ "null", "string" ],
          "default" : null
        }, {
          "name" : "value",
          "type" : [ "null", "string" ],
          "default" : null
        } ]
      },
      "java-class" : "java.util.List"
    } ],
    "default" : null
  } ]
}

I'm able to read the file but don;t know how to retrieve value from the 
nested array ( api name, name and value from the attribute array).

here is my  code


fr, err := goavro.NewReader(goavro.FromReader(r))
  for fr.Scan() {
        datum, err := fr.Read()
        if err != nil {
            log.Println("cannot read datum: ", err)
            continue
        }
        fmt.Println("RECORD: ", datum)
         record := datum.(*goavro.Record)
                        //_, err = reader.Read(varactivity, 
datum.(*goavro.Record))
                        
fmt.Println("===================================================")
                        //fmt.Println(record)
                        //fmt.Println("Record Name:", record.Name)
                        //fmt.Println("Record Fields:")
                        for i, field := range record.Fields {
                                fmt.Println(" field", i, field.Name, ":", 
field.Datum)
                        }

    }
 


Can you please provide a sample code to convert the structure into CSV.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to