java读写orc文件_为什么我读出的orc文件的fileName都是小写

the write orc file code is:

public static void write(Class cls, List datas,Properties props) throws Exception{

String path = props.getProperty("localTempFile");

JobConf conf = new JobConf();

FileSystem fs = FileSystem.get(conf);

Path outputPath = new Path(path);

fs.delete(outputPath,true);

OrcSerde serde = new OrcSerde();

StructObjectInspector inspector =

(StructObjectInspector) ObjectInspectorFactory

.getReflectionObjectInspector(cls,

ObjectInspectorFactory.ObjectInspectorOptions.JAVA);

OutputFormat outFormat = new OrcOutputFormat();

RecordWriter writer = outFormat.getRecordWriter(fs, conf, outputPath.toString(),

Reporter.NULL);

for(int i= 0; i < datas.size();i++){

T data = datas.get(i);

System.out.println(String.format("dats:,%s,JSON:%s,", data, JSON.toJSONString(data)));

writer.write(NullWritable.get(), serde.serialize(data,inspector));

}

writer.close(Reporter.NULL);

System.out.println(fs.deleteOnExit(new Path("." + path + ".crc")));

fs.close();

System.out.println("write success .");

}

the test class is:

static class Student {

private String NAME;

private int AGE;

public Student() {

}

public String getNAME() {

return NAME;

}

public void setNAME(String NAME) {

this.NAME = NAME;

}

public int getAGE() {

return AGE;

}

public void setAGE(int AGE) {

this.AGE = AGE;

}

}

the read orc file is:

public static void read(String path) throws IOException, IOException {

Configuration conf = new Configuration();

conf.set("mapreduce.framework.name", "local");

conf.set("fs.defaultFS", "file:///");

Reader reader = OrcFile.createReader(

new Path(path),

OrcFile.readerOptions(conf));

RecordReader records = reader.rows();

Object row = null;

StructObjectInspector inspector

= (StructObjectInspector) reader.getObjectInspector();

List fields = inspector.getAllStructFieldRefs();

for (int i = 0; i < fields.size(); ++i) {

System.out.println("FieldName:" + ((StructField) fields.get(i)).getFieldName() + '\t');

System.out.println("FieldID:" + ((StructField) fields.get(i)).getFieldID() + '\t');

System.out.println("FieldComment:" + ((StructField) fields.get(i)).getFieldComment() + '\t');

System.out.println("TypeName:" + ((StructField) fields.get(i)).

getFieldObjectInspector().getTypeName() + '\t');

System.out.println("name:" + ((StructField) fields.get(i)).

getFieldObjectInspector().getCategory().name() + '\t');

System.out.println("ordinal:" + ((StructField) fields.get(i)).

getFieldObjectInspector().getCategory().ordinal() + '\t');

System.out.println("\n");

}

while (records.hasNext()) {

row = records.next(row);

List value_lst = inspector.getStructFieldsDataAsList(row);

StringBuilder builder = new StringBuilder();

//iterate over the fields

//Also fields can be null if a null was passed as the input field when processing wrote this file

for (Object field : value_lst) {

if (field != null) {

builder.append(field.toString());

}

builder.append('\t');

}

// this writes out the row as it would be if this were a Text tab seperated file

System.out.println(builder.toString()+'\n');

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值