avrow icon indicating copy to clipboard operation
avrow copied to clipboard

It seems Value::Union never used, please mark it as deprecated

Open safinaskar opened this issue 3 years ago • 0 comments

Hi. I'm unable to understand why we have Value::Union. I attempted to run this code:

use anyhow::Error;
use avrow::{Schema, Writer};
use std::str::FromStr;

fn main() -> Result<(), Error> {
    let schema = Schema::from_str(r##"{
        "type": "record",
        "name": "LongList",
        "aliases": ["LinkedLongs"],
        "fields" : [
          {"name": "value", "type": "long"},
          {"name": "next", "type": ["null", "LongList"]}
        ]
      }"##)?;
    let mut writer = Writer::new(&schema, std::io::stdout())?;
    let mut r = avrow::Record::new("LongList");
    r.insert("value", 2i64);
    r.insert("next", avrow::Value::Union(Box::new(avrow::Value::Null)));
    let res = writer.write(avrow::Value::Record(r))?;
    Ok(())
}

...and I got error Error: Value schema not found in union. Then I tried this code (note line "XXX"):

use anyhow::Error;
use avrow::{Schema, Writer};
use std::str::FromStr;

fn main() -> Result<(), Error> {
    let schema = Schema::from_str(r##"{
        "type": "record",
        "name": "LongList",
        "aliases": ["LinkedLongs"],
        "fields" : [
          {"name": "value", "type": "long"},
          {"name": "next", "type": ["null", "LongList"]}
        ]
      }"##)?;
    let mut writer = Writer::new(&schema, std::io::stdout())?;
    let mut r = avrow::Record::new("LongList");
    r.insert("value", 2i64);
    r.insert("next", avrow::Value::Null); // XXX
    let res = writer.write(avrow::Value::Record(r))?;
    Ok(())
}

...and this time I got no error.

So, it seems from my experiments, that Value::Union is not used at all in avrow. Am I right?

I grepped avrow source code and now I even more sure that Value::Union is not used. All code samples I found was trivial, Value::Union is never constructed.

So, please, mark it as deprecated to make docs more clear

safinaskar avatar Dec 11 '21 02:12 safinaskar