问题描述
我试图在 .ORC 文件中写入对象,但面临空指针异常
下面是我的代码
public static void main(String args[])
{
List<Map<String,Object>> data = new LinkedList<>();
Map< String,Object> map = new HashMap<String,Object>(){{
put("order_id",1);
put("item_name","Laptop");
put("price",800.f);
}};
data.add(map);
String path = "orders.orc";
write(new Configuration(),path,"struct<order_id:int,item_name:string,price:float>",data);
}
public static void write(Configuration configuration,String path,String struct,List<Map<String,Object>> data) throws IOException
{
TypeDescription schema = TypeDescription.fromString(struct);
VectorizedRowBatch batch = schema.createRowBatch();
LongColumnVector orderIdColumnVector = (LongColumnVector) batch.cols[0];
BytesColumnVector itemNameColumnVector = (BytesColumnVector) batch.cols[1];
DoubleColumnVector priceColumnVector = (DoubleColumnVector) batch.cols[2];
try(Writer writer = OrcFile.createWriter(new Path(path),OrcFile.writerOptions(configuration).setSchema(schema))){
//facing null pointer in writer
System.out.println("Done 21");
for (Map<String,Object> row : data) {
int rowNum = batch.size++; orderIdColumnVector.vector[rowNum] = (Integer) row.get("order_id");
byte[] buffer = row.get("item_name").toString().getBytes(StandardCharsets.UTF_8);
itemNameColumnVector.setRef(rowNum,buffer,buffer.length);
priceColumnVector.vector[rowNum] = (Float) row.get("price");
if (batch.size == batch.getMaxSize()) {
writer.addRowBatch(batch);
batch.reset();
}
}
if (batch.size != 0) {
writer.addRowBatch(batch);
}
System.out.println("ORC serialization ended.......");
}
catch(Exception e)
{
e.printstacktrace();
}
}
面对错误
java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1012)
at org.apache.hadoop.util.Shell.runcommand(Shell.java:482)
at org.apache.hadoop.util.Shell.run(Shell.java:455)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:702)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:791)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:774)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:646)
at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:472)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:460)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:426)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:906)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:887)
at org.apache.orc.impl.PhysicalFsWriter.<init>(PhysicalFsWriter.java:115)
at org.apache.orc.impl.WriterImpl.<init>(WriterImpl.java:167)
at org.apache.orc.OrcFile.createWriter(OrcFile.java:1004)
参考https://www.javahelps.com/2020/08/read-and-write-orc-files-in-core-java.html 我正在使用上述链接中使用的相同依赖项
请帮忙!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)