avro-tools 将 avdl 转换为 avsc 无法生成正确的 avsc

问题描述 投票:0回答:1

我正在尝试使用 avro-tools 将 avro avdl 文件( http://avro.apache.org/docs/1.7.6/idl.html#example )转换为 avro 模式文件(example.avsc)。 我下载了 avro-tools 1.7.6 和 1.6.3

example.avdl

    /**
 * An example protocol in Avro IDL
 */
@namespace("org.apache.avro.test")
protocol Simple {

  @aliases(["org.foo.KindOf"])
  enum Kind {
    FOO,
    BAR, // the bar enum value
    BAZ
  }

  fixed MD5(16);

  record TestRecord {
    @order("ignore")
    string name;

    @order("descending")
    Kind kind;

    MD5 hash;

    union { MD5, null} @aliases(["hash"]) nullableHash;

    array<long> arrayOfLongs;
  }

  error TestError {
    string message;
  }

  string hello(string greeting);
  TestRecord echo(TestRecord `record`);
  int add(int arg1, int arg2);
  bytes echoBytes(bytes data);
  void `error`() throws TestError;
  void ping() oneway;
}

生成的 example.avsc

{
  "protocol" : "Simple",
  "namespace" : "org.apache.avro.test",
  "doc" : "* An example protocol in Avro IDL",
  "types" : [ {
    "type" : "enum",
    "name" : "Kind",
    "symbols" : [ "FOO", "BAR", "BAZ" ],
    "order" : "descending",
    "aliases" : [ "org.foo.KindOf" ]
  }, {
    "type" : "fixed",
    "name" : "MD5",
    "size" : 16
  }, {
    "type" : "record",
    "name" : "TestRecord",
    "fields" : [ {
      "name" : "name",
      "type" : {
        "type" : "string",
        "order" : "ignore"
      }
    }, {
      "name" : "kind",
      "type" : "Kind"
    }, {
      "name" : "hash" ...

我在我的Mac上使用以下命令来生成它

java -jar  avro-tools-1.6.3.jar  idl example.avdl

(我已经尝试过1.6.3和1.7.6)

上面生成的模式文件无效,因为它没有名称、类型和字段作为顶级属性。

这里有什么问题吗?

谢谢

java avro
1个回答
19
投票

idl 命令生成 Avro 协议文件 (.avpr) - 要生成架构 (.avsc),您需要使用 idl2schemata 命令,该命令采用输入 idl 和可选输出目录作为参数(如果没有,则将使用当前目录)提供)并根据 IDL 中的类型生成一个或多个文件,例如

java -jar avro-tools-1.7.7.jar idl2schemata example.avdl .
© www.soinside.com 2019 - 2024. All rights reserved.