Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

json - 使用AVRO模式验证JSON有效负载,特别是针对“固定”数据类型(Validating JSON payload with AVRO schema particularly for “fixed” datatype)

JSON Payload:

(JSON有效负载:)

{
"BILLING_EVENT_RULE_MET_DT": "lsks",
"PlanType":"hhh"
}

AVRO Schema:

(AVRO模式:)

{
  "name": "Subscription",
  "type":"record",
  "doc": "Subscription details",
  "fields": 
    [
    { "name": "BILLING_EVENT_RULE_MET_DT",  "type":[ "null","string"],"default": null },

    {"name": "PlanType",
    "type":
         {
         "name":"PlanType",
         "type": "fixed",
            "size": 4
         }
    }
    ]
}

ERROR:
The value [hhh] for field [PlanType] should be [FixedType <size: 4, name: PlanType, namespace: None, aliases: None>].

While validating its giving me the following error, what I am supposed to write in the json payload for PlanType field?

(在验证它给我以下错误的同时,我应该在JSON有效载荷中为PlanType字段写什么?)

Actually this all I am exploring as I want to define the maxlength and minlength for a field in AVRO schema similar to XML schema.

(实际上,我想探索所有这些,因为我想为类似于XML模式的AVRO模式中的字段定义maxlength和minlength。)

  ask by Apu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If the field size of "PlanType" is not a constant you cannot use the 'fixed' type.

(如果“ PlanType”的字段大小不是常数,则不能使用“固定”类型。)

You can either use 'string' type if the data is string or 'bytes' type if the data type is any bytes sequence.

(如果数据是字符串,则可以使用“字符串”类型;如果数据类型是任何字节序列,则可以使用“字节”类型。)

Note that using 'string' or 'bytes' means it cannot have no characters/ zero bytes.

(请注意,使用“字符串”或“字节”意味着它不能没有字符/零字节。)

For enabling null value, you shall use union type (ie union of 'null' and 'string' or union of 'null' and 'bytes').

(为了启用空值,您应该使用联合类型(即,“ null”和“ string”的联合或“ null”和“ bytes”的联合)。)

There is not way to have min size or max size as part of avro schema.

(没有办法将最小大小或最大大小作为avro模式的一部分。)

See avro specification for that.

(参见avro规范 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...