<tfoot id='f67AX'></tfoot>

      <small id='f67AX'></small><noframes id='f67AX'>

      <legend id='f67AX'><style id='f67AX'><dir id='f67AX'><q id='f67AX'></q></dir></style></legend>
      <i id='f67AX'><tr id='f67AX'><dt id='f67AX'><q id='f67AX'><span id='f67AX'><b id='f67AX'><form id='f67AX'><ins id='f67AX'></ins><ul id='f67AX'></ul><sub id='f67AX'></sub></form><legend id='f67AX'></legend><bdo id='f67AX'><pre id='f67AX'><center id='f67AX'></center></pre></bdo></b><th id='f67AX'></th></span></q></dt></tr></i><div id='f67AX'><tfoot id='f67AX'></tfoot><dl id='f67AX'><fieldset id='f67AX'></fieldset></dl></div>

        <bdo id='f67AX'></bdo><ul id='f67AX'></ul>
    1. 如何在 Hadoop 中自定义 Writable 类?

      时间:2023-09-27

                <bdo id='30oQh'></bdo><ul id='30oQh'></ul>
              • <tfoot id='30oQh'></tfoot><legend id='30oQh'><style id='30oQh'><dir id='30oQh'><q id='30oQh'></q></dir></style></legend>

                <small id='30oQh'></small><noframes id='30oQh'>

                <i id='30oQh'><tr id='30oQh'><dt id='30oQh'><q id='30oQh'><span id='30oQh'><b id='30oQh'><form id='30oQh'><ins id='30oQh'></ins><ul id='30oQh'></ul><sub id='30oQh'></sub></form><legend id='30oQh'></legend><bdo id='30oQh'><pre id='30oQh'><center id='30oQh'></center></pre></bdo></b><th id='30oQh'></th></span></q></dt></tr></i><div id='30oQh'><tfoot id='30oQh'></tfoot><dl id='30oQh'><fieldset id='30oQh'></fieldset></dl></div>
                  <tbody id='30oQh'></tbody>
                本文介绍了如何在 Hadoop 中自定义 Writable 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试实现 Writable 类,但是如果我的类中有嵌套对象(例如列表等),我不知道如何实现可写类.任何人都可以帮助我吗?谢谢

                I'm trying to implement Writable class, but i have no idea on how to implement a writable class if in my class there is nested object, such as list, etc. Could any body help me? thanks

                public class StorageClass implements Writable{
                
                public String xStr;
                public String yStr;
                
                public List<Field> sStor
                
                //omitted ctors
                
                
                @override
                public void write(DataOutput out) throws IOException{
                    out.writeChars(xStr);
                    out.WriteChars(yStr);
                
                    //WHAT SHOULD I DO FOR List<Field>
                
                }
                
                @override
                public void readFields(DataInput in) throws IOException{
                    xStr = in.readLine();
                    yStr = in.readLine();
                
                    //WHAT SHOULD I DO FOR List<Field>
                }
                
                }
                
                public class SubStorage{
                    public String x;
                    public String y;
                }
                
                }
                

                下面是Field类:

                public final class Field implements Comparable<Field>, Serializable {
                
                    private String name;
                    private DataType dataType;
                    private Object value;
                    private FieldType fieldType;
                
                
                    public Field(){
                
                    }
                
                
                
                    public  Field(String name, DataType dataType, FieldType fieldType){
                        this(name, dataType, null, fieldType);
                    }
                
                    public  Field(String name, DataType type, Object value, FieldType fieldType){
                        this.name = name;
                        this.dataType = type;
                        this.value = value;
                        this.fieldType = fieldType;
                    }
                }
                
                
                
                
                
                public enum FieldType {
                    PRI, LOOKUP, SCD, VERSION, OTHER
                }
                
                
                
                public enum DataType {
                
                    UNDEFINED(4) {
                        public int getSizeInBytes(Object value) {
                            return STRING.getSizeInBytes(value);
                        }
                    },
                
                    STRING(4) {
                        public int getSizeInBytes(Object value) {
                            if (value == null) {
                                return 0;
                            }
                            return super.getSizeInBytes(value) + (value.toString().length() * 2); // length + chars
                        }
                    },
                
                    INT(4),
                    LONG(8),
                    DOUBLE(8),
                    DATETIME(8),
                    BOOLEAN(1),
                    BYTE(1),
                    FLOAT(4),
                    SHORT(2),
                    CHAR(2),
                    DATE(8),
                    TIME(8),
                
                    BLOB(0) {
                        public int getSizeInBytes(Object value) {
                            if (value == null) {
                                return 0;
                            }
                            return ((byte[])value).length;
                        }
                    };
                
                    private final int sizeInBytes;
                
                    private DataType(int sizeInBytes) {
                        this.sizeInBytes = sizeInBytes;
                    }
                
                    public int getSizeInBytes(Object value) {
                        return sizeInBytes;
                    }
                
                }
                

                推荐答案

                序列化集合非常简单.

                @Override
                public void readFields(DataInput in) throws IOException {
                    int size = in.readInt();
                    list= new ArrayList<Field>(size);
                    for(int i = 0; i < size; i++){
                        Field f = new Field();
                        f.readFields(in);
                        list.add(f);
                    }
                }
                
                @Override
                public void write(DataOutput out) throws IOException {
                    out.writeInt(list.size());
                    for (Field l : list) {
                        l.write(out);
                    }
                }
                

                Field 也必须实现 Writable.

                Field has to implement Writable as well.

                这篇关于如何在 Hadoop 中自定义 Writable 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:由于任务尝试未能报告状态 600 秒,reduce 失败.杀 下一篇:带有 ADT 的 Android Studio 与 Eclipse (2015)

                相关文章

                最新文章

              • <legend id='Gblz8'><style id='Gblz8'><dir id='Gblz8'><q id='Gblz8'></q></dir></style></legend>
                <i id='Gblz8'><tr id='Gblz8'><dt id='Gblz8'><q id='Gblz8'><span id='Gblz8'><b id='Gblz8'><form id='Gblz8'><ins id='Gblz8'></ins><ul id='Gblz8'></ul><sub id='Gblz8'></sub></form><legend id='Gblz8'></legend><bdo id='Gblz8'><pre id='Gblz8'><center id='Gblz8'></center></pre></bdo></b><th id='Gblz8'></th></span></q></dt></tr></i><div id='Gblz8'><tfoot id='Gblz8'></tfoot><dl id='Gblz8'><fieldset id='Gblz8'></fieldset></dl></div>

                  <bdo id='Gblz8'></bdo><ul id='Gblz8'></ul>

                  <small id='Gblz8'></small><noframes id='Gblz8'>

                  1. <tfoot id='Gblz8'></tfoot>