Closed mrwilby closed 9 years ago
Codegen is intended to be used for record schemas ONLY so a map schema not wrapped around a record schema is not allowed.
Given your example though, I cannot get this panic. My output is this:
Not a Record schema.
exit status 1
If you still get this kind of panic please let me know how can I reproduce this and fix to return a message like mine.
My apologies for the ambiguous post.
Here's the missing info I omitted before:
schemas = []string {
`{
"type": "record",
"name": "test",
"fields": [
{
"type": "map",
"values": {
"type": "record",
"name": "ATM",
"fields": [
{
"name": "serial_no",
"type": "string"
},
{
"name": "location",
"type": "string"
}
]
}
}
]
}`,
}
gen := avro.NewCodeGenerator(schemas)
code, err := gen.Generate()
This results in the error I mentioned previously.
Hi.
I've fixed this panic in #53.
The record field without a name is invalid and should not parse. But it should not panic though, so now it will return an error like Schema field name missing
.
I tried to use the codegen to generate code for the following schema, obtained from:
http://wiki.pentaho.com/display/EAI/Avro+Input
{ "type": "map", "values":{ "type": "record", "name":"ATM", "fields": [ {"name": "serial_no", "type": "string"}, {"name": "location", "type": "string"} ] } }
However, a panic occurs:
panic: interface conversion: interface is nil, not string
goroutine 1 [running]: github.com/stealthly/go-avro.parseSchemaField(0x234780, 0x8205cde90, 0x8205a5128, 0x8205cde60, 0x22, 0x1, 0x0, 0x0) /mypath/golang/src/github.com/stealthly/go-avro/schema.go:1028 +0x142 github.com/stealthly/go-avro.parseRecordSchema(0x8205cde30, 0x8205a5128, 0x8205cde60, 0x22, 0x0, 0x0, 0x0, 0x0) /mypath/golang/src/github.com/stealthly/go-avro/schema.go:1013 +0x969 github.com/stealthly/go-avro.schemaByType(0x234780, 0x8205cde30, 0x8205a5128, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) /mypath/golang/src/github.com/stealthly/go-avro/schema.go:962 +0x1361 github.com/stealthly/go-avro.ParseSchemaWithRegistry(0x3815c0, 0x246, 0x8205a5128, 0x0, 0x0, 0x0, 0x0) /mypath/golang/src/github.com/stealthly/go-avro/schema.go:882 +0x182 github.com/stealthly/go-avro.ParseSchema(0x3815c0, 0x246, 0x0, 0x0, 0x0, 0x0) /mypath/golang/src/github.com/stealthly/go-avro/schema.go:870 +0xd2 github.com/stealthly/go-avro.(_CodeGenerator).Generate(0x8205a5560, 0x0, 0x0, 0x0, 0x0) /mypath/golang/src/github.com/stealthly/go-avro/codegen.go:88 +0xe7 main.main.func1(0x82057c3c0) /mypath/golang/src/.../schema.go:88 +0xaef github.com/codegangsta/cli.Command.Run(0x2feb18, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x338360, 0x1d, 0x0, ...) /mypath/golang/src/github.com/codegangsta/cli/command.go:127 +0x1052 github.com/codegangsta/cli.(_App).Run(0x820594200, 0x820552100, 0x4, 0x4, 0x0, 0x0) /mypath/golang/src/github.com/codegangsta/cli/app.go:159 +0xc2f main.main()
If a name property is added to the map object, then at least the panic is resolved...