Tag: avro

Avro Schema引发StructType

这实际上与我之前的问题相同,但使用Avro而不是JSON作为数据格式。 我正在使用Sparkdataframe,它可以从几个不同的模式版本之一加载数据: // Version One {“namespace”: “com.example.avro”, “type”: “record”, “name”: “MeObject”, “fields”: [ {“name”: “A”, “type”: [“null”, “int”], “default”: null} ] } // Version Two {“namespace”: “com.example.avro”, “type”: “record”, “name”: “MeObject”, “fields”: [ {“name”: “A”, “type”: [“null”, “int”], “default”: null}, {“name”: “B”, “type”: [“null”, “int”], “default”: null} ] } 我正在使用Spark Avro加载数据。 DataFrame df = context.read() […]

带解码器问题的Kafka Avro Consumer

当我尝试使用我的相应模式使用Avro运行Kafka Consumer时 ,它返回错误“AvroRuntimeException:格式错误的数据。长度为负:-40”。 我看到其他人有类似的问题,将字节数组转换为json , Avro写入和读取 ,以及Kafka Avro Binary *编码器 。 我也引用了这个消费者组示例 ,它们都很有帮助,但到目前为止这个错误没有任何帮助..它可以工作到这部分代码(第73行) 解码器解码器= DecoderFactory.get()。binaryDecoder(byteArrayInputStream,null); 我已经尝试了其他解码器并打印出byteArrayInputStream变量的内容,看起来我相信你会期望序列化的avro数据看起来(在消息中我可以看到模式和一些数据以及一些格式错误的数据)我打印出来了使用.available()方法可用的字节,返回594.我无法理解为什么会发生此错误。 Apache Nifi用于生成具有来自hdfs的相同模式的Kafka流。 我将不胜感激任何帮助。

如何使用Apache Avro Avro二进制编码JSON字符串?

我试图avro二进制编码我的JSON字符串。 下面是我的JSON字符串,我创建了一个简单的方法来进行转换,但我不确定我的方式是否正确? public static void main(String args[]) throws Exception{ try{ Schema schema = new Parser().parse((TestExample.class.getResourceAsStream(“/3233.avsc”))); String json=”{“+ ” \”location\” : {“+ ” \”devices\”:[“+ ” {“+ ” \”did\”:\”9abd09-439bcd-629a8f\”,”+ ” \”dt\”:\”browser\”,”+ ” \”usl\”:{“+ ” \”pos\”:{“+ ” \”source\”:\”GPS\”,”+ ” \”lat\”:90.0,”+ ” \”long\”:101.0,”+ ” \”acc\”:100″+ ” },”+ ” \”addSource\”:\”LL\”,”+ ” \”add\”:[“+ ” {“+ ” \”val\”:\”2123\”,”+ ” \”type\” : \”NUM\””+ […]

Apache Avro:map使用CharSequence作为密钥

我正在使用Apache Avro 。 我的架构有地图类型: {“name”: “MyData”, “type” : {“type”: “map”, “values”:{ “type”: “record”, “name”: “Person”, “fields”:[ {“name”: “name”, “type”: “string”}, {“name”: “age”, “type”: “int”}, ] } } } 在编译模式之后,生成的Java类使用CharSequence作为Map MyData的键 。 在Map使用CharSequence作为键是非常不方便的,有没有办法在Apache Avro中为Map生成String类型键? PS 问题是,例如dataMap.containsKey(“SOME_KEY”)将返回false即使有那样的键,只是因为它是CharSequence 。 此外,使用现有密钥放置映射条目不会重新使用旧密钥。 这就是为什么我说使用CharSequence作为关键是不方便的。