output.reserve(4); current.start = output.getLength();
private void beginElement() { final Field current = stack.peek(); if (current.type == STRUCT) { // Every 8 fields we write a NULL byte. if ((current.fieldIndex % 8) == 0) { if (current.fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(current.nullOffset, current.nullByte); current.nullByte = 0; current.nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. current.nullByte |= 1 << (current.fieldIndex % 8); } }
@Override public void beginList(List list) { final Field current = new Field(LIST); beginComplex(current); final int size = list.size(); current.fieldCount = size; if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the list // which is a integer and takes four bytes current.byteSizeStart = output.getLength(); output.reserve(4); current.start = output.getLength(); } // 2/ write the size of the list as a VInt LazyBinaryUtils.writeVInt(output, size); // 3/ write the null bytes byte nullByte = 0; for (int eid = 0; eid < size; eid++) { // set the bit to 1 if an element is not null if (null != list.get(eid)) { nullByte |= 1 << (eid % 8); } // store the byte every eight elements or // if this is the last element if (7 == eid % 8 || eid == size - 1) { output.write(nullByte); nullByte = 0; } } }
@Override public void writeDate(Date date) throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. nullByte |= 1 << (fieldIndex % 8); LazyBinaryUtils.writeVInt(output, DateWritable.dateToDays(date)); fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeBoolean(boolean v) throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. nullByte |= 1 << (fieldIndex % 8); output.write((byte) (v ? 1 : 0)); fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeDate(Date date) throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. nullByte |= 1 << (fieldIndex % 8); LazyBinaryUtils.writeVInt(output, DateWritable.dateToDays(date)); fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeDouble(double v) throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. nullByte |= 1 << (fieldIndex % 8); LazyBinaryUtils.writeDouble(output, v); fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeInt(int v) throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. nullByte |= 1 << (fieldIndex % 8); LazyBinaryUtils.writeVInt(output, v); fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeNull() throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // We DO NOT set a bit in the NULL byte when we are writing a NULL. fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeNull() throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // We DO NOT set a bit in the NULL byte when we are writing a NULL. fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
@Override public void writeNull() throws IOException { // Every 8 fields we write a NULL byte. if ((fieldIndex % 8) == 0) { if (fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(nullOffset, nullByte); nullByte = 0; nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // We DO NOT set a bit in the NULL byte when we are writing a NULL. fieldIndex++; if (fieldIndex == fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(nullOffset, nullByte); } }
private void beginElement() { final Field current = stack.peek(); if (current.type == STRUCT) { // Every 8 fields we write a NULL byte. if ((current.fieldIndex % 8) == 0) { if (current.fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(current.nullOffset, current.nullByte); current.nullByte = 0; current.nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // Set bit in NULL byte when a field is NOT NULL. current.nullByte |= 1 << (current.fieldIndex % 8); } }
@Override public void beginUnion(int tag) throws IOException { final Field current = new Field(UNION); beginComplex(current); current.fieldCount = 1; if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the struct // which is a integer and takes four bytes current.byteSizeStart = output.getLength(); output.reserve(4); current.start = output.getLength(); } // 2/ serialize the union output.write(tag); }
@Override public void beginStruct(List fieldValues) { final Field current = new Field(STRUCT); beginComplex(current); current.fieldCount = fieldValues.size(); if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the struct // which is a integer and takes four bytes current.byteSizeStart = output.getLength(); output.reserve(4); current.start = output.getLength(); } current.nullOffset = output.getLength(); }
public Output getOuputForRowBytes() { if (!isOpen) { initFile(); isOpen = true; } // Reserve space for the int length. output.reserve(4); rowBeginPos = output.getLength(); return output; }
@Override public void writeNull() throws IOException { final Field current = stack.peek(); if (current.type == STRUCT) { // Every 8 fields we write a NULL byte. if ((current.fieldIndex % 8) == 0) { if (current.fieldIndex > 0) { // Write back previous 8 field's NULL byte. output.writeByte(current.nullOffset, current.nullByte); current.nullByte = 0; current.nullOffset = output.getLength(); } // Allocate next NULL byte. output.reserve(1); } // We DO NOT set a bit in the NULL byte when we are writing a NULL. current.fieldIndex++; if (current.fieldIndex == current.fieldCount) { // Write back the final NULL byte before the last fields. output.writeByte(current.nullOffset, current.nullByte); } } }
@Override public void beginUnion(int tag) throws IOException { final Field current = new Field(UNION); beginComplex(current); current.fieldCount = 1; if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the struct // which is a integer and takes four bytes current.byteSizeStart = output.getLength(); output.reserve(4); current.start = output.getLength(); } // 2/ serialize the union output.write(tag); }
public Output getOuputForRowBytes() { if (!isOpen) { initFile(); isOpen = true; } // Reserve space for the int length. output.reserve(4); rowBeginPos = output.getLength(); return output; }
@Override public void beginStruct(List fieldValues) { final Field current = new Field(STRUCT); beginComplex(current); current.fieldCount = fieldValues.size(); if (!skipLengthPrefix) { // 1/ reserve spaces for the byte size of the struct // which is a integer and takes four bytes current.byteSizeStart = output.getLength(); output.reserve(4); current.start = output.getLength(); } current.nullOffset = output.getLength(); }
public Output getOuputForRowBytes() { if (!isOpen) { initFile(); isOpen = true; } // Reserve space for the int length. output.reserve(4); rowBeginPos = output.getLength(); return output; }