【问题标题】:avro-tools convert avdl to avsc does not generate correct avscavro-tools 将 avdl 转换为 avsc 不会生成正确的 avsc
【发布时间】:2014-06-17 22:14:38
【问题描述】:

我正在尝试使用 avro 工具将 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;
}

生成的例子.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我都试过了)

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

这里有什么问题吗?

谢谢

【问题讨论】:

  • "上面生成的模式文件无效,因为它没有名称、类型和字段作为顶级属性。" - 据我所知,所有属性都存在于正确的级别。 “名称”出现在 TestRecord 等等......你还期待它们在哪里?

标签: java avro


【解决方案1】:

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

java -jar avro-tools-1.7.7.jar idl2schemata example.avdl .

【讨论】:

  • 谢谢,这是我获取 C++ Avro 生成器可以接受的 avsc 文件所需的提示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多