title: Creating an nested record in Avro schema for a simple json
body: <p>I'm trying to build an Avro schema for the following json (for Hadoop):</p>
  
  <pre><code>{
    "name_tag":"Guy",
    "known_nested_structure" : {
      "fieldA" : ["value1"],
      "fieldB" : ["value1","value2"],
      "fieldC" : [],
      "fieldD" : ["value1"]
    },
    "another_field" : "hi"
  }
  </code></pre>
  
  <p>My first idea was this avro schema (including the hive commands):</p>
  
  <pre><code>CREATE EXTERNAL TABLE IF NOT EXISTS record_table
       PARTITIONED BY (YEAR INT, MONTH INT, DAY INT, HOUR INT)
       ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
       STORED AS
       INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
       OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
       LOCATION 'hdfs://localhost/data/output/records_data/hourly'
       TBLPROPERTIES ('avro.schema.literal'='{
    "name": "myRecord",
    "type": "record",
    "fields": [
      {"name":"name_tag", "type":"string",c"default": ""},
      {
        "name": "known_nested_structure",
        "type": "record",
        "fields": [
            {"name":"fieldA", "type":{"type":"array","items":"string"},"default":null},
            {"name":"fieldB", "type":{"type":"array","items":"string"},"default":null},
            {"name":"fieldC", "type":{"type":"array","items":"string"},"default":null},
            {"name":"fieldD", "type":{"type":"array","items":"string"},"default":null}
          ],
          "default":null
      },
      {"name": "another_field","type":"string","default": ""}
    ]
  }');
  </code></pre>
  
  <p>The hive result of the command:
      OK
      error_error_error_error_error_error_error   string  from deserializer
      cannot_determine_schema string  from deserializer
      check   string  from deserializer
      schema  string  from deserializer
      url string  from deserializer
      and string  from deserializer
      literal string  from deserializer
      year    int 
      month   int 
      day int 
      hour    int 
      Time taken: 0.128 seconds</p>
  
  <p>But for some reason this is the avro schema that works.</p>
  
  <pre><code>{
    "name": "myRecord",
    "type": "record",
    "fields": [
      {"name":"name_tag", "type":"string","default": null},
      {
    "name": "known_nested_structure",
    "type": {
          "name": "known_nested_structure",
          "type": "record",
          "fields": [
                  {"name":"fieldA", "type":{"type":"array","items":"string"},"default":null},
                  {"name":"fieldB", "type":{"type":"array","items":"string"},"default":null},
                  {"name":"fieldC", "type":{"type":"array","items":"string"},"default":null},
                  {"name":"fieldD", "type":{"type":"array","items":"string"},"default":null}
                ],
                "default":null
  
         }
      },
          {"name": "another_field","type": "string","default": null}
    ]
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>OK
  name_tag    string  from deserializer
  known_nested_structure          struct&lt;fielda:array&lt;string&gt;,fieldb:array&lt;string&gt;,fieldc:array&lt;string&gt;,fieldd:array&lt;string&gt;&gt;         from deserializer
  another_field   string  from deserializer
  year    int 
  month   int 
  day int 
  hour    int 
  Time taken: 0.123 seconds
  </code></pre>
  
  <p>What is the reason that the first avro schema doesn't work? Why can't I put a record directly as a field (known_nested_structure is in known_nested_structure in my second schema example)?</p>
  
  <p>Thanks,</p>
  
  <p>Guy</p>