gpt4 book ai didi

hadoop - 在没有类(-对象)的情况下创建 Avro 模式

转载 作者:可可西里 更新时间:2023-11-01 16:38:16 26 4
gpt4 key购买 nike

目前我正在将一个类序列化为 avsc 模式。这很好用:

DatasetDescriptor desc = new DatasetDescriptor.Builder().schema(ClassName.class).build();

但是,我需要动态创建一个 没有任何给定类 的 AVSC。这可能吗?

最佳答案

这是可能的。您可以即时创建模式或读取 avro 模式。以下代码使用硬编码模式,但基本相同的想法

Schema schema = new Schema.Parser().parse("{\"namespace\": \"example.avro\",\n" +
" \"type\": \"record\",\n" +
" \"name\": \"User\",\n" +
" \"fields\": [\n" +
" {\"name\": \"name\", \"type\": \"string\"},\n" +
" {\"name\": \"favorite_number\", \"type\": [\"int\", \"null\"]},\n" +
" {\"name\": \"favorite_color\", \"type\": [\"string\", \"null\"]}\n" +
" ]\n" +
"}");
DatasetDescriptor desc = new DatasetDescriptor.Builder().schema(schema).build();

关于hadoop - 在没有类(-对象)的情况下创建 Avro 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47198444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com