avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Mucha <alfon...@gmail.com>
Subject Re: how to do non-optional field in nested object?
Date Mon, 27 Nov 2017 14:47:35 GMT
I don't understand where "or more" is comming from.

IIUC (and I need not), there's just one top-level json object. If so,
there's 1 ARecord. ARecord has required ID field, thus has 1 ID field. Then
it has second field BRecord, one of them. This Brecord has 2 required
fields, B and C, each should come exactly once. Right?

What I'm after is:

I) valid:


{
  "id": "..."
}

II) invalid:

{
  "id": "...",
  "B": {

  }
}

III) valid:

{
  "id": "...",
  "B": {
    "C": "..."
  }
}

IV) everything else is invalid.

2017-11-27 15:39 GMT+01:00 Dan Schmitt <dan.schmitt@gmail.com>:

> The problem is BRecord can be 0 or more and you still end up with the a
> valid B.
>
> How about
>
> {
>   "name" : "ARecord",
>   "type" : "record",
>   "namespace" : "A",
>   "fields" : [
>     {"name": "id", "type": "string" },
>     {
>       "name": "BRecord",
>       "type": "record",
>       "fields": [
>           { "name": "B", "type": "string" },
>           { "name": "C", "type": "string" }
>         ]
>       }
>     }
>   ]
> }
>
> This gives me 0 or more ARecords, each with and id, and 0 or more BRecords
> associated with each ARecord each with a B and C.  If you wanted one or
> more
> C's I don't see a trivial clean way to do that (you could add a
> Cextras array to the
> BRecord to get 0 or more additional C things, but that feels unclean.)
>
>
> On Mon, Nov 27, 2017 at 9:10 AM, Martin Mucha <alfonz19@gmail.com> wrote:
> > Thanks for reply.
> >
> > Sadly it does not work that way (here). Even:
> >
> > {
> >   "name" : "ARecord",
> >   "type" : "record",
> >   "namespace" : "A",
> >   "fields" : [
> >     {"name": "id", "type": "string" },
> >     {
> >       "name": "B",
> >       "type":  {
> >         "type": "record",
> >         "name": "BRecord",
> >         "fields": [
> >           {
> >             "name": "C",
> >             "type": "string"
> >           }
> >         ]
> >       }
> >     }
> >   ]
> > }
> >
> > does not require C. And that's not what I want ... I'd like optional B,
> and
> > once user provide B, then B.C is required.
> >
> > Martin.
> >
> >
> > 2017-11-27 15:06 GMT+01:00 Dan Schmitt <dan.schmitt@gmail.com>:
> >>
> >>       "name": "B",
> >>       "type": ["null", {
> >>
> >> The [] union lets you do null or a BRecord, your JSON does null.
> >> Pull the null from the union and it will require the C.
> >>
> >> On Mon, Nov 27, 2017 at 9:00 AM, Martin Mucha <alfonz19@gmail.com>
> wrote:
> >> > Hi,
> >> >
> >> > I have this avro schema:
> >> >
> >> > {
> >> >   "name" : "ARecord",
> >> >   "type" : "record",
> >> >   "namespace" : "A",
> >> >   "fields" : [
> >> >     {"name": "id", "type": "string" },
> >> >     {
> >> >       "name": "B",
> >> >       "type": ["null", {
> >> >         "type": "record",
> >> >         "name": "BRecord",
> >> >         "fields": [
> >> >           {
> >> >             "name": "C",
> >> >             "type": "string"
> >> >           }
> >> >         ]
> >> >       }]
> >> >     }
> >> >   ]
> >> > }
> >> >
> >> >
> >> > and following JSON, which validates against it:
> >> >
> >> > {
> >> >   "id": "...",
> >> >   "B": {
> >> >
> >> >   }
> >> > }
> >> >
> >> >
> >> > I would expect, that C is required. Why it's not? What shall I do to
> >> > make it
> >> > required?
> >> >
> >> > Thanks!
> >> > Martin.
> >
> >
>

Mime
View raw message