Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BF8D9200D4B for ; Mon, 27 Nov 2017 15:47:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id BDE16160C13; Mon, 27 Nov 2017 14:47:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DCA36160C02 for ; Mon, 27 Nov 2017 15:47:47 +0100 (CET) Received: (qmail 60390 invoked by uid 500); 27 Nov 2017 14:47:46 -0000 Mailing-List: contact user-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@avro.apache.org Delivered-To: mailing list user@avro.apache.org Received: (qmail 60379 invoked by uid 99); 27 Nov 2017 14:47:46 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Nov 2017 14:47:46 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 095BAC4C0B for ; Mon, 27 Nov 2017 14:47:46 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.329 X-Spam-Level: ** X-Spam-Status: No, score=2.329 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, HTML_MESSAGE=2, KB_WAM_FROM_NAME_SINGLEWORD=0.2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id MLWZnzAZwey8 for ; Mon, 27 Nov 2017 14:47:44 +0000 (UTC) Received: from mail-vk0-f51.google.com (mail-vk0-f51.google.com [209.85.213.51]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id EF4595F1B3 for ; Mon, 27 Nov 2017 14:47:43 +0000 (UTC) Received: by mail-vk0-f51.google.com with SMTP id t14so5075457vkc.1 for ; Mon, 27 Nov 2017 06:47:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=f7rF1ft9OxfD0g1G6reDe/Hw2TSZ8fqhVNn9Sp7CNHw=; b=EqDmCKuWKa6WPgaO5pbHTvHJTJR2x348/gzvSku1q7ATIQMzH/7yhBt1bv8PPhvVNf c3alUqg+hjRtM2juSft4kIQGP99fA3wdPOzvMdfpwhQij4n6J7V3HPeXyRJeizhsHCaJ UfvDpFIDFiV5vCUTeajiRpm9DNU1pRSoI2qTEBhyHIsa+VGMoQwGz4hZ1vt1MVJJJzov N6gNgjKAvOfvcGYYGwKjNk9Oxy42CzmPi6XtxeROVDrLNjrjybydz221m33iL10LZVhj 3NzIlGfX8SUp9Q+pTg0XdKChfpUgAMONRoSsR2Z/u15WZgDIKuQeSutCxAJ866Fhxj3A zFPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=f7rF1ft9OxfD0g1G6reDe/Hw2TSZ8fqhVNn9Sp7CNHw=; b=IgTueHSat08XXQTvs92Ru0G2Rkr5Q7SFwgOZyrU0bCOCVHJRJJNKrElM2J4tbGw75p 2dnhvZlkxZBFS8BKfpDYYBp51uPVfvR2qU7XyNuFE5IOBHRjM3paFclhDsTz6ULUlXYp szAswtCR/TiWlvHyUPS75ACVeA4HoIOGDv2CW6lWsddr0OVlFvsPZ6dyGXyVCD/3OGnb v0m2LYb9+AgNt1nj17I1/jlFOZGN8oZY5VGMNKkLPA6HGZNefqoRXkRWh1U3EUQxZPwf Suyh/P1md0+kGxHuyCIH7QbSJdFYOpF3YLYoRL/Qm3gRbxaXfgxR3GxcKp52KZCSv0qs tKcA== X-Gm-Message-State: AJaThX6LU5zS5YVkfjQ8tMuPofoIgHjAn1Mx4NMv7AhtMcxRqVw4mS+x Prt0xOA1MzHeTUMsma/YkYJFY71ITR7iu02SwE5WJw== X-Google-Smtp-Source: AGs4zMZOI0EvjoNGnYDBy2iQ1h1LQD39TWv/JUL3uSql28Ytn1Qlt8uru13ryNxG8V5g+lgypmdy+cGeLITR1+MTiH0= X-Received: by 10.31.193.82 with SMTP id r79mr27404621vkf.62.1511794056479; Mon, 27 Nov 2017 06:47:36 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.103.198 with HTTP; Mon, 27 Nov 2017 06:47:35 -0800 (PST) In-Reply-To: References: From: Martin Mucha Date: Mon, 27 Nov 2017 15:47:35 +0100 Message-ID: Subject: Re: how to do non-optional field in nested object? To: user@avro.apache.org Content-Type: multipart/alternative; boundary="001a114dceb0b5c9e8055ef7fbc7" archived-at: Mon, 27 Nov 2017 14:47:48 -0000 --001a114dceb0b5c9e8055ef7fbc7 Content-Type: text/plain; charset="UTF-8" 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 : > 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 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 : > >> > >> "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 > 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. > > > > > --001a114dceb0b5c9e8055ef7fbc7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I don't understand where "or more" is commin= g from.

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

What I'm after is:

<= div>I) valid:


{
=C2=A0 "id": "..."=C2=A0
}

=
II) invalid:

{
=C2=A0 "id": ".= ..",
=C2=A0 "B": {

= =C2=A0 }
}

<= div>III) valid:

{
=C2=A0 = "id": "...",
=C2= =A0 "B": {
=C2=A0 =C2=A0 &qu= ot;C": "..."
=C2=A0 }
}

IV) ev= erything else is invalid.

2017-11-27 15:39 GMT+01:00 Dan Schmitt <dan.schmit= t@gmail.com>:
The problem i= s BRecord can be 0 or more and you still end up with the a valid B.

How about

{
=C2=A0 "name" : "ARecord",
=C2=A0 "type" : "record",
=C2=A0 "namespace" : "A",
=C2=A0 "fields" : [
=C2=A0 =C2=A0 {"name": "id", "type": "st= ring" },
=C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 "name": "BRecord",
=C2=A0 =C2=A0 =C2=A0 "type": "record",
=C2=A0 =C2=A0 =C2=A0 "fields": [
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 { "name": "B", "= ;type": "string" },
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 { "name": "C", "= ;type": "string" }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ]
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 }
=C2=A0 ]
}

This gives me 0 or more ARecords, each with and id, and 0 or more BRecords<= br> associated with each ARecord each with a B and C.=C2=A0 If you wanted one o= r 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:
>
> {
>=C2=A0 =C2=A0"name" : "ARecord",
>=C2=A0 =C2=A0"type" : "record",
>=C2=A0 =C2=A0"namespace" : "A",
>=C2=A0 =C2=A0"fields" : [
>=C2=A0 =C2=A0 =C2=A0{"name": "id", "type"= : "string" },
>=C2=A0 =C2=A0 =C2=A0{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0"name": "B",
>=C2=A0 =C2=A0 =C2=A0 =C2=A0"type":=C2=A0 {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"type": "record",=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"name": "BRecord"= ,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"fields": [
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"name": "= ;C",
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"type": "= ;string"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0 =C2=A0}
>=C2=A0 =C2=A0]
> }
>
> does not require C. And that's not what I want ... I'd like op= tional 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>:
>>
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0"name": "B",
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0"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:
>> >
>> > {
>> >=C2=A0 =C2=A0"name" : "ARecord",
>> >=C2=A0 =C2=A0"type" : "record",
>> >=C2=A0 =C2=A0"namespace" : "A",
>> >=C2=A0 =C2=A0"fields" : [
>> >=C2=A0 =C2=A0 =C2=A0{"name": "id", "t= ype": "string" },
>> >=C2=A0 =C2=A0 =C2=A0{
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0"name": "B", >> >=C2=A0 =C2=A0 =C2=A0 =C2=A0"type": ["null"= , {
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"type": "reco= rd",
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"name": "BRec= ord",
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"fields": [
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"name&quo= t;: "C",
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"type&quo= t;: "string"
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0]
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0}]
>> >=C2=A0 =C2=A0 =C2=A0}
>> >=C2=A0 =C2=A0]
>> > }
>> >
>> >
>> > and following JSON, which validates against it:
>> >
>> > {
>> >=C2=A0 =C2=A0"id": "...",
>> >=C2=A0 =C2=A0"B": {
>> >
>> >=C2=A0 =C2=A0}
>> > }
>> >
>> >
>> > I would expect, that C is required. Why it's not? What sh= all I do to
>> > make it
>> > required?
>> >
>> > Thanks!
>> > Martin.
>
>

--001a114dceb0b5c9e8055ef7fbc7--