给定的示例架构包含一个字段,它是 null 和字符串的并集,
{
"type":"record",
"name":"DataFlowEntity",
"namespace":"org.sdf.manage.commons.server",
"fields":
[
{"name":"dataTypeGroupName","type":["null","string"]},
{"name":"dataTypeName","type":"string"},
{"name":"dataSchemaVersion","type":"string"}
]
}
Run Code Online (Sandbox Code Playgroud)
我想转换以下 json 对象,
{
"dataTypeGroupName": "dg_1",
"dataTypeName": "dt_1",
"dataSchemaVersion": "1"
}
Run Code Online (Sandbox Code Playgroud)
进入与上述模式对应的 avro 对象。我尝试使用 Avro 的 JsonDecoder 和下面描述的代码 snppet,
String dataFlowEntity = "{\"dataTypeGroupName\": \"dg_1\", \"dataTypeName\": \"dt_1\", \"dataSchemaVersion\": \"1\"}";
Schema schema = DataFlowEntity.SCHEMA$;
InputStream inputStream = new ByteArrayInputStream(dataFlowEntity.getBytes());
DataInputStream dInputStream = new DataInputStream(inputStream);
Decoder decoder = DecoderFactory.get().jsonDecoder(schema, dInputStream);
DatumReader<DataFlowEntity> datumReader = new GenericDatumReader<DataFlowEntity>(schema);
DataFlowEntity dataFlowEntityObject = DataFlowEntity.newBuilder().build();
dataFlowEntityObject = datumReader.read(null, decoder);
Run Code Online (Sandbox Code Playgroud)
它无一例外地失败,
threw exception [org.apache.avro.AvroRuntimeException: …Run Code Online (Sandbox Code Playgroud) 我正在使用CentOS 6.5,并希望访问远程配置单元服务器.但是我无法使用安装pyhs2 pip install pyhs2.
我已经安装了所有必需的依赖项:
但我仍然得到同样的错误:
Failed building wheel for sasl
Failed to build sasl
Installing collected packages: sasl, pyhs2
Running setup.py install for sasl
Complete output from command /usr/local/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-vq9qfls4/sasl/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-bjam3ra0-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
running egg_info
writing top-level names to sasl.egg-info/top_level.txt
writing dependency_links to sasl.egg-info/dependency_links.txt
writing sasl.egg-info/PKG-INFO
warning: manifest_maker: standard file '-c' not found
reading manifest file 'sasl.egg-info/SOURCES.txt'
reading …Run Code Online (Sandbox Code Playgroud)