English 中文(简体)
• 如何在Hadoop定制可爱的班级?
原标题:How to customize Writable class in Hadoop?

我不想执行令人敬畏的阶级,但是,如果在我的班子里有nes的物体,如名单等,我对如何执行令人敬畏的阶级没有任何想法。 是否有任何机构帮助我? 感谢

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;
}

}

外地班次如下:

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);
    }
}

外地也必须执行<代码> 可复制

问题回答

The tutorial Interpretation better :





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签