avsc icon indicating copy to clipboard operation
avsc copied to clipboard

Support ?-syntax for optional fields in avdl

Open adamlindqvist opened this issue 2 years ago • 1 comments

I'm trying to parse a avdl file with an optional field but it seems that avsc does not support using the ?-syntax to describe a optional/nullable field.

Example

.avdl file

protocol Protocol {
	record Record {
		string? text;
	}
}

Code:

const path = path.resolve('./path-to-avdl-file.avdl');
const schema = fs.readFileSync(path, { encoding: 'utf8' });
const protocol = avsc.readProtocol(schema);

Resulting in error:

Error: invalid token {"pos":47,"id":"operator","val":"?"}: expected ID name

Is this a known issue or is it possible to work around this?

Context: https://avro.apache.org/docs/1.11.1/idl-language/#unions

adamlindqvist avatar Oct 09 '23 11:10 adamlindqvist

Hi @adamlindqvist. Thanks for reporting - the optional shorthand isn't currently supported (PR very welcome!).

You'll need to stick to the long form until it is:

protocol Protocol {
	record Record {
		union { null, string } text;
	}
}

mtth avatar Oct 12 '23 23:10 mtth

@mtth Since the corresponding PR is now merged, any chance to release a new version to NPM to make this feature accessible?

yehonatanz avatar Mar 18 '24 07:03 yehonatanz